@bitcobblers/wod-wiki-tools 0.58.2220 → 0.59.2236

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 (615) hide show
  1. package/dist/{agentCommands-4KTNPDHR.mjs → agentCommands-CL4MZU2F.mjs} +3 -3
  2. package/dist/{agentCommands-4KTNPDHR.mjs.map → agentCommands-CL4MZU2F.mjs.map} +1 -1
  3. package/dist/bin/wod.cjs +1 -1
  4. package/dist/bin/wod.cjs.map +1 -1
  5. package/dist/bin/wod.mjs +2 -2
  6. package/dist/{chunk-BENMP7VH.mjs → chunk-B2O23OSS.mjs} +8 -8
  7. package/dist/{chunk-BENMP7VH.mjs.map → chunk-B2O23OSS.mjs.map} +1 -1
  8. package/dist/{chunk-CIJHRNSR.mjs → chunk-O2YPCOII.mjs} +3 -3
  9. package/dist/chunk-O2YPCOII.mjs.map +1 -0
  10. package/dist/{chunk-ETSR5XVS.mjs → chunk-RUC6HPY6.mjs} +3 -3
  11. package/dist/{chunk-ETSR5XVS.mjs.map → chunk-RUC6HPY6.mjs.map} +1 -1
  12. package/dist/{chunk-WKKRSIIY.mjs → chunk-V4M6JMHX.mjs} +3 -3
  13. package/dist/{chunk-WKKRSIIY.mjs.map → chunk-V4M6JMHX.mjs.map} +1 -1
  14. package/dist/{chunk-TWYETTJK.mjs → chunk-ZZCARBRF.mjs} +3 -3
  15. package/dist/{chunk-TWYETTJK.mjs.map → chunk-ZZCARBRF.mjs.map} +1 -1
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.mjs +5 -5
  19. package/dist/{mcp-XVTWLU6K.mjs → mcp-DTIDQDU2.mjs} +4 -4
  20. package/dist/{mcp-XVTWLU6K.mjs.map → mcp-DTIDQDU2.mjs.map} +1 -1
  21. package/dist/{scaffoldFeed-N6NWV34O.mjs → scaffoldFeed-OUNIZC74.mjs} +3 -3
  22. package/dist/{scaffoldFeed-N6NWV34O.mjs.map → scaffoldFeed-OUNIZC74.mjs.map} +1 -1
  23. package/dist/server/app.cjs +1 -1
  24. package/dist/server/app.cjs.map +1 -1
  25. package/dist/server/app.mjs +3 -3
  26. package/dist/server-R2IRIFF2.mjs +13 -0
  27. package/dist/{server-AV2VNXJ7.mjs.map → server-R2IRIFF2.mjs.map} +1 -1
  28. package/dist/skills/README.md +2 -0
  29. package/dist/skills/wod-code-to-ontology/SKILL.md +61 -0
  30. package/dist/skills/wod-ontology-to-code/SKILL.md +47 -0
  31. package/dist/web/playground/assets/{main-FNVo5lac.js → main-qouuvW5M.js} +7 -7
  32. package/dist/web/playground/assets/{statementBuilderFlow-D4pompqP.js → statementBuilderFlow-BT8aA8RB.js} +2 -2
  33. package/dist/web/playground/index.html +1 -1
  34. package/dist/web/playground/seed/core/chunks/{canvas.d5661252.json → canvas.6f3fadc8.json} +1 -1
  35. package/dist/web/playground/seed/core/chunks/{dashboards.54e683a5.json → dashboards.a4d18a56.json} +1 -1
  36. package/dist/web/playground/seed/core/chunks/{efforts.25839dad.json → efforts.392df815.json} +1 -1
  37. package/dist/web/playground/seed/core/chunks/{equipment.5090c94c.json → equipment.75f0b9bb.json} +1 -1
  38. package/dist/web/playground/seed/core/indexes/notebooks/canvas.json +180 -180
  39. package/dist/web/playground/seed/core/indexes/notebooks/dashboards.json +16 -16
  40. package/dist/web/playground/seed/core/indexes/notebooks/efforts.json +326 -326
  41. package/dist/web/playground/seed/core/indexes/notebooks/equipment.json +50 -50
  42. package/dist/web/playground/seed/core/manifest.json +27 -27
  43. package/dist/web/playground/seed/core/markdown/canvas/ai-first/README.json +1 -1
  44. package/dist/web/playground/seed/core/markdown/canvas/guide/README.json +4 -4
  45. package/dist/web/playground/seed/core/markdown/canvas/guide/clock.json +1 -1
  46. package/dist/web/playground/seed/core/markdown/canvas/guide/dashboards.json +1 -1
  47. package/dist/web/playground/seed/core/markdown/canvas/guide/metrics-summaries.json +2 -2
  48. package/dist/web/playground/seed/core/markdown/canvas/guide/metrics.json +12 -12
  49. package/dist/web/playground/seed/core/markdown/canvas/guide/protocols.json +20 -20
  50. package/dist/web/playground/seed/core/markdown/canvas/guide/sessions.json +33 -33
  51. package/dist/web/playground/seed/core/markdown/canvas/guide/start.json +11 -11
  52. package/dist/web/playground/seed/core/markdown/canvas/guide/structure.json +25 -25
  53. package/dist/web/playground/seed/core/markdown/canvas/guide/wql.json +5 -5
  54. package/dist/web/playground/seed/core/markdown/canvas/home/sample-script.json +4 -4
  55. package/dist/web/playground/seed/core/markdown/canvas/home/welcome-1.json +2 -2
  56. package/dist/web/playground/seed/core/markdown/canvas/syntax/actions-comments.json +4 -4
  57. package/dist/web/playground/seed/core/markdown/canvas/syntax/alternating-emom.json +5 -5
  58. package/dist/web/playground/seed/core/markdown/canvas/syntax/basic-emom.json +4 -4
  59. package/dist/web/playground/seed/core/markdown/canvas/syntax/calculated-metrics.json +4 -4
  60. package/dist/web/playground/seed/core/markdown/canvas/syntax/classic-amrap.json +6 -6
  61. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-barbell-cycling.json +4 -4
  62. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-full-session.json +10 -10
  63. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-nested-protocols.json +7 -7
  64. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-partner-workout.json +7 -7
  65. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-swimming.json +5 -5
  66. package/dist/web/playground/seed/core/markdown/canvas/syntax/core-rules.json +4 -4
  67. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-and-calculated-metrics.json +4 -4
  68. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-intervals.json +4 -4
  69. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-1.json +4 -4
  70. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-2.json +5 -5
  71. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-3.json +3 -3
  72. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-4.json +4 -4
  73. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-5.json +4 -4
  74. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-climb-bouldering.json +2 -2
  75. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-climb-hangboard.json +2 -2
  76. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-climb-sport.json +2 -2
  77. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-log.json +4 -4
  78. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-plan.json +8 -8
  79. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-wod.json +5 -5
  80. package/dist/web/playground/seed/core/markdown/canvas/syntax/distance-intervals.json +3 -3
  81. package/dist/web/playground/seed/core/markdown/canvas/syntax/document-1.json +4 -4
  82. package/dist/web/playground/seed/core/markdown/canvas/syntax/document-2.json +5 -5
  83. package/dist/web/playground/seed/core/markdown/canvas/syntax/document-3.json +10 -10
  84. package/dist/web/playground/seed/core/markdown/canvas/syntax/document-4.json +5 -5
  85. package/dist/web/playground/seed/core/markdown/canvas/syntax/effort-notes.json +5 -5
  86. package/dist/web/playground/seed/core/markdown/canvas/syntax/frontmatter-summaries.json +4 -4
  87. package/dist/web/playground/seed/core/markdown/canvas/syntax/groups-1.json +5 -5
  88. package/dist/web/playground/seed/core/markdown/canvas/syntax/groups-2.json +6 -6
  89. package/dist/web/playground/seed/core/markdown/canvas/syntax/groups-3.json +3 -3
  90. package/dist/web/playground/seed/core/markdown/canvas/syntax/groups-4.json +3 -3
  91. package/dist/web/playground/seed/core/markdown/canvas/syntax/longer-duration.json +4 -4
  92. package/dist/web/playground/seed/core/markdown/canvas/syntax/longer-intervals.json +4 -4
  93. package/dist/web/playground/seed/core/markdown/canvas/syntax/measurements.json +7 -7
  94. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-1.json +5 -5
  95. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-2.json +7 -7
  96. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-3.json +8 -8
  97. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-4.json +6 -6
  98. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-5.json +5 -5
  99. package/dist/web/playground/seed/core/markdown/canvas/syntax/mixed-sections.json +10 -10
  100. package/dist/web/playground/seed/core/markdown/canvas/syntax/mixed-timers.json +5 -5
  101. package/dist/web/playground/seed/core/markdown/canvas/syntax/multiple-amrap-windows.json +7 -7
  102. package/dist/web/playground/seed/core/markdown/canvas/syntax/multiple-sets.json +4 -4
  103. package/dist/web/playground/seed/core/markdown/canvas/syntax/named-groups.json +6 -6
  104. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-1.json +6 -6
  105. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-2.json +4 -4
  106. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-3.json +6 -6
  107. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-4.json +3 -3
  108. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-5.json +4 -4
  109. package/dist/web/playground/seed/core/markdown/canvas/syntax/single-movement.json +3 -3
  110. package/dist/web/playground/seed/core/markdown/canvas/syntax/supplemental-1.json +4 -4
  111. package/dist/web/playground/seed/core/markdown/canvas/syntax/supplemental-2.json +5 -5
  112. package/dist/web/playground/seed/core/markdown/canvas/syntax/supplemental-3.json +4 -4
  113. package/dist/web/playground/seed/core/markdown/canvas/syntax/supplemental-4.json +4 -4
  114. package/dist/web/playground/seed/core/markdown/canvas/syntax/time-cap.json +6 -6
  115. package/dist/web/playground/seed/core/markdown/canvas/syntax/timer-modifiers.json +6 -6
  116. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-1.json +6 -6
  117. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-2.json +4 -4
  118. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-3.json +4 -4
  119. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-4.json +4 -4
  120. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-5.json +5 -5
  121. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-rest.json +4 -4
  122. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/aggregate-by-effort.json +2 -2
  123. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/aggregate-by-week.json +2 -2
  124. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/content-fran.json +2 -2
  125. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/filter-combos.json +2 -2
  126. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/pipes-limit.json +2 -2
  127. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/session-rpe.json +2 -2
  128. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/source-journal.json +2 -2
  129. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/tis-trend.json +2 -2
  130. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/where-join.json +2 -2
  131. package/dist/web/playground/seed/core/markdown/dashboards/benchmark-pr-board.json +6 -6
  132. package/dist/web/playground/seed/core/markdown/dashboards/finger-strength-v8.json +5 -5
  133. package/dist/web/playground/seed/core/markdown/dashboards/polarized-base-marathon.json +9 -9
  134. package/dist/web/playground/seed/core/markdown/dashboards/recovery-readiness.json +7 -7
  135. package/dist/web/playground/seed/core/markdown/dashboards/road-to-560-total.json +9 -9
  136. package/dist/web/playground/seed/core/markdown/dashboards/training-block-review.json +11 -11
  137. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/air-squat.json +1 -1
  138. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/box-jump.json +1 -1
  139. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/broad-jump.json +1 -1
  140. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/burpee-box-jump-over.json +1 -1
  141. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/burpee-over-dumbbell.json +1 -1
  142. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/burpee.json +1 -1
  143. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/dumbbell-squat-clean.json +1 -1
  144. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/ghd-sit-up.json +1 -1
  145. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/ground-kong.json +1 -1
  146. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/jumping-jack.json +1 -1
  147. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/kong-walk.json +1 -1
  148. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/lunge.json +1 -1
  149. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/overhead-squat.json +1 -1
  150. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/parkour-roll.json +1 -1
  151. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/parkour-squat.json +1 -1
  152. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/pistol-squat.json +1 -1
  153. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/plank.json +1 -1
  154. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/precision-burpee.json +1 -1
  155. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/precision-jump.json +1 -1
  156. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/quadrupedal-movement.json +1 -1
  157. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/russian-twist.json +1 -1
  158. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/sit-up.json +1 -1
  159. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/squat-clean.json +1 -1
  160. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/squat-hold.json +1 -1
  161. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/squat-snatch.json +1 -1
  162. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/tuck-jump.json +1 -1
  163. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/wall-ball.json +1 -1
  164. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/wall-burpee.json +1 -1
  165. package/dist/web/playground/seed/core/markdown/efforts/cycling/assault-bike.json +1 -1
  166. package/dist/web/playground/seed/core/markdown/efforts/cycling/cycling-moderate.json +1 -1
  167. package/dist/web/playground/seed/core/markdown/efforts/cycling/cycling-vigorous.json +1 -1
  168. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/assisted-pull-up.json +1 -1
  169. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/burpee-pull-up.json +1 -1
  170. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/chest-to-bar-pull-up.json +1 -1
  171. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/dip.json +1 -1
  172. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/double-under.json +1 -1
  173. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/handstand-hold.json +1 -1
  174. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/handstand-push-up.json +1 -1
  175. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/handstand-walk.json +1 -1
  176. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/jump-rope.json +1 -1
  177. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/jumping-pull-up.json +1 -1
  178. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/jumping-push-up.json +1 -1
  179. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/l-sit-pull-up.json +1 -1
  180. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/muscle-up.json +1 -1
  181. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/pull-up.json +1 -1
  182. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/push-up.json +1 -1
  183. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/reverse-wall-dip.json +1 -1
  184. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/rope-climb.json +1 -1
  185. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/toes-to-bar.json +1 -1
  186. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-arm-bar.json +1 -1
  187. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-around-the-world.json +1 -1
  188. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-bent-over-row.json +1 -1
  189. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-clean-and-jerk.json +1 -1
  190. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-clean-and-press.json +1 -1
  191. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-clean.json +1 -1
  192. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-deadlift.json +1 -1
  193. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-floor-press.json +1 -1
  194. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-front-squat.json +1 -1
  195. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-goblet-squat.json +1 -1
  196. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-gorilla-row.json +1 -1
  197. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-halo.json +1 -1
  198. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-jerk.json +1 -1
  199. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-overhead-squat.json +1 -1
  200. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-press.json +1 -1
  201. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-snatch.json +1 -1
  202. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-swing.json +1 -1
  203. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-windmill.json +1 -1
  204. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/turkish-get-up.json +1 -1
  205. package/dist/web/playground/seed/core/markdown/efforts/recovery/rest.json +1 -1
  206. package/dist/web/playground/seed/core/markdown/efforts/recovery/stretching.json +1 -1
  207. package/dist/web/playground/seed/core/markdown/efforts/rowing/rowing-sprint.json +1 -1
  208. package/dist/web/playground/seed/core/markdown/efforts/rowing/rowing.json +1 -1
  209. package/dist/web/playground/seed/core/markdown/efforts/rowing/ski-erg.json +1 -1
  210. package/dist/web/playground/seed/core/markdown/efforts/running/backward-running.json +1 -1
  211. package/dist/web/playground/seed/core/markdown/efforts/running/running-6-mph.json +1 -1
  212. package/dist/web/playground/seed/core/markdown/efforts/running/running-8-mph.json +1 -1
  213. package/dist/web/playground/seed/core/markdown/efforts/running/running-sprint.json +1 -1
  214. package/dist/web/playground/seed/core/markdown/efforts/snatch.json +2 -2
  215. package/dist/web/playground/seed/core/markdown/efforts/strength/back-squat.json +1 -1
  216. package/dist/web/playground/seed/core/markdown/efforts/strength/bench-press.json +1 -1
  217. package/dist/web/playground/seed/core/markdown/efforts/strength/box-step-up.json +1 -1
  218. package/dist/web/playground/seed/core/markdown/efforts/strength/carioca.json +1 -1
  219. package/dist/web/playground/seed/core/markdown/efforts/strength/clean-and-jerk.json +1 -1
  220. package/dist/web/playground/seed/core/markdown/efforts/strength/cluster.json +1 -1
  221. package/dist/web/playground/seed/core/markdown/efforts/strength/dead-hang.json +1 -1
  222. package/dist/web/playground/seed/core/markdown/efforts/strength/deadlift.json +1 -1
  223. package/dist/web/playground/seed/core/markdown/efforts/strength/devils-press.json +1 -1
  224. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-box-step-up.json +1 -1
  225. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-clean.json +1 -1
  226. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-fly.json +1 -1
  227. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-row.json +1 -1
  228. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-snatch.json +1 -1
  229. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-thruster.json +1 -1
  230. package/dist/web/playground/seed/core/markdown/efforts/strength/elbows-to-knees.json +1 -1
  231. package/dist/web/playground/seed/core/markdown/efforts/strength/farmer-carry.json +1 -1
  232. package/dist/web/playground/seed/core/markdown/efforts/strength/frog-stand.json +1 -1
  233. package/dist/web/playground/seed/core/markdown/efforts/strength/front-squat.json +1 -1
  234. package/dist/web/playground/seed/core/markdown/efforts/strength/good-morning.json +1 -1
  235. package/dist/web/playground/seed/core/markdown/efforts/strength/hanging-leg-raise.json +1 -1
  236. package/dist/web/playground/seed/core/markdown/efforts/strength/hollow-rock.json +1 -1
  237. package/dist/web/playground/seed/core/markdown/efforts/strength/knees-to-elbows.json +1 -1
  238. package/dist/web/playground/seed/core/markdown/efforts/strength/l-sit.json +1 -1
  239. package/dist/web/playground/seed/core/markdown/efforts/strength/man-maker.json +1 -1
  240. package/dist/web/playground/seed/core/markdown/efforts/strength/medicine-ball-clean.json +1 -1
  241. package/dist/web/playground/seed/core/markdown/efforts/strength/overhead-press.json +1 -1
  242. package/dist/web/playground/seed/core/markdown/efforts/strength/parkour-vault.json +1 -1
  243. package/dist/web/playground/seed/core/markdown/efforts/strength/pig-flip.json +1 -1
  244. package/dist/web/playground/seed/core/markdown/efforts/strength/power-clean.json +1 -1
  245. package/dist/web/playground/seed/core/markdown/efforts/strength/power-snatch.json +1 -1
  246. package/dist/web/playground/seed/core/markdown/efforts/strength/push-jerk.json +1 -1
  247. package/dist/web/playground/seed/core/markdown/efforts/strength/push-press.json +1 -1
  248. package/dist/web/playground/seed/core/markdown/efforts/strength/romanian-deadlift.json +1 -1
  249. package/dist/web/playground/seed/core/markdown/efforts/strength/single-leg-deadlift.json +1 -1
  250. package/dist/web/playground/seed/core/markdown/efforts/strength/skull-crusher.json +1 -1
  251. package/dist/web/playground/seed/core/markdown/efforts/strength/slam-ball.json +1 -1
  252. package/dist/web/playground/seed/core/markdown/efforts/strength/sled-pull.json +1 -1
  253. package/dist/web/playground/seed/core/markdown/efforts/strength/sled-push.json +1 -1
  254. package/dist/web/playground/seed/core/markdown/efforts/strength/sumo-deadlift.json +1 -1
  255. package/dist/web/playground/seed/core/markdown/efforts/strength/thruster.json +1 -1
  256. package/dist/web/playground/seed/core/markdown/efforts/strength/triceps-extension.json +1 -1
  257. package/dist/web/playground/seed/core/markdown/efforts/strength/v-sit-hold.json +1 -1
  258. package/dist/web/playground/seed/core/markdown/efforts/strength/wall-walk.json +1 -1
  259. package/dist/web/playground/seed/core/markdown/efforts/strength/yoga-sun-salutation.json +1 -1
  260. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-assisted-sprint.json +1 -1
  261. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-backstroke.json +1 -1
  262. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-breaststroke-kick.json +1 -1
  263. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-breaststroke.json +1 -1
  264. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-butterfly.json +1 -1
  265. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-catch-up-drill.json +1 -1
  266. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-choice-stroke.json +1 -1
  267. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-dive-start.json +1 -1
  268. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-dolphin-kick.json +1 -1
  269. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-drafting.json +1 -1
  270. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-fingertip-drag.json +1 -1
  271. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-freestyle.json +1 -1
  272. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-individual-medley.json +1 -1
  273. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-kick.json +1 -1
  274. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-pull.json +1 -1
  275. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-resisted-sprint.json +1 -1
  276. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-rotation-drill.json +1 -1
  277. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-sighting.json +1 -1
  278. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-single-arm-drill.json +1 -1
  279. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-stroke-transition.json +1 -1
  280. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-two-kick-one-pull.json +1 -1
  281. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-vigorous.json +1 -1
  282. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming.json +1 -1
  283. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-arm-cast.json +1 -1
  284. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-circles.json +1 -1
  285. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-mill.json +1 -1
  286. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-reverse-mill.json +1 -1
  287. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-shield-cast.json +1 -1
  288. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-10-to-2-swing.json +1 -1
  289. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-360-swing.json +1 -1
  290. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-barbarian-squat.json +1 -1
  291. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-flow.json +1 -1
  292. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-gravedigger.json +1 -1
  293. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-touchdown.json +1 -1
  294. package/dist/web/playground/seed/core/markdown/efforts/unconventional/sandbag-bear-hug-carry.json +1 -1
  295. package/dist/web/playground/seed/core/markdown/efforts/unconventional/sandbag-bear-hug-extension.json +1 -1
  296. package/dist/web/playground/seed/core/markdown/efforts/unconventional/sandbag-over-shoulder.json +1 -1
  297. package/dist/web/playground/seed/core/markdown/efforts/walking/walking-3-mph.json +1 -1
  298. package/dist/web/playground/seed/core/markdown/equipment/air-bike.json +1 -1
  299. package/dist/web/playground/seed/core/markdown/equipment/barbell.json +1 -1
  300. package/dist/web/playground/seed/core/markdown/equipment/bench.json +1 -1
  301. package/dist/web/playground/seed/core/markdown/equipment/bike-erg.json +1 -1
  302. package/dist/web/playground/seed/core/markdown/equipment/climbing-rope.json +1 -1
  303. package/dist/web/playground/seed/core/markdown/equipment/clubs.json +1 -1
  304. package/dist/web/playground/seed/core/markdown/equipment/dumbbell.json +1 -1
  305. package/dist/web/playground/seed/core/markdown/equipment/ghd.json +1 -1
  306. package/dist/web/playground/seed/core/markdown/equipment/gymnastic-rings.json +1 -1
  307. package/dist/web/playground/seed/core/markdown/equipment/jump-rope.json +1 -1
  308. package/dist/web/playground/seed/core/markdown/equipment/kettlebell.json +1 -1
  309. package/dist/web/playground/seed/core/markdown/equipment/macebell.json +1 -1
  310. package/dist/web/playground/seed/core/markdown/equipment/medicine-ball.json +1 -1
  311. package/dist/web/playground/seed/core/markdown/equipment/parallettes.json +1 -1
  312. package/dist/web/playground/seed/core/markdown/equipment/plyo-box.json +1 -1
  313. package/dist/web/playground/seed/core/markdown/equipment/pull-up-bar.json +1 -1
  314. package/dist/web/playground/seed/core/markdown/equipment/rower.json +1 -1
  315. package/dist/web/playground/seed/core/markdown/equipment/sandbag.json +1 -1
  316. package/dist/web/playground/seed/core/markdown/equipment/ski-erg.json +1 -1
  317. package/dist/web/playground/seed/core/markdown/equipment/slam-ball.json +1 -1
  318. package/dist/web/playground/seed/core/markdown/equipment/sled.json +1 -1
  319. package/dist/web/playground/seed/core/markdown/equipment/sledgehammer.json +1 -1
  320. package/dist/web/playground/seed/core/markdown/equipment/weight-vest.json +1 -1
  321. package/dist/web/playground/seed/core/report.html +13 -13
  322. package/dist/web/server/assets/{main-BwcFpdxj.js → main-B434yd-K.js} +7 -7
  323. package/dist/web/server/assets/{statementBuilderFlow-DVhmPVHz.js → statementBuilderFlow-CILJ_dtU.js} +2 -2
  324. package/dist/web/server/index.html +1 -1
  325. package/dist/web/server/seed/core/chunks/{canvas.d5661252.json → canvas.6f3fadc8.json} +1 -1
  326. package/dist/web/server/seed/core/chunks/{dashboards.54e683a5.json → dashboards.a4d18a56.json} +1 -1
  327. package/dist/web/server/seed/core/chunks/{efforts.25839dad.json → efforts.392df815.json} +1 -1
  328. package/dist/web/server/seed/core/chunks/{equipment.5090c94c.json → equipment.75f0b9bb.json} +1 -1
  329. package/dist/web/server/seed/core/indexes/notebooks/canvas.json +180 -180
  330. package/dist/web/server/seed/core/indexes/notebooks/dashboards.json +16 -16
  331. package/dist/web/server/seed/core/indexes/notebooks/efforts.json +326 -326
  332. package/dist/web/server/seed/core/indexes/notebooks/equipment.json +50 -50
  333. package/dist/web/server/seed/core/manifest.json +27 -27
  334. package/dist/web/server/seed/core/markdown/canvas/ai-first/README.json +1 -1
  335. package/dist/web/server/seed/core/markdown/canvas/guide/README.json +4 -4
  336. package/dist/web/server/seed/core/markdown/canvas/guide/clock.json +1 -1
  337. package/dist/web/server/seed/core/markdown/canvas/guide/dashboards.json +1 -1
  338. package/dist/web/server/seed/core/markdown/canvas/guide/metrics-summaries.json +2 -2
  339. package/dist/web/server/seed/core/markdown/canvas/guide/metrics.json +12 -12
  340. package/dist/web/server/seed/core/markdown/canvas/guide/protocols.json +20 -20
  341. package/dist/web/server/seed/core/markdown/canvas/guide/sessions.json +33 -33
  342. package/dist/web/server/seed/core/markdown/canvas/guide/start.json +11 -11
  343. package/dist/web/server/seed/core/markdown/canvas/guide/structure.json +25 -25
  344. package/dist/web/server/seed/core/markdown/canvas/guide/wql.json +5 -5
  345. package/dist/web/server/seed/core/markdown/canvas/home/sample-script.json +4 -4
  346. package/dist/web/server/seed/core/markdown/canvas/home/welcome-1.json +2 -2
  347. package/dist/web/server/seed/core/markdown/canvas/syntax/actions-comments.json +4 -4
  348. package/dist/web/server/seed/core/markdown/canvas/syntax/alternating-emom.json +5 -5
  349. package/dist/web/server/seed/core/markdown/canvas/syntax/basic-emom.json +4 -4
  350. package/dist/web/server/seed/core/markdown/canvas/syntax/calculated-metrics.json +4 -4
  351. package/dist/web/server/seed/core/markdown/canvas/syntax/classic-amrap.json +6 -6
  352. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-barbell-cycling.json +4 -4
  353. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-full-session.json +10 -10
  354. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-nested-protocols.json +7 -7
  355. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-partner-workout.json +7 -7
  356. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-swimming.json +5 -5
  357. package/dist/web/server/seed/core/markdown/canvas/syntax/core-rules.json +4 -4
  358. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-and-calculated-metrics.json +4 -4
  359. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-intervals.json +4 -4
  360. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-1.json +4 -4
  361. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-2.json +5 -5
  362. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-3.json +3 -3
  363. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-4.json +4 -4
  364. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-5.json +4 -4
  365. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-climb-bouldering.json +2 -2
  366. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-climb-hangboard.json +2 -2
  367. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-climb-sport.json +2 -2
  368. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-log.json +4 -4
  369. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-plan.json +8 -8
  370. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-wod.json +5 -5
  371. package/dist/web/server/seed/core/markdown/canvas/syntax/distance-intervals.json +3 -3
  372. package/dist/web/server/seed/core/markdown/canvas/syntax/document-1.json +4 -4
  373. package/dist/web/server/seed/core/markdown/canvas/syntax/document-2.json +5 -5
  374. package/dist/web/server/seed/core/markdown/canvas/syntax/document-3.json +10 -10
  375. package/dist/web/server/seed/core/markdown/canvas/syntax/document-4.json +5 -5
  376. package/dist/web/server/seed/core/markdown/canvas/syntax/effort-notes.json +5 -5
  377. package/dist/web/server/seed/core/markdown/canvas/syntax/frontmatter-summaries.json +4 -4
  378. package/dist/web/server/seed/core/markdown/canvas/syntax/groups-1.json +5 -5
  379. package/dist/web/server/seed/core/markdown/canvas/syntax/groups-2.json +6 -6
  380. package/dist/web/server/seed/core/markdown/canvas/syntax/groups-3.json +3 -3
  381. package/dist/web/server/seed/core/markdown/canvas/syntax/groups-4.json +3 -3
  382. package/dist/web/server/seed/core/markdown/canvas/syntax/longer-duration.json +4 -4
  383. package/dist/web/server/seed/core/markdown/canvas/syntax/longer-intervals.json +4 -4
  384. package/dist/web/server/seed/core/markdown/canvas/syntax/measurements.json +7 -7
  385. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-1.json +5 -5
  386. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-2.json +7 -7
  387. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-3.json +8 -8
  388. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-4.json +6 -6
  389. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-5.json +5 -5
  390. package/dist/web/server/seed/core/markdown/canvas/syntax/mixed-sections.json +10 -10
  391. package/dist/web/server/seed/core/markdown/canvas/syntax/mixed-timers.json +5 -5
  392. package/dist/web/server/seed/core/markdown/canvas/syntax/multiple-amrap-windows.json +7 -7
  393. package/dist/web/server/seed/core/markdown/canvas/syntax/multiple-sets.json +4 -4
  394. package/dist/web/server/seed/core/markdown/canvas/syntax/named-groups.json +6 -6
  395. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-1.json +6 -6
  396. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-2.json +4 -4
  397. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-3.json +6 -6
  398. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-4.json +3 -3
  399. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-5.json +4 -4
  400. package/dist/web/server/seed/core/markdown/canvas/syntax/single-movement.json +3 -3
  401. package/dist/web/server/seed/core/markdown/canvas/syntax/supplemental-1.json +4 -4
  402. package/dist/web/server/seed/core/markdown/canvas/syntax/supplemental-2.json +5 -5
  403. package/dist/web/server/seed/core/markdown/canvas/syntax/supplemental-3.json +4 -4
  404. package/dist/web/server/seed/core/markdown/canvas/syntax/supplemental-4.json +4 -4
  405. package/dist/web/server/seed/core/markdown/canvas/syntax/time-cap.json +6 -6
  406. package/dist/web/server/seed/core/markdown/canvas/syntax/timer-modifiers.json +6 -6
  407. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-1.json +6 -6
  408. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-2.json +4 -4
  409. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-3.json +4 -4
  410. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-4.json +4 -4
  411. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-5.json +5 -5
  412. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-rest.json +4 -4
  413. package/dist/web/server/seed/core/markdown/canvas/wql-presets/aggregate-by-effort.json +2 -2
  414. package/dist/web/server/seed/core/markdown/canvas/wql-presets/aggregate-by-week.json +2 -2
  415. package/dist/web/server/seed/core/markdown/canvas/wql-presets/content-fran.json +2 -2
  416. package/dist/web/server/seed/core/markdown/canvas/wql-presets/filter-combos.json +2 -2
  417. package/dist/web/server/seed/core/markdown/canvas/wql-presets/pipes-limit.json +2 -2
  418. package/dist/web/server/seed/core/markdown/canvas/wql-presets/session-rpe.json +2 -2
  419. package/dist/web/server/seed/core/markdown/canvas/wql-presets/source-journal.json +2 -2
  420. package/dist/web/server/seed/core/markdown/canvas/wql-presets/tis-trend.json +2 -2
  421. package/dist/web/server/seed/core/markdown/canvas/wql-presets/where-join.json +2 -2
  422. package/dist/web/server/seed/core/markdown/dashboards/benchmark-pr-board.json +6 -6
  423. package/dist/web/server/seed/core/markdown/dashboards/finger-strength-v8.json +5 -5
  424. package/dist/web/server/seed/core/markdown/dashboards/polarized-base-marathon.json +9 -9
  425. package/dist/web/server/seed/core/markdown/dashboards/recovery-readiness.json +7 -7
  426. package/dist/web/server/seed/core/markdown/dashboards/road-to-560-total.json +9 -9
  427. package/dist/web/server/seed/core/markdown/dashboards/training-block-review.json +11 -11
  428. package/dist/web/server/seed/core/markdown/efforts/bodyweight/air-squat.json +1 -1
  429. package/dist/web/server/seed/core/markdown/efforts/bodyweight/box-jump.json +1 -1
  430. package/dist/web/server/seed/core/markdown/efforts/bodyweight/broad-jump.json +1 -1
  431. package/dist/web/server/seed/core/markdown/efforts/bodyweight/burpee-box-jump-over.json +1 -1
  432. package/dist/web/server/seed/core/markdown/efforts/bodyweight/burpee-over-dumbbell.json +1 -1
  433. package/dist/web/server/seed/core/markdown/efforts/bodyweight/burpee.json +1 -1
  434. package/dist/web/server/seed/core/markdown/efforts/bodyweight/dumbbell-squat-clean.json +1 -1
  435. package/dist/web/server/seed/core/markdown/efforts/bodyweight/ghd-sit-up.json +1 -1
  436. package/dist/web/server/seed/core/markdown/efforts/bodyweight/ground-kong.json +1 -1
  437. package/dist/web/server/seed/core/markdown/efforts/bodyweight/jumping-jack.json +1 -1
  438. package/dist/web/server/seed/core/markdown/efforts/bodyweight/kong-walk.json +1 -1
  439. package/dist/web/server/seed/core/markdown/efforts/bodyweight/lunge.json +1 -1
  440. package/dist/web/server/seed/core/markdown/efforts/bodyweight/overhead-squat.json +1 -1
  441. package/dist/web/server/seed/core/markdown/efforts/bodyweight/parkour-roll.json +1 -1
  442. package/dist/web/server/seed/core/markdown/efforts/bodyweight/parkour-squat.json +1 -1
  443. package/dist/web/server/seed/core/markdown/efforts/bodyweight/pistol-squat.json +1 -1
  444. package/dist/web/server/seed/core/markdown/efforts/bodyweight/plank.json +1 -1
  445. package/dist/web/server/seed/core/markdown/efforts/bodyweight/precision-burpee.json +1 -1
  446. package/dist/web/server/seed/core/markdown/efforts/bodyweight/precision-jump.json +1 -1
  447. package/dist/web/server/seed/core/markdown/efforts/bodyweight/quadrupedal-movement.json +1 -1
  448. package/dist/web/server/seed/core/markdown/efforts/bodyweight/russian-twist.json +1 -1
  449. package/dist/web/server/seed/core/markdown/efforts/bodyweight/sit-up.json +1 -1
  450. package/dist/web/server/seed/core/markdown/efforts/bodyweight/squat-clean.json +1 -1
  451. package/dist/web/server/seed/core/markdown/efforts/bodyweight/squat-hold.json +1 -1
  452. package/dist/web/server/seed/core/markdown/efforts/bodyweight/squat-snatch.json +1 -1
  453. package/dist/web/server/seed/core/markdown/efforts/bodyweight/tuck-jump.json +1 -1
  454. package/dist/web/server/seed/core/markdown/efforts/bodyweight/wall-ball.json +1 -1
  455. package/dist/web/server/seed/core/markdown/efforts/bodyweight/wall-burpee.json +1 -1
  456. package/dist/web/server/seed/core/markdown/efforts/cycling/assault-bike.json +1 -1
  457. package/dist/web/server/seed/core/markdown/efforts/cycling/cycling-moderate.json +1 -1
  458. package/dist/web/server/seed/core/markdown/efforts/cycling/cycling-vigorous.json +1 -1
  459. package/dist/web/server/seed/core/markdown/efforts/gymnastics/assisted-pull-up.json +1 -1
  460. package/dist/web/server/seed/core/markdown/efforts/gymnastics/burpee-pull-up.json +1 -1
  461. package/dist/web/server/seed/core/markdown/efforts/gymnastics/chest-to-bar-pull-up.json +1 -1
  462. package/dist/web/server/seed/core/markdown/efforts/gymnastics/dip.json +1 -1
  463. package/dist/web/server/seed/core/markdown/efforts/gymnastics/double-under.json +1 -1
  464. package/dist/web/server/seed/core/markdown/efforts/gymnastics/handstand-hold.json +1 -1
  465. package/dist/web/server/seed/core/markdown/efforts/gymnastics/handstand-push-up.json +1 -1
  466. package/dist/web/server/seed/core/markdown/efforts/gymnastics/handstand-walk.json +1 -1
  467. package/dist/web/server/seed/core/markdown/efforts/gymnastics/jump-rope.json +1 -1
  468. package/dist/web/server/seed/core/markdown/efforts/gymnastics/jumping-pull-up.json +1 -1
  469. package/dist/web/server/seed/core/markdown/efforts/gymnastics/jumping-push-up.json +1 -1
  470. package/dist/web/server/seed/core/markdown/efforts/gymnastics/l-sit-pull-up.json +1 -1
  471. package/dist/web/server/seed/core/markdown/efforts/gymnastics/muscle-up.json +1 -1
  472. package/dist/web/server/seed/core/markdown/efforts/gymnastics/pull-up.json +1 -1
  473. package/dist/web/server/seed/core/markdown/efforts/gymnastics/push-up.json +1 -1
  474. package/dist/web/server/seed/core/markdown/efforts/gymnastics/reverse-wall-dip.json +1 -1
  475. package/dist/web/server/seed/core/markdown/efforts/gymnastics/rope-climb.json +1 -1
  476. package/dist/web/server/seed/core/markdown/efforts/gymnastics/toes-to-bar.json +1 -1
  477. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-arm-bar.json +1 -1
  478. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-around-the-world.json +1 -1
  479. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-bent-over-row.json +1 -1
  480. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-clean-and-jerk.json +1 -1
  481. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-clean-and-press.json +1 -1
  482. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-clean.json +1 -1
  483. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-deadlift.json +1 -1
  484. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-floor-press.json +1 -1
  485. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-front-squat.json +1 -1
  486. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-goblet-squat.json +1 -1
  487. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-gorilla-row.json +1 -1
  488. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-halo.json +1 -1
  489. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-jerk.json +1 -1
  490. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-overhead-squat.json +1 -1
  491. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-press.json +1 -1
  492. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-snatch.json +1 -1
  493. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-swing.json +1 -1
  494. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-windmill.json +1 -1
  495. package/dist/web/server/seed/core/markdown/efforts/kettlebell/turkish-get-up.json +1 -1
  496. package/dist/web/server/seed/core/markdown/efforts/recovery/rest.json +1 -1
  497. package/dist/web/server/seed/core/markdown/efforts/recovery/stretching.json +1 -1
  498. package/dist/web/server/seed/core/markdown/efforts/rowing/rowing-sprint.json +1 -1
  499. package/dist/web/server/seed/core/markdown/efforts/rowing/rowing.json +1 -1
  500. package/dist/web/server/seed/core/markdown/efforts/rowing/ski-erg.json +1 -1
  501. package/dist/web/server/seed/core/markdown/efforts/running/backward-running.json +1 -1
  502. package/dist/web/server/seed/core/markdown/efforts/running/running-6-mph.json +1 -1
  503. package/dist/web/server/seed/core/markdown/efforts/running/running-8-mph.json +1 -1
  504. package/dist/web/server/seed/core/markdown/efforts/running/running-sprint.json +1 -1
  505. package/dist/web/server/seed/core/markdown/efforts/snatch.json +2 -2
  506. package/dist/web/server/seed/core/markdown/efforts/strength/back-squat.json +1 -1
  507. package/dist/web/server/seed/core/markdown/efforts/strength/bench-press.json +1 -1
  508. package/dist/web/server/seed/core/markdown/efforts/strength/box-step-up.json +1 -1
  509. package/dist/web/server/seed/core/markdown/efforts/strength/carioca.json +1 -1
  510. package/dist/web/server/seed/core/markdown/efforts/strength/clean-and-jerk.json +1 -1
  511. package/dist/web/server/seed/core/markdown/efforts/strength/cluster.json +1 -1
  512. package/dist/web/server/seed/core/markdown/efforts/strength/dead-hang.json +1 -1
  513. package/dist/web/server/seed/core/markdown/efforts/strength/deadlift.json +1 -1
  514. package/dist/web/server/seed/core/markdown/efforts/strength/devils-press.json +1 -1
  515. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-box-step-up.json +1 -1
  516. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-clean.json +1 -1
  517. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-fly.json +1 -1
  518. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-row.json +1 -1
  519. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-snatch.json +1 -1
  520. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-thruster.json +1 -1
  521. package/dist/web/server/seed/core/markdown/efforts/strength/elbows-to-knees.json +1 -1
  522. package/dist/web/server/seed/core/markdown/efforts/strength/farmer-carry.json +1 -1
  523. package/dist/web/server/seed/core/markdown/efforts/strength/frog-stand.json +1 -1
  524. package/dist/web/server/seed/core/markdown/efforts/strength/front-squat.json +1 -1
  525. package/dist/web/server/seed/core/markdown/efforts/strength/good-morning.json +1 -1
  526. package/dist/web/server/seed/core/markdown/efforts/strength/hanging-leg-raise.json +1 -1
  527. package/dist/web/server/seed/core/markdown/efforts/strength/hollow-rock.json +1 -1
  528. package/dist/web/server/seed/core/markdown/efforts/strength/knees-to-elbows.json +1 -1
  529. package/dist/web/server/seed/core/markdown/efforts/strength/l-sit.json +1 -1
  530. package/dist/web/server/seed/core/markdown/efforts/strength/man-maker.json +1 -1
  531. package/dist/web/server/seed/core/markdown/efforts/strength/medicine-ball-clean.json +1 -1
  532. package/dist/web/server/seed/core/markdown/efforts/strength/overhead-press.json +1 -1
  533. package/dist/web/server/seed/core/markdown/efforts/strength/parkour-vault.json +1 -1
  534. package/dist/web/server/seed/core/markdown/efforts/strength/pig-flip.json +1 -1
  535. package/dist/web/server/seed/core/markdown/efforts/strength/power-clean.json +1 -1
  536. package/dist/web/server/seed/core/markdown/efforts/strength/power-snatch.json +1 -1
  537. package/dist/web/server/seed/core/markdown/efforts/strength/push-jerk.json +1 -1
  538. package/dist/web/server/seed/core/markdown/efforts/strength/push-press.json +1 -1
  539. package/dist/web/server/seed/core/markdown/efforts/strength/romanian-deadlift.json +1 -1
  540. package/dist/web/server/seed/core/markdown/efforts/strength/single-leg-deadlift.json +1 -1
  541. package/dist/web/server/seed/core/markdown/efforts/strength/skull-crusher.json +1 -1
  542. package/dist/web/server/seed/core/markdown/efforts/strength/slam-ball.json +1 -1
  543. package/dist/web/server/seed/core/markdown/efforts/strength/sled-pull.json +1 -1
  544. package/dist/web/server/seed/core/markdown/efforts/strength/sled-push.json +1 -1
  545. package/dist/web/server/seed/core/markdown/efforts/strength/sumo-deadlift.json +1 -1
  546. package/dist/web/server/seed/core/markdown/efforts/strength/thruster.json +1 -1
  547. package/dist/web/server/seed/core/markdown/efforts/strength/triceps-extension.json +1 -1
  548. package/dist/web/server/seed/core/markdown/efforts/strength/v-sit-hold.json +1 -1
  549. package/dist/web/server/seed/core/markdown/efforts/strength/wall-walk.json +1 -1
  550. package/dist/web/server/seed/core/markdown/efforts/strength/yoga-sun-salutation.json +1 -1
  551. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-assisted-sprint.json +1 -1
  552. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-backstroke.json +1 -1
  553. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-breaststroke-kick.json +1 -1
  554. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-breaststroke.json +1 -1
  555. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-butterfly.json +1 -1
  556. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-catch-up-drill.json +1 -1
  557. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-choice-stroke.json +1 -1
  558. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-dive-start.json +1 -1
  559. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-dolphin-kick.json +1 -1
  560. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-drafting.json +1 -1
  561. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-fingertip-drag.json +1 -1
  562. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-freestyle.json +1 -1
  563. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-individual-medley.json +1 -1
  564. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-kick.json +1 -1
  565. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-pull.json +1 -1
  566. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-resisted-sprint.json +1 -1
  567. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-rotation-drill.json +1 -1
  568. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-sighting.json +1 -1
  569. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-single-arm-drill.json +1 -1
  570. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-stroke-transition.json +1 -1
  571. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-two-kick-one-pull.json +1 -1
  572. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-vigorous.json +1 -1
  573. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming.json +1 -1
  574. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-arm-cast.json +1 -1
  575. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-circles.json +1 -1
  576. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-mill.json +1 -1
  577. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-reverse-mill.json +1 -1
  578. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-shield-cast.json +1 -1
  579. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-10-to-2-swing.json +1 -1
  580. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-360-swing.json +1 -1
  581. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-barbarian-squat.json +1 -1
  582. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-flow.json +1 -1
  583. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-gravedigger.json +1 -1
  584. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-touchdown.json +1 -1
  585. package/dist/web/server/seed/core/markdown/efforts/unconventional/sandbag-bear-hug-carry.json +1 -1
  586. package/dist/web/server/seed/core/markdown/efforts/unconventional/sandbag-bear-hug-extension.json +1 -1
  587. package/dist/web/server/seed/core/markdown/efforts/unconventional/sandbag-over-shoulder.json +1 -1
  588. package/dist/web/server/seed/core/markdown/efforts/walking/walking-3-mph.json +1 -1
  589. package/dist/web/server/seed/core/markdown/equipment/air-bike.json +1 -1
  590. package/dist/web/server/seed/core/markdown/equipment/barbell.json +1 -1
  591. package/dist/web/server/seed/core/markdown/equipment/bench.json +1 -1
  592. package/dist/web/server/seed/core/markdown/equipment/bike-erg.json +1 -1
  593. package/dist/web/server/seed/core/markdown/equipment/climbing-rope.json +1 -1
  594. package/dist/web/server/seed/core/markdown/equipment/clubs.json +1 -1
  595. package/dist/web/server/seed/core/markdown/equipment/dumbbell.json +1 -1
  596. package/dist/web/server/seed/core/markdown/equipment/ghd.json +1 -1
  597. package/dist/web/server/seed/core/markdown/equipment/gymnastic-rings.json +1 -1
  598. package/dist/web/server/seed/core/markdown/equipment/jump-rope.json +1 -1
  599. package/dist/web/server/seed/core/markdown/equipment/kettlebell.json +1 -1
  600. package/dist/web/server/seed/core/markdown/equipment/macebell.json +1 -1
  601. package/dist/web/server/seed/core/markdown/equipment/medicine-ball.json +1 -1
  602. package/dist/web/server/seed/core/markdown/equipment/parallettes.json +1 -1
  603. package/dist/web/server/seed/core/markdown/equipment/plyo-box.json +1 -1
  604. package/dist/web/server/seed/core/markdown/equipment/pull-up-bar.json +1 -1
  605. package/dist/web/server/seed/core/markdown/equipment/rower.json +1 -1
  606. package/dist/web/server/seed/core/markdown/equipment/sandbag.json +1 -1
  607. package/dist/web/server/seed/core/markdown/equipment/ski-erg.json +1 -1
  608. package/dist/web/server/seed/core/markdown/equipment/slam-ball.json +1 -1
  609. package/dist/web/server/seed/core/markdown/equipment/sled.json +1 -1
  610. package/dist/web/server/seed/core/markdown/equipment/sledgehammer.json +1 -1
  611. package/dist/web/server/seed/core/markdown/equipment/weight-vest.json +1 -1
  612. package/dist/web/server/seed/core/report.html +13 -13
  613. package/package.json +6 -6
  614. package/dist/chunk-CIJHRNSR.mjs.map +0 -1
  615. package/dist/server-AV2VNXJ7.mjs +0 -13
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/statementBuilderFlow-DVhmPVHz.js","assets/rolldown-runtime-C0FnF6B9.js","assets/vendor-B_PPmYw_.js","assets/vendor-CelWxf33.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/statementBuilderFlow-CILJ_dtU.js","assets/rolldown-runtime-C0FnF6B9.js","assets/vendor-B_PPmYw_.js","assets/vendor-CelWxf33.css"])))=>i.map(i=>d[i]);
2
2
  import{o as e,r as t}from"./rolldown-runtime-C0FnF6B9.js";import{$ as n,$i as r,$n as i,$r as a,A as o,Ai as s,An as c,Ar as l,At as u,B as d,Bi as f,Bn as p,Br as m,Bt as h,C as g,Ci as _,Cn as v,Cr as y,Ct as b,D as x,Di as S,Dn as C,Dr as w,Dt as T,E,Ei as D,En as O,Er as k,Et as A,F as j,Fi as M,Fn as N,Fr as P,Ft as F,G as I,Gi as ee,Gn as L,Gr as te,Gt as R,H as ne,Hi as z,Hn as B,Hr as V,Ht as re,I as ie,Ii as ae,In as oe,Ir as se,It as ce,J as le,Ji as H,Jn as ue,Jr as U,Jt as de,K as fe,Ki as pe,Kn as me,Kr as he,Kt as ge,L as _e,Li as ve,Ln as ye,Lr as be,Lt as xe,M as Se,Mi as Ce,Mn as we,Mr as Te,Mt as Ee,N as De,Ni as Oe,Nn as ke,Nr as Ae,Nt as je,O as Me,Oi as Ne,On as Pe,Or as Fe,Ot as Ie,P as Le,Pi as Re,Pn as ze,Pr as Be,Pt as Ve,Q as He,Qi as Ue,Qn as We,Qr as Ge,Qt as Ke,R as qe,Ri as Je,Rn as Ye,Rr as Xe,Rt as Ze,S as Qe,Si as $e,Sn as et,Sr as tt,St as nt,T as rt,Ti as it,Tn as at,Tr as ot,Tt as st,U as ct,Ui as lt,Un as ut,Ur as dt,Ut as ft,V as pt,Vi as mt,Vn as ht,Vr as gt,Vt as _t,W as vt,Wi as yt,Wn as bt,Wr as xt,Wt as St,X as Ct,Xi as wt,Xn as Tt,Xr as Et,Xt as Dt,Y as Ot,Yi as kt,Yn as At,Yr as jt,Yt as Mt,Z as Nt,Zi as Pt,Zn as Ft,Zr as It,Zt as Lt,_ as Rt,_i as zt,_n as Bt,_r as Vt,_t as Ht,a as Ut,ai as eee,ar as Wt,at as Gt,b as Kt,bi as qt,bn as Jt,br as Yt,bt as Xt,c as Zt,ci as Qt,cr as $t,ct as en,d as tn,di as nn,dn as rn,dr as an,dt as on,ea as sn,ei as cn,en as ln,er as un,et as dn,f as fn,fi as pn,fn as mn,fr as hn,ft as gn,g as tee,gi as _n,gn as vn,gr as yn,gt as bn,h as xn,hi as Sn,hn as Cn,hr as wn,ht as Tn,i as En,ia as Dn,ii as On,ir as kn,it as An,j as jn,ji as Mn,jn as Nn,jt as Pn,k as Fn,ki as In,kn as Ln,kr as nee,kt as Rn,l as ree,li as zn,ln as Bn,lr as iee,lt as aee,m as oee,mi as Vn,mn as see,mr as Hn,mt as Un,n as Wn,na as Gn,ni as Kn,nn as qn,nr as Jn,nt as Yn,o as Xn,oi as cee,or as Zn,ot as Qn,p as $n,pi as er,pn as tr,pr as nr,pt as rr,q as ir,qi as ar,qn as or,qr as sr,qt as cr,r as lr,ra as ur,ri as dr,rr as fr,rt as pr,s as mr,si as hr,sr as gr,st as _r,t as vr,ta as yr,ti as br,tn as xr,tr as Sr,tt as Cr,u as wr,ui as Tr,un as Er,ur as lee,ut as uee,v as dee,vi as fee,vn as Dr,vr as Or,vt as kr,w as Ar,wi as jr,wn as Mr,wr as Nr,wt as Pr,x as Fr,xi as Ir,xn as Lr,xr as Rr,xt as zr,y as Br,yi as Vr,yn as Hr,yr as Ur,yt as Wr,z as Gr,zi as Kr,zn as qr,zr as Jr,zt as Yr}from"./vendor-B_PPmYw_.js";import{$ as Xr,A as Zr,B as Qr,C as $r,D as ei,E as ti,F as ni,G as ri,H as ii,I as ai,J as oi,K as si,L as ci,M as li,N as ui,O as di,P as fi,Q as pi,R as mi,S as hi,T as gi,U as _i,V as vi,W as yi,X as bi,Y as xi,Z as Si,_ as Ci,a as wi,at as Ti,b as Ei,c as Di,ct as Oi,d as ki,dt as Ai,et as pee,f as mee,ft as ji,g as hee,h as Mi,i as gee,it as Ni,j as Pi,k as Fi,l as _ee,lt as Ii,m as Li,mt as Ri,n as vee,nt as yee,o as bee,ot as zi,p as Bi,pt as Vi,q as xee,r as Hi,rt as Ui,s as Wi,st as Gi,t as Ki,tt as qi,u as Ji,ut as Yi,v as Xi,w as Zi,x as Qi,y as $i,z as ea}from"./vendor-codemirror-CvjMzS3W.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 ta=ar(),W=e(kt(),1),G=Re(),na=(0,W.createContext)({theme:`system`,setTheme:()=>null});function ra({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`}){let[r,i]=(0,W.useState)(()=>localStorage.getItem(n)||t);(0,W.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,W.useCallback)(e=>{localStorage.setItem(n,e),i(e)},[n]),o=(0,W.useMemo)(()=>({theme:r,setTheme:a}),[r,a]);return(0,G.jsx)(na.Provider,{value:o,children:e})}var ia=()=>{let e=(0,W.useContext)(na);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function K(...e){return zn(Oe(e))}var See=Tr(`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`}}),q=W.memo(W.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},a)=>{let o=r?nn:`button`;return(0,G.jsx)(Ce,{as:o,className:K(See({variant:t,size:n,className:e})),ref:a,...i})}));q.displayName=`Button`;var aa=[`parser`,`dialect`,`user-plan`,`runtime`,`user-entry`],Cee={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`,diagnostic:`runtime`};function wee(e){return Cee[e??`parser`]??`parser`}var J=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.Diagnostic=`diagnostic`,e.Choice=`choice`,e}({}),oa={parser:0,dialect:1,"user-plan":2,runtime:3,"user-entry":4};function sa(e){return e.ownershipLayer??wee(e.origin)}function ca(e){return oa[sa(e)]??0}function la(e){return e.map((e,t)=>{let n=sa(e);return{metric:e,type:e.type,layer:n,layerRank:oa[n]??0,index:t,isSuppressor:e.action===`suppress`}})}function ua(e,t){return t?e.filter(e=>!(t.types&&!t.types.includes(e.type)||t.layers&&!t.layers.includes(e.layer))):[...e]}function da(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 fa(e){let t;for(let n of e)n.isSuppressor||(t==null||n.layerRank>t)&&(t=n.layerRank);return t}function pa(e,t){return{metric:e.metric,type:e.type,layer:e.layer,outcome:t}}function ma(e,t){return e.index-t.index}function ha(e){let t=la(e);return{raw(e){return ua(t,e).map(e=>e.metric)},visible(e){let n=da(ua(t,e)),r=[];for(let e of n.values()){if(e.some(e=>e.isSuppressor))continue;let t=fa(e);if(t!=null)for(let n of e)!n.isSuppressor&&n.layerRank===t&&r.push(n)}return r.sort(ma),r.map(e=>e.metric)},byLayer(e){let n=ua(t,e),r={};for(let e of aa)r[e]=[];for(let e of n)r[e.layer].push(e.metric);for(let e of aa)r[e]?.length===0&&delete r[e];return r},promotionCandidates(e){let n=da(ua(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:aa[i]});continue}let i=fa(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:aa[i]})}return r.sort((e,t)=>{let n=(oa[t.layer]??0)-(oa[e.layer]??0);return n===0?0:n}),r},explain(e){let n=da(ua(t,e)),r=[];for(let[e,t]of n.entries()){let n=t.some(e=>e.isSuppressor),i=n?void 0:fa(t),a=t.map(e=>e.isSuppressor?pa(e,`suppressor`):n?pa(e,`hidden-by-suppressor`):i!=null&&e.layerRank===i?pa(e,`visible`):pa(e,`hidden-by-layer`));r.push({type:e,winnerLayer:i==null?void 0:aa[i],suppressed:n,entries:a})}return r}}}function ga(e,t){let n=[...e];return(t?.types?.includes(J.Hint)??!1)||(n=n.filter(e=>e.type!==J.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 _a=class{resolve(e,t){return ha(ga(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)=>ca(t)-ca(e))}};function va(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 ya(e){let t=va(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 ba(e){return e.split(`.`).map(ya).filter(e=>e.length>0).join(`.`)}function xa(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 Sa(e){return JSON.stringify([e.path,e.kind,e.dimension??null])}var Ca=class extends Error{code;constructor(e,t){super(t),this.name=`UnitConversionError`,this.code=e}},wa=[{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 wa){e.set(t.canonical.toLowerCase(),t);for(let n of t.aliases??[])e.has(n.toLowerCase())||e.set(n.toLowerCase(),t)}return e})();function Ea(e){if(typeof e==`string`)return Ta.get(e.trim().toLowerCase())}function Da(e){return Ea(e)?.dimension}var Oa=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 ka(e){return Oa[e]}function Aa(e,t,n){let r=Ea(t);if(!r)throw new Ca(`unknown-unit`,`Unknown unit "${t}"`);let i=Ea(n);if(!i)throw new Ca(`unknown-unit`,`Unknown unit "${n}"`);if(r.dimension!==i.dimension)throw new Ca(`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 Ca(`scale-mismatch`,`Named scales ${t} and ${n} are not interchangeable`);if(!Number.isFinite(e))throw new Ca(`non-finite`,`Non-finite value cannot be converted`);return e*r.factor/i.factor}var ja=`references`,Ma=[`explicit`,`split`,`whole`,`default`,`none`];function Na(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 Pa(e){return!e||typeof e!=`object`?!1:typeof e.reason==`string`}function Fa(e){let t=e?.[ja];if(!t||typeof t!=`object`)return;let n=t;if(!(typeof n.matched!=`string`||!Ma.includes(n.matched))&&typeof n.source==`string`&&!(n.refs!==void 0&&(!Array.isArray(n.refs)||!n.refs.every(Na)))&&!(n.diagnostics!==void 0&&(!Array.isArray(n.diagnostics)||!n.diagnostics.every(Pa))))return t}var Ia=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}},La=class e{_metrics;_indexedLength=0;_resolver=new _a;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)=>ca(t)-ca(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=>ca(e))),i=Math.max(...t.map(e=>ca(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(`, `)}]`}},Ra=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 La?this.metrics:La.from(this.metrics,this.id)}},za=class extends Ra{id=0;parent;children=[];meta=new Ia(0,0,0,0);_metrics=La.empty();metricMeta=new Map;isLeaf;get metrics(){return this._metrics}set metrics(e){this._metrics=La.from(e,this.id)}constructor(e){super(),e&&(Object.assign(this,e),e.metrics&&(this.metrics=La.from(e.metrics,this.id)),this.metricMeta||=new Map)}},Ba=class e extends Ra{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=La.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 Ia(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=La.from(n,this.id),this.metricMeta=new Map,this.children=[],this.isLeaf=!0,this.meta=i?.meta??new Ia(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}},Va=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 Ha(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 Ua=`tagReference`;function Wa(e){let t=e?.[Ua];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 Ga(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 Ka(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 qa(e){return[...e].sort(Ka)}function Ja(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of qa(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 Ya(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 Xa=[`segment`,`system`,`load`,`event`,`compiler`,`completion`,`analytics`,`wellness`];function Za(e){return e===`time`?`run`:e===`log`?`log`:null}var Qa=[`defaults`,`guides`,`efforts`,`equipment`,`dashboards`],$a=[`journal`,`playground`,`defaults`,`custom`,`guides`,`efforts`,`equipment`,`dashboards`],eo=new Set(Qa),to=new Set($a);function no(e){return eo.has(io(e))}function ro(e){return to.has(io(e))}function io(e){let t=e.trim();return t.startsWith(`notebook/`)||t.startsWith(`notebook:`)?t.slice(9):t}function ao(e){return`notebook/${io(e)}`}function oo(e,t,n){let r=n??e.notebookId??void 0;return r&&no(r)?!1:t?t!==`feed`:e.seedOrigin!==`seed`&&e.feedOrigin!==`feed`}var so=[{slug:`journal`,notebookId:`notebook/journal`,name:`Journal`,description:`Private training log tracking all created notes and sessions across journal and playground.`,icon:`J`,href:`/journal`,readOnly:!1,publishable:!1},{slug:`playground`,notebookId:`notebook/playground`,name:`Playground`,description:`Scratchpad workouts and timer experiments.`,icon:`P`,href:`/playgrounds`,readOnly:!1,publishable:!1},{slug:`defaults`,notebookId:`notebook/defaults`,name:`Defaults`,description:`Read-only base primitives: Tags, Efforts, Equipment, and shared dynamic properties.`,icon:`D`,href:`/notebook/defaults`,readOnly:!0,publishable:!1},{slug:`custom`,notebookId:`notebook/custom`,name:`Custom`,description:`User overrides and custom Tags, Efforts, Equipment, and starter workouts.`,icon:`C`,href:`/notebook/custom`,readOnly:!1,publishable:!1},{slug:`guides`,notebookId:`notebook/guides`,name:`Guides`,description:`Pre-subscribed read-only Whiteboard Language and WQL guides.`,icon:`G`,href:`/notebook/guides`,readOnly:!0,publishable:!1,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`}],co=[`playground-run-tip`,`attention`,`code-example`,`syntax-group`],lo={table:!0,list:!0,value:!0,timeseries:!0,bar:!0,donut:!0,toplist:!0,"stacked-bar":!0,"goal-rings":!0,"zone-distribution":!0},Tee={time:`time`,wod:`time`,whiteboard:`time`,log:`log`};function uo(e){let t=e.match(/^`{3,}(time|wod|whiteboard|log)(?::([\w-]+))?\s*$/i);return t?{dialect:Tee[t[1].toLowerCase()],...t[2]?{sport:t[2]}:{}}:null}function Eee(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`,`metrics.met`,`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 Dee(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 fo(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]==="`"?uo(`\`\`\`${h}`):null,_=a[0]==="`"?h.match(/^widget:([\w-]+)$/):null,v=t.registeredWidgets??co,y=_&&(`has`in v?v.has(_[1]):v.includes(_[1])),b=a[0]==="`"&&!y?h.match(/^widget:([a-zA-Z-]+)(?:-(?:full|\d+))?(?:\s+.*)?$/i):null,x=!!(b&&lo[b[1].toLowerCase()]),S=a[0]==="`"?h.match(/^query(?:[:\s](.*))?$/i)??(x?h.match(/^widget:?(.*)$/i):null):null,C=p&&g?g.dialect:p&&y?`widget`:p&&S?`query`:`code`,w=u(C,l,m);w.contentFrom=r[l]+n[l].length+i[l].length,w.contentTo=p?r[c]:w.to,w.displayContent=e.slice(w.contentFrom,w.contentTo),g&&p&&(w.sport=g.sport,w.contentId=Ga(w.displayContent),w.scriptBlock={id:w.id,contentId:w.contentId,dialect:g.dialect,sport:g.sport,startLine:l,endLine:m,content:w.displayContent,state:`idle`,version:1,createdAt:s}),C===`widget`&&_&&(w.widgetName=_[1]),C===`query`&&S&&(w.querySuffix=(S[1]??``).trim()),o.push(w),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=Eee(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=Dee(m.displayContent.trim()),a&&(c=!1),o.push(m),l=p+1}return o}function po(e){return e.type===`time`||e.type===`log`?`wod`:e.type===`query`||e.type===`widget`||e.type===`embed`?e.type:null}function mo(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 fo(e,t)){let e=po(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 ho(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=mo(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 go(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 Oee=/^[A-Za-z][\w.-]*$/,kee=/^---\r?\n([\s\S]*?)\r?\n---/;function Aee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function _o(e){let t=e.trim();return t===``||t.startsWith(`#`)}function vo(e){return Array.isArray(e)}function yo(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 bo(e,t,n){let r=` `.repeat(e);return vo(n)?n.length===0?[`${r}${t}: []`]:[`${r}${t}:`,...n.map(e=>`${r} - ${typeof e==`number`?String(e):yo(e)}`)]:[`${r}${t}: ${typeof n==`number`?String(n):yo(n)}`]}function xo(e,t,n,r){let i=[],a=r;for(let r=t;r<e.length;r++)r===e.length-1?i.push(...bo(a,e[r],n)):i.push(`${` `.repeat(a)}${e[r]}:`),a+=2;return i}function jee(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 So(e,t,n){let r=[t],i=[];for(let a=t+1;a<e.length;a++){let t=e[a];if(_o(t)){i.push(a);continue}if(t.length-t.trimStart().length>n)r.push(...i,a),i=[];else break}return r}function Co(e,t,n,r,i){let a=RegExp(`^ {${n}}${Aee(t)}\\s*:`);for(let t=r;t<i;t++)if(a.test(e[t]))return t;return-1}function wo(e,t,n){if(t.length===0||!t.every(e=>typeof e==`string`&&Oee.test(e)))return e;let r=e.includes(`\r
@@ -98,7 +98,7 @@ query: sum:$metric{} by {week}
98
98
  `)+`
99
99
  `}function Zb(e){let t=Wb(e);if(t.length<2)return{bundles:[],errors:[]};let n=Ub(t[0]);if(n[0]!==`recordKind`)try{let t=Jb(e);return{bundles:[{sessions:[t.session],events:t.events}],errors:[]}}catch(e){return{bundles:[],errors:[e instanceof Error?e.message:String(e)]}}let r=new Map;n.forEach((e,t)=>r.set(e,t));let i=(e,t)=>{let n=r.get(t);return n===void 0?``:e[n]??``},a=new Map,o=new Map,s=new Map,c=[];for(let[e,n]of t.slice(1).entries()){let t=Ub(n);if(t.length===1&&t[0]===``)continue;let r=i(t,`recordKind`),l=Kb(i(t,`noteId`));if(!l){c.push(`Row ${e+2}: missing noteId`);continue}if(r===`revision`){let n=Kb(i(t,`revisionKind`)),r=Kb(i(t,`blockId`)),o=Gb(i(t,`blockVersion`)),s=Gb(i(t,`revisionSavedAt`));if(!n||!r||!o||s===void 0){c.push(`Row ${e+2}: invalid revision columns`);continue}let u={noteId:l,blockId:r,version:o,kind:n,rawContent:i(t,`revisionRawContent`),savedAt:s,...Kb(i(t,`revisionDialect`))?{dialect:Kb(i(t,`revisionDialect`))}:{},...Kb(i(t,`revisionSport`))?{sport:Kb(i(t,`revisionSport`))}:{}},d=a.get(l)??[];d.push(u),a.set(l,d)}else if(r===`parse`){let n=Kb(i(t,`parseId`)),r=Kb(i(t,`parseStage`)),a=Kb(i(t,`parseStatus`)),s=Gb(i(t,`timestamp`));if(!n||!r||!a||s===void 0){c.push(`Row ${e+2}: invalid parse columns`);continue}let u={id:n,noteId:l,...Kb(i(t,`blockId`))?{blockId:Kb(i(t,`blockId`))}:{},...Gb(i(t,`blockVersion`))===void 0?{}:{blockVersion:Gb(i(t,`blockVersion`))},stage:r,status:a,timestamp:s,...Kb(i(t,`parseDiagnosticsJson`))?{diagnostics:qb(i(t,`parseDiagnosticsJson`))}:{},...Kb(i(t,`parseMetricsJson`))?{metrics:qb(i(t,`parseMetricsJson`))}:{}},d=o.get(l)??[];d.push(u),o.set(l,d)}else if(r===`session`||r===`event`){let n=Kb(i(t,`sessionId`));if(!n){c.push(`Row ${e+2}: missing sessionId`);continue}let r=Bb.map(e=>Vb(i(t,e))),a=s.get(n)??{noteId:l,lines:[Bb.join(`,`)]};a.lines.push(r.join(`,`)),s.set(n,a)}else c.push(`Row ${e+2}: unknown recordKind '${r}'`)}let l=new Map,u=e=>{let t=l.get(e);if(t)return t;let n={sessions:[],events:[]};return l.set(e,n),n};for(let[e,t]of a)u(e).revisions=t;for(let[e,t]of o)u(e).parses=t;for(let[,{noteId:e,lines:t}]of s)try{let n=Jb(t.join(`
100
100
  `)+`
101
- `),r=u(e);r.sessions.push(n.session),r.events.push(...n.events)}catch(e){c.push(e instanceof Error?e.message:String(e))}return{bundles:[...l.values()],errors:c}}var Tne=`0.58.2220`,Qb=co,Ene=`1b671a64-40d5-491e-99b0-da01ff1f3341`,Dne={core:0,community:1,imported:2,user:3};function One(e,t){if(t)return t;if(!e)return`core`;if(e===`user`)return`user`;let n=e.startsWith(`seed:`)?e.slice(5):e;return n===`core`||n===`efforts`||n===`equipment`?`core`:n===`community`||n.startsWith(`community-`)||n===`common`?`community`:`imported`}function $b(e,t){return Dne[One(e,t)]}var ex=`wodwiki.seed`,tx=`efforts`,nx=`equipment`,rx=`canvas`;function ix(e){return`seed:${e}`}function kne(e){return e.startsWith(`seed:`)?e.slice(5):e}function ax(e){return{key:e,schema:9,seedVersion:0,builtAt:``,importedAt:0,chunks:{},claim:null}}function ox(e){let t=/^notebook\.(.+)$/.exec(e)?.[1];return t&&t!==`_root`?t:void 0}function Ane(e){let t=/^---\r?\n([\s\S]*?)\r?\n---/.exec(e);return t?.[1]&&!/^template:\s*canvas\s*$/m.test(t[1])?null:t?.[1]?.match(/^route:\s*(\S+)\s*$/m)?.[1]?.replace(/^\//,``)||null}function jne(e,t,n){let r=e.split(`/`),i=(r.at(-1)??``).replace(/\.md$/i,``),a=r.slice(2).map(e=>e.replace(/\.md$/i,``)).join(`/`);if(n===`canvas`)return`guides:${Ane(t)??a}`;if(n===`dashboards`)return`dashboards`;if(n===`efforts`)return`efforts`;if(n===`equipment`)return`equipment`;if(n.startsWith(`notebook.`)){let e=ox(n);return e?i.toLowerCase()===`readme`?`notebook:${e}`:`notebook:${a}`:`notebook:_root`}}var sx=[{name:`notes`,keyPath:[`id`],indexes:[{name:`by-date`,keyPath:[`date`]},{name:`by-created`,keyPath:[`createdAt`]},{name:`by-type`,keyPath:[`type`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`page`,keyPath:[`id`],indexes:[{name:`by-date`,keyPath:[`date`],unique:!0},{name:`by-slug`,keyPath:[`slug`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`page_notes`,keyPath:[`id`],indexes:[{name:`by-page`,keyPath:[`pageId`]},{name:`by-note`,keyPath:[`noteId`]},{name:`by-page-note`,keyPath:[`pageId`,`noteId`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`tags`,keyPath:[`id`],indexes:[{name:`by-label`,keyPath:[`label`],unique:!0},{name:`by-type`,keyPath:[`type`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`tag_types`,keyPath:[`id`],indexes:[{name:`by-name`,keyPath:[`name`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`note_tags`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-tag`,keyPath:[`tagId`]},{name:`by-note-tag`,keyPath:[`noteId`,`tagId`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`block_revisions`,keyPath:[`noteId`,`blockId`,`version`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-block`,keyPath:[`noteId`,`blockId`]}]},{name:`sessions`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-completed`,keyPath:[`createdAt`]},{name:`by-content`,keyPath:[`blockContentId`]},{name:`by-block`,keyPath:[`blockId`]},{name:`by-page`,keyPath:[`pageId`]},{name:`by-origin`,keyPath:[`origin`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`attachments`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-time`,keyPath:[`createdAt`]},{name:`by-page`,keyPath:[`pageId`]},{name:`by-result`,keyPath:[`resultId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`events`,keyPath:[`id`],indexes:[{name:`by-timestamp`,keyPath:[`timestamp`]},{name:`by-result-grain`,keyPath:[`resultId`,`grain`]},{name:`by-content-grain`,keyPath:[`blockContentId`,`grain`]},{name:`by-effort`,keyPath:[`effortSlug`]},{name:`by-outputType`,keyPath:[`outputType`]},{name:`by-grain`,keyPath:[`grain`]},{name:`by-metric-date`,keyPath:[`metricDateKeys`],multiEntry:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`field_catalog`,keyPath:[`id`],indexes:[{name:`by-path`,keyPath:[`path`]}]},{name:`field_sources`,keyPath:[`id`],indexes:[]},{name:`field_values`,keyPath:[`key`],indexes:[{name:`by-field`,keyPath:[`fieldId`]}]},{name:`field_catalog_meta`,keyPath:[`id`],indexes:[]},{name:`efforts`,keyPath:[`slug`],indexes:[{name:`by-discipline`,keyPath:[`baseAttributes.discipline`]},{name:`by-source`,keyPath:[`registrySource`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`equipment`,keyPath:[`slug`],indexes:[{name:`by-source`,keyPath:[`registrySource`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`block_index`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-content`,keyPath:[`blockContentId`]},{name:`by-type`,keyPath:[`dataType`]},{name:`by-source`,keyPath:[`sourceId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`block_efforts`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-effort`,keyPath:[`effortSlug`]},{name:`by-block`,keyPath:[`blockContentId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`block_equipment`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-equipment`,keyPath:[`equipmentSlug`]},{name:`by-block`,keyPath:[`blockContentId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`notebook_links`,keyPath:[`id`],indexes:[{name:`by-notebook`,keyPath:[`notebookId`]},{name:`by-note`,keyPath:[`noteId`]},{name:`by-target`,keyPath:[`targetKind`,`targetId`]},{name:`by-notebook-target`,keyPath:[`notebookId`,`targetKind`,`targetId`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`property_overrides`,keyPath:[`id`],indexes:[{name:`by-notebook`,keyPath:[`notebookId`]},{name:`by-kind-slug`,keyPath:[`kind`,`slug`]},{name:`by-owner-note`,keyPath:[`ownerNoteId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`meta`,keyPath:[`key`],indexes:[]},{name:`memberships`,keyPath:[`id`],indexes:[],system:!0}],cx=`default`;function lx(e=Date.now()){return{id:cx,displayName:`Anonymous`,createdAt:e}}var ux=[`notes`,`page`,`page_notes`,`tags`,`tag_types`,`note_tags`,`sessions`,`attachments`,`events`,`efforts`,`block_index`,`block_efforts`,`equipment`,`block_equipment`,`notebook_links`,`property_overrides`],Mne=Object.fromEntries(ux.map(e=>[e,!0]));function dx(e,t,n){if(!Mne[e]||typeof t!=`object`||!t||Array.isArray(t))return t;let r=t;return r.seedOrigin===`seed`||r.userId===n?t:{...r,userId:n}}function fx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&(`only`in e||`lower`in e||`upper`in e||`lowerOpen`in e||`upperOpen`in e)}function px(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;let t=n;if(!(e in t))return;n=t[e]}if(n!==null&&typeof n!=`object`&&n!==void 0)return n}function mx(e,t){let n=e.keyPath.map(e=>px(t,e));for(let[t,r]of n.entries())if(r===void 0)throw Error(`keyFromValue(${e.name}): keyPath part '${e.keyPath[t]}' missing on value`);let r=n;return r.length===1?r[0]:r}function Nne(e){return encodeURIComponent(JSON.stringify(e))}function hx(e){if(e===void 0)return;if(!fx(e))return{only:e};if(e.only!==void 0)return e;let t={};return e.lower!==void 0&&e.lower!==null&&(t.lower=e.lower,t.lowerOpen=e.lowerOpen===!0),e.upper!==void 0&&e.upper!==null&&(t.upper=Array.isArray(e.upper)?e.upper.map(e=>Array.isArray(e)&&e.length===0?`￿`:e):e.upper,t.upperOpen=e.upperOpen===!0),t.lower!==void 0||t.upper!==void 0?t:void 0}function gx(e,t){if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t))return Array.isArray(e)?1:-1;for(let n=0;n<Math.min(e.length,t.length);n++){let r=gx(e[n],t[n]);if(r!==0)return r}return e.length-t.length}return typeof e==`number`&&typeof t==`number`?e<t?-1:+(e>t):typeof e==`number`||typeof t==`number`?typeof e==`number`?-1:1:e<t?-1:+(e>t)}function _x(e,t){if(t.only!==void 0)return gx(e,t.only)===0;if(t.lower!==void 0){let n=gx(e,t.lower);if(n<0||n===0&&t.lowerOpen===!0)return!1}if(t.upper!==void 0){let n=gx(e,t.upper);if(n>0||n===0&&t.upperOpen===!0)return!1}return!0}function vx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function yx(e,t){return t.every(t=>e[t]===void 0||typeof e[t]==`string`)}function bx(e,t){return t.every(t=>typeof e[t]==`number`&&Number.isFinite(e[t]))}function xx(e){if(!vx(e)||typeof e.id!=`string`||typeof e.title!=`string`||typeof e.rawContent!=`string`||!Number.isSafeInteger(e.sourceRevision)||typeof e.sourceRevision!=`number`||e.sourceRevision<1||!vx(e.blocks)||!bx(e,[`createdAt`])||e.date!==void 0&&!bx(e,[`date`])||!yx(e,[`type`,`sourceId`,`notebookId`,`sourcePath`,`seedOrigin`,`seedChunkId`,`feedOrigin`,`feedSourceId`])||e.tags!==void 0&&(!Array.isArray(e.tags)||!e.tags.every(e=>typeof e==`string`)))return!1;try{return ho(e.rawContent,e.blocks,e.sourceRevision),!0}catch{return!1}}function Pne(e){return vx(e)&&typeof e.id==`string`&&typeof e.noteId==`string`&&typeof e.blockId==`string`&&bx(e,[`blockVersion`,`sourceRevision`,`from`,`to`,`createdAt`])&&e.id===`${e.noteId}:${e.blockId}`&&typeof e.blockVersion==`number`&&Number.isSafeInteger(e.blockVersion)&&e.blockVersion>0&&typeof e.sourceRevision==`number`&&Number.isSafeInteger(e.sourceRevision)&&e.sourceRevision>0&&typeof e.from==`number`&&Number.isSafeInteger(e.from)&&e.from>=0&&typeof e.to==`number`&&Number.isSafeInteger(e.to)&&e.to>e.from&&[`wod`,`query`,`widget`,`embed`].includes(String(e.dataType))&&typeof e.rawContent==`string`&&typeof e.noteTitle==`string`&&yx(e,[`blockContentId`,`sourceId`,`sourcePath`,`routeId`])&&(e.position===void 0||bx(e,[`position`]))&&(e.isStatic===void 0||typeof e.isStatic==`boolean`)}function Fne(e){return vx(e)&&typeof e.id==`string`&&typeof e.label==`string`&&bx(e,[`createdAt`])&&yx(e,[`type`])}function Ine(e){return vx(e)&&typeof e.id==`string`&&bx(e,[`createdAt`])&&yx(e,[`date`,`slug`,`title`])}function Lne(e){return vx(e)&&typeof e.id==`string`&&typeof e.noteId==`string`&&typeof e.pageId==`string`&&bx(e,[`createdAt`])&&(e.position===void 0||bx(e,[`position`]))}function Rne(e){return vx(e)&&xx(e.note)&&Array.isArray(e.tags)&&e.tags.every(Fne)&&Array.isArray(e.links)&&e.links.every(Lne)&&Array.isArray(e.pages)&&e.pages.every(Ine)}function zne(e,t){if(!vx(e)||e.projectionVersion!==4||e.plan!==t||!Array.isArray(e.rows)||typeof e.selectedCount!=`number`||!Number.isSafeInteger(e.selectedCount)||e.selectedCount<0||typeof e.matchedCount!=`number`||!Number.isSafeInteger(e.matchedCount)||e.matchedCount<0||e.matchedCount>e.selectedCount||e.rows.length>e.matchedCount)throw Error(`ApiStorage: invalid or stale domain projection response`);let n={projectionVersion:4,selectedCount:e.selectedCount,matchedCount:e.matchedCount};switch(t){case`notes`:if(e.rows.every(xx))return{...n,plan:t,rows:e.rows};break;case`blocks`:if(e.rows.every(Pne))return{...n,plan:t,rows:e.rows};break;case`detail`:if(e.rows.every(Rne))return{...n,plan:t,rows:e.rows}}throw Error(`ApiStorage: invalid domain query rows`)}var Sx=(e,t)=>`${e}\u0000${JSON.stringify(t)}`;function Cx(e,t,n){if(n?.has(e))return!0;if(!t)return!1;let r=`${e}\u0000`;for(let e of t.keys())if(e.startsWith(r))return!0;return!1}function Bne(e,t,n){if(!n)return;let r=n.get(Sx(e,t));if(r)return r.kind===`put`?{hit:!0,value:r.value}:{hit:!1}}function Vne(e,t,n,r,i,a,o,s){if(!n||!Cx(t,n,r))return a===void 0?i:i.slice(0,a);let c=new Map;if(!r?.has(t))for(let t of i)c.set(JSON.stringify(mx(e,t)),t);let l=`${t}\u0000`;for(let[e,t]of n)e.startsWith(l)&&(t.kind===`put`?c.set(e.slice(l.length),t.value):c.delete(e.slice(l.length)));let u=s?e.indexes.find(e=>e.name===s):void 0;if(s&&!u)throw Error(`unknown index '${s}' for ${t}`);let d=t=>{if(!u)return mx(e,t);let n=u.keyPath.map(e=>px(t,e));if(n.some(e=>e===void 0))return;let r=n.filter(e=>e!==void 0);return r.length===1?r[0]:r},f=e=>{if(u?.multiEntry){let t=e;for(let e of u.keyPath[0].split(`.`)){if(typeof t!=`object`||!t||!(e in t))return!1;t=Reflect.get(t,e)}return Array.isArray(t)&&t.some(e=>(typeof e==`string`||typeof e==`number`)&&(!o||_x(e,o)))}let t=d(e);return t!==void 0&&(!o||_x(t,o))},p=[...c.values()].filter(f);return p.sort((t,n)=>{let r=gx(mx(e,t),mx(e,n));if(u?.multiEntry)return r;let i=d(t),a=d(n);return i!==void 0&&a!==void 0&&gx(i,a)||r}),a===void 0?p:p.slice(0,a)}function Hne(e,t,n){let r=new Set(e),i=[];for(let e of n)r.has(e)&&i.push({op:`clear`,store:e});for(let[e,n]of t){let t=e.indexOf(`\0`),a=e.slice(0,t);r.has(a)&&(n.kind===`put`?i.push({op:`put`,store:a,value:n.value}):i.push({op:`delete`,store:a,key:JSON.parse(e.slice(t+1))}))}return i}var wx=class extends Error{status;code;constructor(e,t,n){super(t),this.status=e,this.code=n,this.name=`StorageError`}};function Tx(e,t){if(Object.is(e,t))return!0;if(e instanceof ArrayBuffer&&t instanceof ArrayBuffer){let n=new Uint8Array(e),r=new Uint8Array(t);return n.length===r.length&&n.every((e,t)=>e===r[t])}if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>Tx(e,t[n]));let n=Object.keys(e).filter(t=>Reflect.get(e,t)!==void 0),r=Object.keys(t).filter(e=>Reflect.get(t,e)!==void 0);return n.length===r.length&&n.every(n=>Object.hasOwn(t,n)&&Tx(Reflect.get(e,n),Reflect.get(t,n)))}function Ex(e){if(typeof e!=`object`||!e||Array.isArray(e))throw new wx(400,`storage row must be an object`);return e}function Dx(e,t){if(e!==`notes`&&e!==`block_revisions`&&e!==`sessions`&&e!==`block_index`)return;let n=Ex(t),r=e=>typeof n[e]==`number`&&Number.isSafeInteger(n[e])&&n[e]>0,i=e=>typeof n[e]==`string`&&n[e].length>0;if(e===`notes`){if(!i(`id`)||typeof n.title!=`string`||typeof n.rawContent!=`string`||!r(`sourceRevision`)||typeof n.createdAt!=`number`||!Number.isFinite(n.createdAt)||`segments`in n||`segmentIds`in n||n.date!==void 0&&(typeof n.date!=`number`||!Number.isFinite(n.date))||n.seedOrigin!==void 0&&n.seedOrigin!==`seed`&&n.seedOrigin!==`user`||n.feedOrigin!==void 0&&n.feedOrigin!==`feed`&&n.feedOrigin!==`user`||n.feedOrigin===`feed`&&(n.seedOrigin===void 0||typeof n.feedSourceId!=`string`||n.feedSourceId.length===0)||n.feedOrigin===`user`&&n.seedOrigin===`seed`||n.feedSourceId!==void 0&&n.feedOrigin!==`feed`||n.seedVersion!==void 0&&!(typeof n.seedVersion==`number`&&Number.isSafeInteger(n.seedVersion)&&n.seedVersion>=0)||n.tags!==void 0&&(!Array.isArray(n.tags)||!n.tags.every(e=>typeof e==`string`))||n.public!==void 0&&typeof n.public!=`boolean`||n.notebookIds!==void 0&&(!Array.isArray(n.notebookIds)||!n.notebookIds.every(e=>typeof e==`string`))||n.provenance!==void 0&&(typeof n.provenance!=`object`||n.provenance===null||Array.isArray(n.provenance)||typeof n.provenance.sourceNoteId!=`string`)||[`type`,`sourceId`,`sourcePath`,`notebookId`,`seedChunkId`,`feedSourceId`].some(e=>n[e]!==void 0&&typeof n[e]!=`string`))throw new wx(400,`invalid whole Note`,`invalid_note_blocks`);try{ho(n.rawContent,Ex(n.blocks),n.sourceRevision)}catch(e){throw new wx(400,e instanceof Error?e.message:`invalid block map`,`invalid_note_blocks`)}}else if(e===`block_revisions`){if(!i(`noteId`)||!i(`blockId`)||!r(`version`)||typeof n.rawContent!=`string`||typeof n.savedAt!=`number`||!Number.isFinite(n.savedAt)||![`wod`,`query`,`widget`,`embed`].includes(String(n.kind))||(n.kind===`wod`?n.dialect!==`time`&&n.dialect!==`log`:n.dialect!==void 0||n.sport!==void 0)||n.sport!==void 0&&typeof n.sport!=`string`)throw new wx(400,`invalid block revision`,`invalid_note_blocks`);try{ho(n.rawContent,{[String(n.blockId)]:{id:String(n.blockId),kind:n.kind,version:n.version,sourceRevision:1,from:0,to:n.rawContent.length,...n.dialect===void 0?{}:{dialect:n.dialect},...n.sport===void 0?{}:{sport:n.sport}}},1)}catch(e){throw new wx(400,e instanceof Error?e.message:`invalid revision source`,`invalid_note_blocks`)}}else if(e===`sessions`){if(!i(`noteId`)||!i(`blockId`)||!r(`blockVersion`)||n.public!==void 0&&typeof n.public!=`boolean`||n.notebookIds!==void 0&&(!Array.isArray(n.notebookIds)||!n.notebookIds.every(e=>typeof e==`string`))||[`segmentId`,`segmentVersion`,`version`,`rawContent`,`script`,`serializedScript`,`source`,`data`,`logs`].some(e=>e in n))throw new wx(400,`Session requires immutable block pin`,`invalid_session_pin`)}else if(!i(`noteId`)||!i(`blockId`)||!r(`blockVersion`)||!r(`sourceRevision`)||n.id!==`${n.noteId}:${n.blockId}`||!Number.isSafeInteger(n.from)||!Number.isSafeInteger(n.to)||`segmentId`in n||`segmentVersion`in n||![`wod`,`query`,`widget`,`embed`].includes(String(n.dataType))||typeof n.rawContent!=`string`||typeof n.noteTitle!=`string`||typeof n.from!=`number`||typeof n.to!=`number`||n.from<0||n.to<=n.from)throw new wx(400,`invalid actionable block projection`,`invalid_note_blocks`)}function Une(e,t){if(e===void 0||Tx(e,t))return;let n=Ex(e),r=Ex(t);if(typeof n.sourceRevision!=`number`||typeof r.sourceRevision!=`number`||r.sourceRevision<n.sourceRevision||(!Tx(n.blocks,r.blocks)||n.rawContent!==r.rawContent)&&r.sourceRevision<=n.sourceRevision)throw new wx(409,`stale Note source revision`,`transaction_conflict`)}function Wne(e,t){if(e===void 0)return;let n=Ex(e),r=Ex(t);if(n.noteId!==r.noteId||n.blockId!==r.blockId||n.blockVersion!==r.blockVersion)throw new wx(409,`Session pin is immutable`,`invalid_session_pin`)}async function Ox(e,t,n){let r=[];for(let t of e)for(let e of Object.values(t.blocks))r.push([t.id,e.id,e.version]);for(let e of t)r.push([e.noteId,e.blockId,e.blockVersion]);let i=await n(r),a=0;for(let t of e)for(let e of Object.values(t.blocks)){let n=i[a++];if(!n||n.kind!==e.kind||n.rawContent!==t.rawContent.slice(e.from,e.to)||n.dialect!==e.dialect||n.sport!==e.sport)throw new wx(409,`Note block has no matching immutable revision`,`invalid_note_blocks`)}for(let e=0;e<t.length;e++){let e=i[a++];if(!e||e.kind!==`wod`)throw new wx(409,`Session pin must reference a saved workout revision`,`invalid_session_pin`)}}async function kx(e,t,n,r){let i=r?.params?.toString(),a=await e.fetchImpl(`${e.baseUrl}/v1${n}${i?`?${i}`:``}`,{method:t,headers:r?.body===void 0?void 0:{"content-type":`application/json`},body:r?.body===void 0?void 0:JSON.stringify(r.body)});if(!a.ok)throw Error(`ApiStorage: ${t} /v1${n} → ${a.status}`);return a}async function Gne(e,t,n){let r=await e.fetchImpl(`${e.baseUrl}/v1/${t}/get?key=${Nne(n)}`);if(r.status!==404){if(!r.ok)throw Error(`ApiStorage: GET /v1/${t}/get → ${r.status}`);return await r.json()}}async function Kne(e,t,n,r,i){let a=new URLSearchParams;return r&&a.set(`range`,JSON.stringify(r)),i!==void 0&&a.set(`count`,String(i)),await(await kx(e,`GET`,`/${t}/${n}`,{params:a})).json()}async function Ax(e,t,n,r){let i=new URLSearchParams;return n&&i.set(`range`,JSON.stringify(n)),r!==void 0&&i.set(`index`,r),(await(await kx(e,`GET`,`/${t}/count`,{params:i})).json()).count}async function jx(e,t,n){await kx(e,`DELETE`,`/${t}`,{params:new URLSearchParams({key:JSON.stringify(n)})})}var qne=class{http;defs;getUserId;constructor(e=`/api`,t=globalThis.fetch.bind(globalThis),n={}){this.http={baseUrl:e,fetchImpl:t},this.getUserId=n.getUserId,this.defs=Object.fromEntries(sx.map(e=>[e.name,e]))}def(e){let t=this.defs[e];if(!t)throw Error(`ApiStorage: unknown store '${e}'`);return t}makeView(e,t,n,r,i=!1){return new Jne(this.http,this.def(e),e,t,n,this.getUserId,r,i)}readonly(e){return this.makeView(e)}readwrite(e){return this.makeView(e,void 0,void 0,void 0,!0)}async queryDomain(e){let t=await this.http.fetchImpl(`${this.http.baseUrl}/v1/query`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)});if(t.status===409){let e=await t.json();if(typeof e==`object`&&e&&`code`in e&&e.code===`domain_projection_unavailable`)return}if(!t.ok)throw Error(`ApiStorage: POST /v1/query → ${t.status}`);return zne(await t.json(),e.plan)}async transaction(e,t,n){let r=new Map,i=new Set,a=new Map,o=new Set(e),s=(e,n)=>{if(!o.has(e))throw Error(`store outside transaction scope`);if(n&&t!==`readwrite`)throw Error(`read-only transaction`);return this.makeView(e,r,i,a,n)},c=await n({readonly:e=>s(e,!1),readwrite:e=>s(e,!0)});return await this.flush(r,i,a),c}async flush(e,t,n){let r=Hne(sx.map(e=>e.name),e,t);r.length>0&&await kx(this.http,`POST`,`/tx`,{body:{ops:[...n.values(),...r]}})}async wipe(){await kx(this.http,`POST`,`/wipe`)}async close(){}},Jne=class{http;def;store;buffer;cleared;getUserId;checks;mutable;constructor(e,t,n,r,i,a,o,s=!1){this.http=e,this.def=t,this.store=n,this.buffer=r,this.cleared=i,this.getUserId=a,this.checks=o,this.mutable=s}dirty(){return Cx(this.store,this.buffer,this.cleared)}async get(e){let t=fx(e)?e:void 0,n;if(t){if(t.only===void 0)throw Error(`ApiStorage.get: needs a plain key or {only}; bounded ranges match no single row`);n=t.only}else n=e;let r=Bne(this.store,n,this.buffer);if(r)return r.hit?r.value:void 0;if(this.cleared?.has(this.store))return;let i=await Gne(this.http,this.store,n),a=Sx(this.store,n);return this.checks?.has(a)||this.checks?.set(a,{op:`check`,store:this.store,key:n,value:structuredClone(i??null)}),i}async getMany(e){return Promise.all(e.map(e=>this.get(e)))}async getAllFromIndexMany(e,t){return Promise.all(t.map(t=>this.getAllFromIndex(e,t)))}async getAll(e,t){let n=hx(e);return this.overlay(await this.serverRows(`all`,n,this.dirty()?void 0:t),t,n)}async getAllFromIndex(e,t,n){let r=hx(t);return this.overlay(await this.serverRows(`index/${encodeURIComponent(e)}`,r,this.dirty()?void 0:n),n,r,e)}async count(e){let t=hx(e);return this.dirty()?this.overlay(await this.serverRows(`all`,t),void 0,t).length:Ax(this.http,this.store,t)}async countFromIndex(e,t){let n=hx(t);return this.dirty()?this.overlay(await this.serverRows(`index/${encodeURIComponent(e)}`,n),void 0,n,e).length:Ax(this.http,this.store,n,e)}async serverRows(e,t,n){if(this.cleared?.has(this.store))return[];let r=await Kne(this.http,this.store,e,t,n);for(let e of r){let t=mx(this.def,e),n=Sx(this.store,t);this.checks?.has(n)||this.checks?.set(n,{op:`check`,store:this.store,key:t,value:structuredClone(e)})}return r}overlay(e,t,n,r){return Vne(this.def,this.store,this.buffer,this.cleared,e,t,n,r)}async put(e,t){if(!this.mutable)throw Error(`read-only store`);let n=this.getUserId?.(),r=n?dx(this.store,e,n):e,i=mx(this.def,r);if(this.store===`block_revisions`){let e=this.buffer?.get(Sx(this.store,i));if(e?.kind===`put`&&!Tx(e.value,r))throw Error(`immutable block revision collision`)}return this.buffer?(this.buffer.set(Sx(this.store,i),{kind:`put`,value:r}),i):(await kx(this.http,`POST`,`/tx`,{body:{ops:[{op:`put`,store:this.store,value:r}]}}),i)}async putMany(e,t){if(!this.mutable)throw Error(`read-only store`);if(this.buffer){let t=[];for(let n of e)t.push(await this.put(n));return t}let n=e.map(e=>this.getUserId?dx(this.store,e,this.getUserId()):e),r=n.map(e=>mx(this.def,e));return await kx(this.http,`POST`,`/tx`,{body:{ops:n.map(e=>({op:`put`,store:this.store,value:e}))}}),r}async delete(e){if(!this.mutable)throw Error(`read-only store`);if(this.store===`block_revisions`)throw Error(`block history requires explicit wipe`);let t=fx(e)?e:void 0;if(t){if(this.buffer){let e=await this.getAll(t);for(let t of e){let e=mx(this.def,t);this.buffer.set(Sx(this.store,e),{kind:`delete`,key:e})}return}await jx(this.http,this.store,t);return}let n=e;if(this.buffer){this.buffer.set(Sx(this.store,n),{kind:`delete`,key:n});return}await jx(this.http,this.store,n)}async clear(){if(!this.mutable)throw Error(`read-only store`);if(this.store===`block_revisions`)throw Error(`block history requires explicit wipe`);if(this.buffer){this.cleared?.add(this.store);let e=`${this.store}\u0000`;for(let t of[...this.buffer.keys()])t.startsWith(e)&&this.buffer.delete(t);return}await kx(this.http,`POST`,`/tx`,{body:{ops:[{op:`clear`,store:this.store}]}})}},Yne=`user-deleted-seed:`;function Mx(e){return`${Yne}${e}`}function Xne(e){if(!(typeof e!=`string`||!e.startsWith(`user-deleted-seed:`)))return e.slice(18)||void 0}function Zne(e){return typeof e==`string`&&e.startsWith(`seed:`)}function Nx(e){let t=new Set;for(let n of e)typeof n==`object`&&n&&`seedOrigin`in n&&n.seedOrigin===`seed`&&`id`in n&&typeof n.id==`string`&&t.add(n.id);return{seedNoteIds:t}}function Px(e,t,n){if(typeof t!=`object`||!t)return!0;switch(e){case`notes`:return!(`seedOrigin`in t&&t.seedOrigin===`seed`);case`block_index`:case`block_efforts`:case`block_equipment`:return!(`isStatic`in t&&t.isStatic===!0&&`noteId`in t&&typeof t.noteId==`string`&&n.seedNoteIds.has(t.noteId));case`efforts`:case`equipment`:return!(`registrySource`in t&&t.registrySource===`bundled`);case`property_overrides`:return!(`seedOrigin`in t&&t.seedOrigin===`seed`);case`meta`:return!Zne(`key`in t?t.key:void 0);default:return!0}}function Fx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ix(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function Lx(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function Rx(e){return typeof e==`number`&&Number.isFinite(e)}function zx(e){if(!Fx(e)||e.schema!==9)throw Error(`Incompatible seed schema; rebuild seed artifacts`);if(!Lx(e.version)||typeof e.builtAt!=`string`||!Number.isFinite(Date.parse(e.builtAt))||!Array.isArray(e.chunks))throw Error(`seed manifest failed shape validation`);for(let t of[`versionLabel`,`commit`,`name`,`description`])if(e[t]!==void 0&&typeof e[t]!=`string`)throw Error(`invalid seed manifest metadata`);if(e.repositoryUrl!==void 0&&(typeof e.repositoryUrl!=`string`||!/^https:\/\//.test(e.repositoryUrl)||new URL(e.repositoryUrl).username||new URL(e.repositoryUrl).password))throw Error(`invalid seed repository URL`);if(e.dirty!==void 0&&typeof e.dirty!=`boolean`)throw Error(`invalid seed manifest metadata`);let t=new Set,n=new Set;for(let r of e.chunks){if(!Fx(r)||typeof r.id!=`string`||!r.id||typeof r.path!=`string`||!/^chunks\/[a-zA-Z0-9._-]+\.json$/.test(r.path)||typeof r.sha256!=`string`||!/^[0-9a-f]{64}$/.test(r.sha256)||!Lx(r.bytes)||!Lx(r.count)||r.kind!==void 0&&r.kind!==`notes`||t.has(r.id)||n.has(r.path))throw Error(`seed manifest failed shape validation`);t.add(r.id),n.add(r.path)}if(e.notebooks!==void 0){if(!Array.isArray(e.notebooks))throw Error(`seed manifest failed shape validation`);for(let t of e.notebooks){if(!Fx(t)||typeof t.notebookId!=`string`||!t.notebookId||typeof t.label!=`string`||!Lx(t.count)||typeof t.indexPath!=`string`||!t.indexPath||!Lx(t.version)||typeof t.commit!=`string`||typeof t.builtAt!=`string`||typeof t.sha256!=`string`||!Lx(t.bytes))throw Error(`seed manifest failed shape validation`);if(`records`in t&&Array.isArray(t.records))throw Error(`seed manifest failed shape validation: manifest.notebooks must not contain inline records`)}}return e}function Bx(e){if(!Fx(e))throw Error(`notebook index failed shape validation`);if(typeof e.notebookId!=`string`||!e.notebookId||typeof e.label!=`string`||!e.label||typeof e.indexPath!=`string`||!e.indexPath||!Lx(e.version)||typeof e.commit!=`string`||typeof e.builtAt!=`string`||typeof e.sha256!=`string`||!Lx(e.bytes)||!Lx(e.count)||!Array.isArray(e.records))throw Error(`notebook index failed shape validation: missing required index summary or records`);for(let t of e.records)if(!Fx(t)||typeof t.uuid!=`string`||typeof t.path!=`string`||typeof t.recordPath!=`string`||typeof t.commit!=`string`||!Lx(t.version)||typeof t.sha256!=`string`)throw Error(`notebook index failed shape validation: invalid record ref`);return e}function Qne(e,t){if(e.telemetry===void 0)return;if(!Fx(e.telemetry)||!Array.isArray(e.telemetry.sessions)||!Array.isArray(e.telemetry.events))throw Error(`invalid seed telemetry`);let n=new Map;for(let r of e.telemetry.sessions){if(!Fx(r)||typeof r.id!=`string`||!r.id||n.has(r.id)||typeof r.noteId!=`string`||!r.noteId||typeof e.uuid==`string`&&r.noteId!==e.uuid||typeof r.blockId!=`string`||!Ix(r.blockVersion)||typeof r.blockContentId!=`string`||!Rx(r.startTime)||!Rx(r.endTime)||!Rx(r.duration)||typeof r.completed!=`boolean`||!Rx(r.createdAt))throw Error(`invalid seed session`);let i=t.find(e=>Fx(e)&&e.blockId===r.blockId);if(!Fx(i)||i.dataType!==`wod`||i.blockVersion!==r.blockVersion||i.blockContentId!==r.blockContentId)throw Error(`orphan or incompatible seed session pin`);n.set(r.id,r)}let r=new Set;for(let t of e.telemetry.events){if(!Fx(t)||typeof t.id!=`string`||!t.id||r.has(t.id)||typeof t.resultId!=`string`||typeof t.noteId!=`string`||!Rx(t.timestamp)||t.grain!==`event`&&t.grain!==`summary`||typeof t.outputType!=`string`||!Array.isArray(t.metrics)||!t.metrics.every(e=>Fx(e)&&typeof e.type==`string`)||t.grain===`summary`&&t.metrics.length!==1)throw Error(`invalid seed event`);let e=n.get(t.resultId);if(!e||t.noteId!==e.noteId||t.blockId!==e.blockId||t.blockVersion!==e.blockVersion||t.blockContentId!==e.blockContentId)throw Error(`orphan or incompatible seed event identity`);r.add(t.id)}}function Vx(e){if(!Array.isArray(e))throw Error(`seed chunk is not an array`);let t=new Set;for(let n of e){if(!Fx(n)||typeof n.path!=`string`||!n.path||n.path.startsWith(`/`)||n.path.split(`/`).includes(`..`)||t.has(n.path)||typeof n.content!=`string`||!Fx(n.blocks)||!Array.isArray(n.blockIndex)||!Array.isArray(n.blockEfforts)||!Array.isArray(n.blockEquipment))throw Error(`seed chunk row failed shape validation`);t.add(n.path);for(let[e,t]of Object.entries(n.blocks))if(!Fx(t)||t.id!==e||!e||t.version!==1||t.sourceRevision!==1||!Lx(t.from)||!Ix(t.to)||t.from>=t.to||t.to>n.content.length||![`wod`,`query`,`widget`,`embed`].includes(String(t.kind))||(t.kind===`wod`?![`time`,`log`].includes(String(t.dialect)):t.dialect!==void 0)||t.sport!==void 0&&typeof t.sport!=`string`)throw Error(`invalid seed block range or revision`);ho(n.content,n.blocks,1,{registeredWidgets:Qb});let e=new Set,r=fo(n.content,{registeredWidgets:Qb});for(let t of n.blockIndex){if(!Fx(t)||typeof t.blockId!=`string`)throw Error(`invalid seed projection`);let i=n.blocks[t.blockId];if(!Fx(i)||e.has(t.blockId)||typeof t.id!=`string`||typeof t.noteId!=`string`||t.id!==`${t.noteId}:${t.blockId}`||t.blockVersion!==1||t.sourceRevision!==1||t.from!==i.from||t.to!==i.to||t.dataType!==i.kind||t.rawContent!==n.content.slice(Number(i.from),Number(i.to))||typeof t.noteTitle!=`string`||typeof t.createdAt!=`number`||!Number.isFinite(t.createdAt)||t.sourcePath!==n.path||t.isStatic!==!0)throw Error(`orphan or incompatible seed projection`);if(`segmentId`in t||`segmentVersion`in t)throw Error(`incompatible seed projection`);for(let e of[`sourceId`,`routeId`,`blockContentId`])if(t[e]!==void 0&&typeof t[e]!=`string`)throw Error(`invalid seed projection metadata`);if(t.position!==void 0&&!Lx(t.position))throw Error(`invalid seed projection position`);if(i.kind===`wod`){let e=r.find(e=>e.from===i.from&&e.to===i.to);if(t.blockContentId!==Ga(e?.scriptBlock?.content??n.content.slice(Number(i.from),Number(i.to))))throw Error(`invalid seed workout fingerprint`)}else if(t.blockContentId!==void 0)throw Error(`non-workout seed fingerprint`);e.add(t.blockId)}if(e.size!==Object.keys(n.blocks).length)throw Error(`missing actionable seed projection`);let i=new Set;for(let t of n.blockEfforts){if(!Fx(t)||typeof t.blockId!=`string`||typeof t.noteId!=`string`||typeof t.effortSlug!=`string`||!t.effortSlug)throw Error(`invalid seed effort identity`);let r=n.blocks[t.blockId];if(t.id!==`${t.noteId}:${t.blockId}:${t.effortSlug}`||i.has(String(t.id))||!Fx(r)||r.kind!==`wod`||!e.has(t.blockId)||t.sourcePath!==n.path||t.isStatic!==!0||typeof t.createdAt!=`number`)throw Error(`orphan or incompatible seed effort link`);let a=n.blockIndex.find(e=>Fx(e)&&e.blockId===t.blockId);if(!Fx(a)||t.noteId!==a.noteId||t.blockContentId!==a.blockContentId||!Number.isFinite(t.createdAt))throw Error(`invalid seed effort metadata`);i.add(String(t.id))}let a=new Set;for(let t of n.blockEquipment){if(!Fx(t)||typeof t.blockId!=`string`||typeof t.noteId!=`string`||typeof t.equipmentSlug!=`string`||!t.equipmentSlug)throw Error(`invalid seed equipment identity`);let r=n.blocks[t.blockId];if(t.id!==`${t.noteId}:${t.blockId}:${t.equipmentSlug}`||a.has(String(t.id))||!Fx(r)||r.kind!==`wod`||!e.has(t.blockId)||t.sourcePath!==n.path||t.isStatic!==!0||typeof t.createdAt!=`number`)throw Error(`orphan or incompatible seed equipment link`);let i=n.blockIndex.find(e=>Fx(e)&&e.blockId===t.blockId);if(!Fx(i)||t.noteId!==i.noteId||t.blockContentId!==i.blockContentId||!Number.isFinite(t.createdAt))throw Error(`invalid seed equipment metadata`);a.add(String(t.id))}Qne(n,n.blockIndex)}return e}function Hx(e){return Vx([e])[0]}function Ux(e,t,n){return`${e}:${t}:${n}`}function Wx(e){let t=[];for(let[n,r]of Object.entries(e.metrics)){if(typeof r!=`string`&&typeof r!=`number`)continue;let e=String(r).trim().match(/^([+-]?\d+(?:\.\d+)?)\s*([A-Za-z%/][\w%/.-]*)$/);e?t.push({kind:`metric`,type:n,value:Number(e[1]),unit:e[2]}):t.push({kind:`metric`,type:n,value:r})}for(let[n,r]of Object.entries(e.summaries))t.push({kind:`metric`,type:`summaries.${n}`,value:r});for(let[n,r]of Object.entries(e.widgets??{}))t.push({kind:`metric`,type:`widgets.${n}`,value:r});for(let n of e.tags)t.push({kind:`tag`,slug:n});for(let n of e.functions)t.push({kind:`function`,name:n});return t}async function Gx(e,t){let n=ao(t.targetNotebookId);if(no(n))throw Error(`Notebook '${n}' is read-only and cannot store overrides.`);if(n===`notebook/journal`||n===`notebook/playground`)throw Error(`Property overrides belong in 'notebook/custom' or a shared user Notebook, not '${n}'.`);let r=t.slug.trim().toLowerCase();if(!r)throw Error(`Property override requires a non-empty canonical slug.`);let i=io(n),a=`override/${i}/${t.kind}/${r}`,o=`${t.kind}-override-${i}-${r}`,s=Date.now(),c=t.rawContent,l=Nb(c);(typeof l.id!=`string`||!l.id.trim())&&(c=wo(c,[`id`],o)),(typeof l.slug!=`string`||l.slug.trim()!==r)&&(c=wo(c,[`slug`],r));let u=t.title?.trim()||r,d;if(t.kind===`effort`){let e=Wl(c);if(e.errors.length>0)throw Error(e.errors.join(`
101
+ `),r=u(e);r.sessions.push(n.session),r.events.push(...n.events)}catch(e){c.push(e instanceof Error?e.message:String(e))}return{bundles:[...l.values()],errors:c}}var Tne=`0.59.2236`,Qb=co,Ene=`1b671a64-40d5-491e-99b0-da01ff1f3341`,Dne={core:0,community:1,imported:2,user:3};function One(e,t){if(t)return t;if(!e)return`core`;if(e===`user`)return`user`;let n=e.startsWith(`seed:`)?e.slice(5):e;return n===`core`||n===`efforts`||n===`equipment`?`core`:n===`community`||n.startsWith(`community-`)||n===`common`?`community`:`imported`}function $b(e,t){return Dne[One(e,t)]}var ex=`wodwiki.seed`,tx=`efforts`,nx=`equipment`,rx=`canvas`;function ix(e){return`seed:${e}`}function kne(e){return e.startsWith(`seed:`)?e.slice(5):e}function ax(e){return{key:e,schema:9,seedVersion:0,builtAt:``,importedAt:0,chunks:{},claim:null}}function ox(e){let t=/^notebook\.(.+)$/.exec(e)?.[1];return t&&t!==`_root`?t:void 0}function Ane(e){let t=/^---\r?\n([\s\S]*?)\r?\n---/.exec(e);return t?.[1]&&!/^template:\s*canvas\s*$/m.test(t[1])?null:t?.[1]?.match(/^route:\s*(\S+)\s*$/m)?.[1]?.replace(/^\//,``)||null}function jne(e,t,n){let r=e.split(`/`),i=(r.at(-1)??``).replace(/\.md$/i,``),a=r.slice(2).map(e=>e.replace(/\.md$/i,``)).join(`/`);if(n===`canvas`)return`guides:${Ane(t)??a}`;if(n===`dashboards`)return`dashboards`;if(n===`efforts`)return`efforts`;if(n===`equipment`)return`equipment`;if(n.startsWith(`notebook.`)){let e=ox(n);return e?i.toLowerCase()===`readme`?`notebook:${e}`:`notebook:${a}`:`notebook:_root`}}var sx=[{name:`notes`,keyPath:[`id`],indexes:[{name:`by-date`,keyPath:[`date`]},{name:`by-created`,keyPath:[`createdAt`]},{name:`by-type`,keyPath:[`type`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`page`,keyPath:[`id`],indexes:[{name:`by-date`,keyPath:[`date`],unique:!0},{name:`by-slug`,keyPath:[`slug`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`page_notes`,keyPath:[`id`],indexes:[{name:`by-page`,keyPath:[`pageId`]},{name:`by-note`,keyPath:[`noteId`]},{name:`by-page-note`,keyPath:[`pageId`,`noteId`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`tags`,keyPath:[`id`],indexes:[{name:`by-label`,keyPath:[`label`],unique:!0},{name:`by-type`,keyPath:[`type`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`tag_types`,keyPath:[`id`],indexes:[{name:`by-name`,keyPath:[`name`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`note_tags`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-tag`,keyPath:[`tagId`]},{name:`by-note-tag`,keyPath:[`noteId`,`tagId`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`block_revisions`,keyPath:[`noteId`,`blockId`,`version`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-block`,keyPath:[`noteId`,`blockId`]}]},{name:`sessions`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-completed`,keyPath:[`createdAt`]},{name:`by-content`,keyPath:[`blockContentId`]},{name:`by-block`,keyPath:[`blockId`]},{name:`by-page`,keyPath:[`pageId`]},{name:`by-origin`,keyPath:[`origin`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`attachments`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-time`,keyPath:[`createdAt`]},{name:`by-page`,keyPath:[`pageId`]},{name:`by-result`,keyPath:[`resultId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`events`,keyPath:[`id`],indexes:[{name:`by-timestamp`,keyPath:[`timestamp`]},{name:`by-result-grain`,keyPath:[`resultId`,`grain`]},{name:`by-content-grain`,keyPath:[`blockContentId`,`grain`]},{name:`by-effort`,keyPath:[`effortSlug`]},{name:`by-outputType`,keyPath:[`outputType`]},{name:`by-grain`,keyPath:[`grain`]},{name:`by-metric-date`,keyPath:[`metricDateKeys`],multiEntry:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`field_catalog`,keyPath:[`id`],indexes:[{name:`by-path`,keyPath:[`path`]}]},{name:`field_sources`,keyPath:[`id`],indexes:[]},{name:`field_values`,keyPath:[`key`],indexes:[{name:`by-field`,keyPath:[`fieldId`]}]},{name:`field_catalog_meta`,keyPath:[`id`],indexes:[]},{name:`efforts`,keyPath:[`slug`],indexes:[{name:`by-discipline`,keyPath:[`baseAttributes.discipline`]},{name:`by-source`,keyPath:[`registrySource`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`equipment`,keyPath:[`slug`],indexes:[{name:`by-source`,keyPath:[`registrySource`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`block_index`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-content`,keyPath:[`blockContentId`]},{name:`by-type`,keyPath:[`dataType`]},{name:`by-source`,keyPath:[`sourceId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`block_efforts`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-effort`,keyPath:[`effortSlug`]},{name:`by-block`,keyPath:[`blockContentId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`block_equipment`,keyPath:[`id`],indexes:[{name:`by-note`,keyPath:[`noteId`]},{name:`by-equipment`,keyPath:[`equipmentSlug`]},{name:`by-block`,keyPath:[`blockContentId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`notebook_links`,keyPath:[`id`],indexes:[{name:`by-notebook`,keyPath:[`notebookId`]},{name:`by-note`,keyPath:[`noteId`]},{name:`by-target`,keyPath:[`targetKind`,`targetId`]},{name:`by-notebook-target`,keyPath:[`notebookId`,`targetKind`,`targetId`],unique:!0},{name:`by-user`,keyPath:[`userId`]}]},{name:`property_overrides`,keyPath:[`id`],indexes:[{name:`by-notebook`,keyPath:[`notebookId`]},{name:`by-kind-slug`,keyPath:[`kind`,`slug`]},{name:`by-owner-note`,keyPath:[`ownerNoteId`]},{name:`by-user`,keyPath:[`userId`]}]},{name:`meta`,keyPath:[`key`],indexes:[]},{name:`memberships`,keyPath:[`id`],indexes:[],system:!0}],cx=`default`;function lx(e=Date.now()){return{id:cx,displayName:`Anonymous`,createdAt:e}}var ux=[`notes`,`page`,`page_notes`,`tags`,`tag_types`,`note_tags`,`sessions`,`attachments`,`events`,`efforts`,`block_index`,`block_efforts`,`equipment`,`block_equipment`,`notebook_links`,`property_overrides`],Mne=Object.fromEntries(ux.map(e=>[e,!0]));function dx(e,t,n){if(!Mne[e]||typeof t!=`object`||!t||Array.isArray(t))return t;let r=t;return r.seedOrigin===`seed`||r.userId===n?t:{...r,userId:n}}function fx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&(`only`in e||`lower`in e||`upper`in e||`lowerOpen`in e||`upperOpen`in e)}function px(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;let t=n;if(!(e in t))return;n=t[e]}if(n!==null&&typeof n!=`object`&&n!==void 0)return n}function mx(e,t){let n=e.keyPath.map(e=>px(t,e));for(let[t,r]of n.entries())if(r===void 0)throw Error(`keyFromValue(${e.name}): keyPath part '${e.keyPath[t]}' missing on value`);let r=n;return r.length===1?r[0]:r}function Nne(e){return encodeURIComponent(JSON.stringify(e))}function hx(e){if(e===void 0)return;if(!fx(e))return{only:e};if(e.only!==void 0)return e;let t={};return e.lower!==void 0&&e.lower!==null&&(t.lower=e.lower,t.lowerOpen=e.lowerOpen===!0),e.upper!==void 0&&e.upper!==null&&(t.upper=Array.isArray(e.upper)?e.upper.map(e=>Array.isArray(e)&&e.length===0?`￿`:e):e.upper,t.upperOpen=e.upperOpen===!0),t.lower!==void 0||t.upper!==void 0?t:void 0}function gx(e,t){if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t))return Array.isArray(e)?1:-1;for(let n=0;n<Math.min(e.length,t.length);n++){let r=gx(e[n],t[n]);if(r!==0)return r}return e.length-t.length}return typeof e==`number`&&typeof t==`number`?e<t?-1:+(e>t):typeof e==`number`||typeof t==`number`?typeof e==`number`?-1:1:e<t?-1:+(e>t)}function _x(e,t){if(t.only!==void 0)return gx(e,t.only)===0;if(t.lower!==void 0){let n=gx(e,t.lower);if(n<0||n===0&&t.lowerOpen===!0)return!1}if(t.upper!==void 0){let n=gx(e,t.upper);if(n>0||n===0&&t.upperOpen===!0)return!1}return!0}function vx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function yx(e,t){return t.every(t=>e[t]===void 0||typeof e[t]==`string`)}function bx(e,t){return t.every(t=>typeof e[t]==`number`&&Number.isFinite(e[t]))}function xx(e){if(!vx(e)||typeof e.id!=`string`||typeof e.title!=`string`||typeof e.rawContent!=`string`||!Number.isSafeInteger(e.sourceRevision)||typeof e.sourceRevision!=`number`||e.sourceRevision<1||!vx(e.blocks)||!bx(e,[`createdAt`])||e.date!==void 0&&!bx(e,[`date`])||!yx(e,[`type`,`sourceId`,`notebookId`,`sourcePath`,`seedOrigin`,`seedChunkId`,`feedOrigin`,`feedSourceId`])||e.tags!==void 0&&(!Array.isArray(e.tags)||!e.tags.every(e=>typeof e==`string`)))return!1;try{return ho(e.rawContent,e.blocks,e.sourceRevision),!0}catch{return!1}}function Pne(e){return vx(e)&&typeof e.id==`string`&&typeof e.noteId==`string`&&typeof e.blockId==`string`&&bx(e,[`blockVersion`,`sourceRevision`,`from`,`to`,`createdAt`])&&e.id===`${e.noteId}:${e.blockId}`&&typeof e.blockVersion==`number`&&Number.isSafeInteger(e.blockVersion)&&e.blockVersion>0&&typeof e.sourceRevision==`number`&&Number.isSafeInteger(e.sourceRevision)&&e.sourceRevision>0&&typeof e.from==`number`&&Number.isSafeInteger(e.from)&&e.from>=0&&typeof e.to==`number`&&Number.isSafeInteger(e.to)&&e.to>e.from&&[`wod`,`query`,`widget`,`embed`].includes(String(e.dataType))&&typeof e.rawContent==`string`&&typeof e.noteTitle==`string`&&yx(e,[`blockContentId`,`sourceId`,`sourcePath`,`routeId`])&&(e.position===void 0||bx(e,[`position`]))&&(e.isStatic===void 0||typeof e.isStatic==`boolean`)}function Fne(e){return vx(e)&&typeof e.id==`string`&&typeof e.label==`string`&&bx(e,[`createdAt`])&&yx(e,[`type`])}function Ine(e){return vx(e)&&typeof e.id==`string`&&bx(e,[`createdAt`])&&yx(e,[`date`,`slug`,`title`])}function Lne(e){return vx(e)&&typeof e.id==`string`&&typeof e.noteId==`string`&&typeof e.pageId==`string`&&bx(e,[`createdAt`])&&(e.position===void 0||bx(e,[`position`]))}function Rne(e){return vx(e)&&xx(e.note)&&Array.isArray(e.tags)&&e.tags.every(Fne)&&Array.isArray(e.links)&&e.links.every(Lne)&&Array.isArray(e.pages)&&e.pages.every(Ine)}function zne(e,t){if(!vx(e)||e.projectionVersion!==4||e.plan!==t||!Array.isArray(e.rows)||typeof e.selectedCount!=`number`||!Number.isSafeInteger(e.selectedCount)||e.selectedCount<0||typeof e.matchedCount!=`number`||!Number.isSafeInteger(e.matchedCount)||e.matchedCount<0||e.matchedCount>e.selectedCount||e.rows.length>e.matchedCount)throw Error(`ApiStorage: invalid or stale domain projection response`);let n={projectionVersion:4,selectedCount:e.selectedCount,matchedCount:e.matchedCount};switch(t){case`notes`:if(e.rows.every(xx))return{...n,plan:t,rows:e.rows};break;case`blocks`:if(e.rows.every(Pne))return{...n,plan:t,rows:e.rows};break;case`detail`:if(e.rows.every(Rne))return{...n,plan:t,rows:e.rows}}throw Error(`ApiStorage: invalid domain query rows`)}var Sx=(e,t)=>`${e}\u0000${JSON.stringify(t)}`;function Cx(e,t,n){if(n?.has(e))return!0;if(!t)return!1;let r=`${e}\u0000`;for(let e of t.keys())if(e.startsWith(r))return!0;return!1}function Bne(e,t,n){if(!n)return;let r=n.get(Sx(e,t));if(r)return r.kind===`put`?{hit:!0,value:r.value}:{hit:!1}}function Vne(e,t,n,r,i,a,o,s){if(!n||!Cx(t,n,r))return a===void 0?i:i.slice(0,a);let c=new Map;if(!r?.has(t))for(let t of i)c.set(JSON.stringify(mx(e,t)),t);let l=`${t}\u0000`;for(let[e,t]of n)e.startsWith(l)&&(t.kind===`put`?c.set(e.slice(l.length),t.value):c.delete(e.slice(l.length)));let u=s?e.indexes.find(e=>e.name===s):void 0;if(s&&!u)throw Error(`unknown index '${s}' for ${t}`);let d=t=>{if(!u)return mx(e,t);let n=u.keyPath.map(e=>px(t,e));if(n.some(e=>e===void 0))return;let r=n.filter(e=>e!==void 0);return r.length===1?r[0]:r},f=e=>{if(u?.multiEntry){let t=e;for(let e of u.keyPath[0].split(`.`)){if(typeof t!=`object`||!t||!(e in t))return!1;t=Reflect.get(t,e)}return Array.isArray(t)&&t.some(e=>(typeof e==`string`||typeof e==`number`)&&(!o||_x(e,o)))}let t=d(e);return t!==void 0&&(!o||_x(t,o))},p=[...c.values()].filter(f);return p.sort((t,n)=>{let r=gx(mx(e,t),mx(e,n));if(u?.multiEntry)return r;let i=d(t),a=d(n);return i!==void 0&&a!==void 0&&gx(i,a)||r}),a===void 0?p:p.slice(0,a)}function Hne(e,t,n){let r=new Set(e),i=[];for(let e of n)r.has(e)&&i.push({op:`clear`,store:e});for(let[e,n]of t){let t=e.indexOf(`\0`),a=e.slice(0,t);r.has(a)&&(n.kind===`put`?i.push({op:`put`,store:a,value:n.value}):i.push({op:`delete`,store:a,key:JSON.parse(e.slice(t+1))}))}return i}var wx=class extends Error{status;code;constructor(e,t,n){super(t),this.status=e,this.code=n,this.name=`StorageError`}};function Tx(e,t){if(Object.is(e,t))return!0;if(e instanceof ArrayBuffer&&t instanceof ArrayBuffer){let n=new Uint8Array(e),r=new Uint8Array(t);return n.length===r.length&&n.every((e,t)=>e===r[t])}if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>Tx(e,t[n]));let n=Object.keys(e).filter(t=>Reflect.get(e,t)!==void 0),r=Object.keys(t).filter(e=>Reflect.get(t,e)!==void 0);return n.length===r.length&&n.every(n=>Object.hasOwn(t,n)&&Tx(Reflect.get(e,n),Reflect.get(t,n)))}function Ex(e){if(typeof e!=`object`||!e||Array.isArray(e))throw new wx(400,`storage row must be an object`);return e}function Dx(e,t){if(e!==`notes`&&e!==`block_revisions`&&e!==`sessions`&&e!==`block_index`)return;let n=Ex(t),r=e=>typeof n[e]==`number`&&Number.isSafeInteger(n[e])&&n[e]>0,i=e=>typeof n[e]==`string`&&n[e].length>0;if(e===`notes`){if(!i(`id`)||typeof n.title!=`string`||typeof n.rawContent!=`string`||!r(`sourceRevision`)||typeof n.createdAt!=`number`||!Number.isFinite(n.createdAt)||`segments`in n||`segmentIds`in n||n.date!==void 0&&(typeof n.date!=`number`||!Number.isFinite(n.date))||n.seedOrigin!==void 0&&n.seedOrigin!==`seed`&&n.seedOrigin!==`user`||n.feedOrigin!==void 0&&n.feedOrigin!==`feed`&&n.feedOrigin!==`user`||n.feedOrigin===`feed`&&(n.seedOrigin===void 0||typeof n.feedSourceId!=`string`||n.feedSourceId.length===0)||n.feedOrigin===`user`&&n.seedOrigin===`seed`||n.feedSourceId!==void 0&&n.feedOrigin!==`feed`||n.seedVersion!==void 0&&!(typeof n.seedVersion==`number`&&Number.isSafeInteger(n.seedVersion)&&n.seedVersion>=0)||n.tags!==void 0&&(!Array.isArray(n.tags)||!n.tags.every(e=>typeof e==`string`))||n.public!==void 0&&typeof n.public!=`boolean`||n.notebookIds!==void 0&&(!Array.isArray(n.notebookIds)||!n.notebookIds.every(e=>typeof e==`string`))||n.provenance!==void 0&&(typeof n.provenance!=`object`||n.provenance===null||Array.isArray(n.provenance)||typeof n.provenance.sourceNoteId!=`string`)||[`type`,`sourceId`,`sourcePath`,`notebookId`,`seedChunkId`,`feedSourceId`].some(e=>n[e]!==void 0&&typeof n[e]!=`string`))throw new wx(400,`invalid whole Note`,`invalid_note_blocks`);try{ho(n.rawContent,Ex(n.blocks),n.sourceRevision)}catch(e){throw new wx(400,e instanceof Error?e.message:`invalid block map`,`invalid_note_blocks`)}}else if(e===`block_revisions`){if(!i(`noteId`)||!i(`blockId`)||!r(`version`)||typeof n.rawContent!=`string`||typeof n.savedAt!=`number`||!Number.isFinite(n.savedAt)||![`wod`,`query`,`widget`,`embed`].includes(String(n.kind))||(n.kind===`wod`?n.dialect!==`time`&&n.dialect!==`log`:n.dialect!==void 0||n.sport!==void 0)||n.sport!==void 0&&typeof n.sport!=`string`)throw new wx(400,`invalid block revision`,`invalid_note_blocks`);try{ho(n.rawContent,{[String(n.blockId)]:{id:String(n.blockId),kind:n.kind,version:n.version,sourceRevision:1,from:0,to:n.rawContent.length,...n.dialect===void 0?{}:{dialect:n.dialect},...n.sport===void 0?{}:{sport:n.sport}}},1)}catch(e){throw new wx(400,e instanceof Error?e.message:`invalid revision source`,`invalid_note_blocks`)}}else if(e===`sessions`){if(!i(`noteId`)||!i(`blockId`)||!r(`blockVersion`)||n.public!==void 0&&typeof n.public!=`boolean`||n.notebookIds!==void 0&&(!Array.isArray(n.notebookIds)||!n.notebookIds.every(e=>typeof e==`string`))||[`segmentId`,`segmentVersion`,`version`,`rawContent`,`script`,`serializedScript`,`source`,`data`,`logs`].some(e=>e in n))throw new wx(400,`Session requires immutable block pin`,`invalid_session_pin`)}else if(!i(`noteId`)||!i(`blockId`)||!r(`blockVersion`)||!r(`sourceRevision`)||n.id!==`${n.noteId}:${n.blockId}`||!Number.isSafeInteger(n.from)||!Number.isSafeInteger(n.to)||`segmentId`in n||`segmentVersion`in n||![`wod`,`query`,`widget`,`embed`].includes(String(n.dataType))||typeof n.rawContent!=`string`||typeof n.noteTitle!=`string`||typeof n.from!=`number`||typeof n.to!=`number`||n.from<0||n.to<=n.from)throw new wx(400,`invalid actionable block projection`,`invalid_note_blocks`)}function Une(e,t){if(e===void 0||Tx(e,t))return;let n=Ex(e),r=Ex(t);if(typeof n.sourceRevision!=`number`||typeof r.sourceRevision!=`number`||r.sourceRevision<n.sourceRevision||(!Tx(n.blocks,r.blocks)||n.rawContent!==r.rawContent)&&r.sourceRevision<=n.sourceRevision)throw new wx(409,`stale Note source revision`,`transaction_conflict`)}function Wne(e,t){if(e===void 0)return;let n=Ex(e),r=Ex(t);if(n.noteId!==r.noteId||n.blockId!==r.blockId||n.blockVersion!==r.blockVersion)throw new wx(409,`Session pin is immutable`,`invalid_session_pin`)}async function Ox(e,t,n){let r=[];for(let t of e)for(let e of Object.values(t.blocks))r.push([t.id,e.id,e.version]);for(let e of t)r.push([e.noteId,e.blockId,e.blockVersion]);let i=await n(r),a=0;for(let t of e)for(let e of Object.values(t.blocks)){let n=i[a++];if(!n||n.kind!==e.kind||n.rawContent!==t.rawContent.slice(e.from,e.to)||n.dialect!==e.dialect||n.sport!==e.sport)throw new wx(409,`Note block has no matching immutable revision`,`invalid_note_blocks`)}for(let e=0;e<t.length;e++){let e=i[a++];if(!e||e.kind!==`wod`)throw new wx(409,`Session pin must reference a saved workout revision`,`invalid_session_pin`)}}async function kx(e,t,n,r){let i=r?.params?.toString(),a=await e.fetchImpl(`${e.baseUrl}/v1${n}${i?`?${i}`:``}`,{method:t,headers:r?.body===void 0?void 0:{"content-type":`application/json`},body:r?.body===void 0?void 0:JSON.stringify(r.body)});if(!a.ok)throw Error(`ApiStorage: ${t} /v1${n} → ${a.status}`);return a}async function Gne(e,t,n){let r=await e.fetchImpl(`${e.baseUrl}/v1/${t}/get?key=${Nne(n)}`);if(r.status!==404){if(!r.ok)throw Error(`ApiStorage: GET /v1/${t}/get → ${r.status}`);return await r.json()}}async function Kne(e,t,n,r,i){let a=new URLSearchParams;return r&&a.set(`range`,JSON.stringify(r)),i!==void 0&&a.set(`count`,String(i)),await(await kx(e,`GET`,`/${t}/${n}`,{params:a})).json()}async function Ax(e,t,n,r){let i=new URLSearchParams;return n&&i.set(`range`,JSON.stringify(n)),r!==void 0&&i.set(`index`,r),(await(await kx(e,`GET`,`/${t}/count`,{params:i})).json()).count}async function jx(e,t,n){await kx(e,`DELETE`,`/${t}`,{params:new URLSearchParams({key:JSON.stringify(n)})})}var qne=class{http;defs;getUserId;writeChain=Promise.resolve();constructor(e=`/api`,t=globalThis.fetch.bind(globalThis),n={}){this.http={baseUrl:e,fetchImpl:t},this.getUserId=n.getUserId,this.defs=Object.fromEntries(sx.map(e=>[e.name,e]))}def(e){let t=this.defs[e];if(!t)throw Error(`ApiStorage: unknown store '${e}'`);return t}makeView(e,t,n,r,i=!1){return new Jne(this.http,this.def(e),e,t,n,this.getUserId,r,i)}readonly(e){return this.makeView(e)}readwrite(e){return this.makeView(e,void 0,void 0,void 0,!0)}async queryDomain(e){let t=await this.http.fetchImpl(`${this.http.baseUrl}/v1/query`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)});if(t.status===409){let e=await t.json();if(typeof e==`object`&&e&&`code`in e&&e.code===`domain_projection_unavailable`)return}if(!t.ok)throw Error(`ApiStorage: POST /v1/query → ${t.status}`);return zne(await t.json(),e.plan)}async transaction(e,t,n){let r=async()=>{let r=new Map,i=new Set,a=new Map,o=new Set(e),s=(e,n)=>{if(!o.has(e))throw Error(`store outside transaction scope`);if(n&&t!==`readwrite`)throw Error(`read-only transaction`);return this.makeView(e,r,i,a,n)},c=await n({readonly:e=>s(e,!1),readwrite:e=>s(e,!0)});return await this.flush(r,i,a),c};if(t!==`readwrite`)return r();let i=this.writeChain.then(r,r);return this.writeChain=i.then(()=>void 0,()=>void 0),i}async flush(e,t,n){let r=Hne(sx.map(e=>e.name),e,t);r.length>0&&await kx(this.http,`POST`,`/tx`,{body:{ops:[...n.values(),...r]}})}async wipe(){await kx(this.http,`POST`,`/wipe`)}async close(){}},Jne=class{http;def;store;buffer;cleared;getUserId;checks;mutable;constructor(e,t,n,r,i,a,o,s=!1){this.http=e,this.def=t,this.store=n,this.buffer=r,this.cleared=i,this.getUserId=a,this.checks=o,this.mutable=s}dirty(){return Cx(this.store,this.buffer,this.cleared)}async get(e){let t=fx(e)?e:void 0,n;if(t){if(t.only===void 0)throw Error(`ApiStorage.get: needs a plain key or {only}; bounded ranges match no single row`);n=t.only}else n=e;let r=Bne(this.store,n,this.buffer);if(r)return r.hit?r.value:void 0;if(this.cleared?.has(this.store))return;let i=await Gne(this.http,this.store,n),a=Sx(this.store,n);return this.checks?.has(a)||this.checks?.set(a,{op:`check`,store:this.store,key:n,value:structuredClone(i??null)}),i}async getMany(e){return Promise.all(e.map(e=>this.get(e)))}async getAllFromIndexMany(e,t){return Promise.all(t.map(t=>this.getAllFromIndex(e,t)))}async getAll(e,t){let n=hx(e);return this.overlay(await this.serverRows(`all`,n,this.dirty()?void 0:t),t,n)}async getAllFromIndex(e,t,n){let r=hx(t);return this.overlay(await this.serverRows(`index/${encodeURIComponent(e)}`,r,this.dirty()?void 0:n),n,r,e)}async count(e){let t=hx(e);return this.dirty()?this.overlay(await this.serverRows(`all`,t),void 0,t).length:Ax(this.http,this.store,t)}async countFromIndex(e,t){let n=hx(t);return this.dirty()?this.overlay(await this.serverRows(`index/${encodeURIComponent(e)}`,n),void 0,n,e).length:Ax(this.http,this.store,n,e)}async serverRows(e,t,n){if(this.cleared?.has(this.store))return[];let r=await Kne(this.http,this.store,e,t,n);for(let e of r){let t=mx(this.def,e),n=Sx(this.store,t);this.checks?.has(n)||this.checks?.set(n,{op:`check`,store:this.store,key:t,value:structuredClone(e)})}return r}overlay(e,t,n,r){return Vne(this.def,this.store,this.buffer,this.cleared,e,t,n,r)}async put(e,t){if(!this.mutable)throw Error(`read-only store`);let n=this.getUserId?.(),r=n?dx(this.store,e,n):e,i=mx(this.def,r);if(this.store===`block_revisions`){let e=this.buffer?.get(Sx(this.store,i));if(e?.kind===`put`&&!Tx(e.value,r))throw Error(`immutable block revision collision`)}return this.buffer?(this.buffer.set(Sx(this.store,i),{kind:`put`,value:r}),i):(await kx(this.http,`POST`,`/tx`,{body:{ops:[{op:`put`,store:this.store,value:r}]}}),i)}async putMany(e,t){if(!this.mutable)throw Error(`read-only store`);if(this.buffer){let t=[];for(let n of e)t.push(await this.put(n));return t}let n=e.map(e=>this.getUserId?dx(this.store,e,this.getUserId()):e),r=n.map(e=>mx(this.def,e));return await kx(this.http,`POST`,`/tx`,{body:{ops:n.map(e=>({op:`put`,store:this.store,value:e}))}}),r}async delete(e){if(!this.mutable)throw Error(`read-only store`);if(this.store===`block_revisions`)throw Error(`block history requires explicit wipe`);let t=fx(e)?e:void 0;if(t){if(this.buffer){let e=await this.getAll(t);for(let t of e){let e=mx(this.def,t);this.buffer.set(Sx(this.store,e),{kind:`delete`,key:e})}return}await jx(this.http,this.store,t);return}let n=e;if(this.buffer){this.buffer.set(Sx(this.store,n),{kind:`delete`,key:n});return}await jx(this.http,this.store,n)}async clear(){if(!this.mutable)throw Error(`read-only store`);if(this.store===`block_revisions`)throw Error(`block history requires explicit wipe`);if(this.buffer){this.cleared?.add(this.store);let e=`${this.store}\u0000`;for(let t of[...this.buffer.keys()])t.startsWith(e)&&this.buffer.delete(t);return}await kx(this.http,`POST`,`/tx`,{body:{ops:[{op:`clear`,store:this.store}]}})}},Yne=`user-deleted-seed:`;function Mx(e){return`${Yne}${e}`}function Xne(e){if(!(typeof e!=`string`||!e.startsWith(`user-deleted-seed:`)))return e.slice(18)||void 0}function Zne(e){return typeof e==`string`&&e.startsWith(`seed:`)}function Nx(e){let t=new Set;for(let n of e)typeof n==`object`&&n&&`seedOrigin`in n&&n.seedOrigin===`seed`&&`id`in n&&typeof n.id==`string`&&t.add(n.id);return{seedNoteIds:t}}function Px(e,t,n){if(typeof t!=`object`||!t)return!0;switch(e){case`notes`:return!(`seedOrigin`in t&&t.seedOrigin===`seed`);case`block_index`:case`block_efforts`:case`block_equipment`:return!(`isStatic`in t&&t.isStatic===!0&&`noteId`in t&&typeof t.noteId==`string`&&n.seedNoteIds.has(t.noteId));case`efforts`:case`equipment`:return!(`registrySource`in t&&t.registrySource===`bundled`);case`property_overrides`:return!(`seedOrigin`in t&&t.seedOrigin===`seed`);case`meta`:return!Zne(`key`in t?t.key:void 0);default:return!0}}function Fx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ix(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function Lx(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function Rx(e){return typeof e==`number`&&Number.isFinite(e)}function zx(e){if(!Fx(e)||e.schema!==9)throw Error(`Incompatible seed schema; rebuild seed artifacts`);if(!Lx(e.version)||typeof e.builtAt!=`string`||!Number.isFinite(Date.parse(e.builtAt))||!Array.isArray(e.chunks))throw Error(`seed manifest failed shape validation`);for(let t of[`versionLabel`,`commit`,`name`,`description`])if(e[t]!==void 0&&typeof e[t]!=`string`)throw Error(`invalid seed manifest metadata`);if(e.repositoryUrl!==void 0&&(typeof e.repositoryUrl!=`string`||!/^https:\/\//.test(e.repositoryUrl)||new URL(e.repositoryUrl).username||new URL(e.repositoryUrl).password))throw Error(`invalid seed repository URL`);if(e.dirty!==void 0&&typeof e.dirty!=`boolean`)throw Error(`invalid seed manifest metadata`);let t=new Set,n=new Set;for(let r of e.chunks){if(!Fx(r)||typeof r.id!=`string`||!r.id||typeof r.path!=`string`||!/^chunks\/[a-zA-Z0-9._-]+\.json$/.test(r.path)||typeof r.sha256!=`string`||!/^[0-9a-f]{64}$/.test(r.sha256)||!Lx(r.bytes)||!Lx(r.count)||r.kind!==void 0&&r.kind!==`notes`||t.has(r.id)||n.has(r.path))throw Error(`seed manifest failed shape validation`);t.add(r.id),n.add(r.path)}if(e.notebooks!==void 0){if(!Array.isArray(e.notebooks))throw Error(`seed manifest failed shape validation`);for(let t of e.notebooks){if(!Fx(t)||typeof t.notebookId!=`string`||!t.notebookId||typeof t.label!=`string`||!Lx(t.count)||typeof t.indexPath!=`string`||!t.indexPath||!Lx(t.version)||typeof t.commit!=`string`||typeof t.builtAt!=`string`||typeof t.sha256!=`string`||!Lx(t.bytes))throw Error(`seed manifest failed shape validation`);if(`records`in t&&Array.isArray(t.records))throw Error(`seed manifest failed shape validation: manifest.notebooks must not contain inline records`)}}return e}function Bx(e){if(!Fx(e))throw Error(`notebook index failed shape validation`);if(typeof e.notebookId!=`string`||!e.notebookId||typeof e.label!=`string`||!e.label||typeof e.indexPath!=`string`||!e.indexPath||!Lx(e.version)||typeof e.commit!=`string`||typeof e.builtAt!=`string`||typeof e.sha256!=`string`||!Lx(e.bytes)||!Lx(e.count)||!Array.isArray(e.records))throw Error(`notebook index failed shape validation: missing required index summary or records`);for(let t of e.records)if(!Fx(t)||typeof t.uuid!=`string`||typeof t.path!=`string`||typeof t.recordPath!=`string`||typeof t.commit!=`string`||!Lx(t.version)||typeof t.sha256!=`string`)throw Error(`notebook index failed shape validation: invalid record ref`);return e}function Qne(e,t){if(e.telemetry===void 0)return;if(!Fx(e.telemetry)||!Array.isArray(e.telemetry.sessions)||!Array.isArray(e.telemetry.events))throw Error(`invalid seed telemetry`);let n=new Map;for(let r of e.telemetry.sessions){if(!Fx(r)||typeof r.id!=`string`||!r.id||n.has(r.id)||typeof r.noteId!=`string`||!r.noteId||typeof e.uuid==`string`&&r.noteId!==e.uuid||typeof r.blockId!=`string`||!Ix(r.blockVersion)||typeof r.blockContentId!=`string`||!Rx(r.startTime)||!Rx(r.endTime)||!Rx(r.duration)||typeof r.completed!=`boolean`||!Rx(r.createdAt))throw Error(`invalid seed session`);let i=t.find(e=>Fx(e)&&e.blockId===r.blockId);if(!Fx(i)||i.dataType!==`wod`||i.blockVersion!==r.blockVersion||i.blockContentId!==r.blockContentId)throw Error(`orphan or incompatible seed session pin`);n.set(r.id,r)}let r=new Set;for(let t of e.telemetry.events){if(!Fx(t)||typeof t.id!=`string`||!t.id||r.has(t.id)||typeof t.resultId!=`string`||typeof t.noteId!=`string`||!Rx(t.timestamp)||t.grain!==`event`&&t.grain!==`summary`||typeof t.outputType!=`string`||!Array.isArray(t.metrics)||!t.metrics.every(e=>Fx(e)&&typeof e.type==`string`)||t.grain===`summary`&&t.metrics.length!==1)throw Error(`invalid seed event`);let e=n.get(t.resultId);if(!e||t.noteId!==e.noteId||t.blockId!==e.blockId||t.blockVersion!==e.blockVersion||t.blockContentId!==e.blockContentId)throw Error(`orphan or incompatible seed event identity`);r.add(t.id)}}function Vx(e){if(!Array.isArray(e))throw Error(`seed chunk is not an array`);let t=new Set;for(let n of e){if(!Fx(n)||typeof n.path!=`string`||!n.path||n.path.startsWith(`/`)||n.path.split(`/`).includes(`..`)||t.has(n.path)||typeof n.content!=`string`||!Fx(n.blocks)||!Array.isArray(n.blockIndex)||!Array.isArray(n.blockEfforts)||!Array.isArray(n.blockEquipment))throw Error(`seed chunk row failed shape validation`);t.add(n.path);for(let[e,t]of Object.entries(n.blocks))if(!Fx(t)||t.id!==e||!e||t.version!==1||t.sourceRevision!==1||!Lx(t.from)||!Ix(t.to)||t.from>=t.to||t.to>n.content.length||![`wod`,`query`,`widget`,`embed`].includes(String(t.kind))||(t.kind===`wod`?![`time`,`log`].includes(String(t.dialect)):t.dialect!==void 0)||t.sport!==void 0&&typeof t.sport!=`string`)throw Error(`invalid seed block range or revision`);ho(n.content,n.blocks,1,{registeredWidgets:Qb});let e=new Set,r=fo(n.content,{registeredWidgets:Qb});for(let t of n.blockIndex){if(!Fx(t)||typeof t.blockId!=`string`)throw Error(`invalid seed projection`);let i=n.blocks[t.blockId];if(!Fx(i)||e.has(t.blockId)||typeof t.id!=`string`||typeof t.noteId!=`string`||t.id!==`${t.noteId}:${t.blockId}`||t.blockVersion!==1||t.sourceRevision!==1||t.from!==i.from||t.to!==i.to||t.dataType!==i.kind||t.rawContent!==n.content.slice(Number(i.from),Number(i.to))||typeof t.noteTitle!=`string`||typeof t.createdAt!=`number`||!Number.isFinite(t.createdAt)||t.sourcePath!==n.path||t.isStatic!==!0)throw Error(`orphan or incompatible seed projection`);if(`segmentId`in t||`segmentVersion`in t)throw Error(`incompatible seed projection`);for(let e of[`sourceId`,`routeId`,`blockContentId`])if(t[e]!==void 0&&typeof t[e]!=`string`)throw Error(`invalid seed projection metadata`);if(t.position!==void 0&&!Lx(t.position))throw Error(`invalid seed projection position`);if(i.kind===`wod`){let e=r.find(e=>e.from===i.from&&e.to===i.to);if(t.blockContentId!==Ga(e?.scriptBlock?.content??n.content.slice(Number(i.from),Number(i.to))))throw Error(`invalid seed workout fingerprint`)}else if(t.blockContentId!==void 0)throw Error(`non-workout seed fingerprint`);e.add(t.blockId)}if(e.size!==Object.keys(n.blocks).length)throw Error(`missing actionable seed projection`);let i=new Set;for(let t of n.blockEfforts){if(!Fx(t)||typeof t.blockId!=`string`||typeof t.noteId!=`string`||typeof t.effortSlug!=`string`||!t.effortSlug)throw Error(`invalid seed effort identity`);let r=n.blocks[t.blockId];if(t.id!==`${t.noteId}:${t.blockId}:${t.effortSlug}`||i.has(String(t.id))||!Fx(r)||r.kind!==`wod`||!e.has(t.blockId)||t.sourcePath!==n.path||t.isStatic!==!0||typeof t.createdAt!=`number`)throw Error(`orphan or incompatible seed effort link`);let a=n.blockIndex.find(e=>Fx(e)&&e.blockId===t.blockId);if(!Fx(a)||t.noteId!==a.noteId||t.blockContentId!==a.blockContentId||!Number.isFinite(t.createdAt))throw Error(`invalid seed effort metadata`);i.add(String(t.id))}let a=new Set;for(let t of n.blockEquipment){if(!Fx(t)||typeof t.blockId!=`string`||typeof t.noteId!=`string`||typeof t.equipmentSlug!=`string`||!t.equipmentSlug)throw Error(`invalid seed equipment identity`);let r=n.blocks[t.blockId];if(t.id!==`${t.noteId}:${t.blockId}:${t.equipmentSlug}`||a.has(String(t.id))||!Fx(r)||r.kind!==`wod`||!e.has(t.blockId)||t.sourcePath!==n.path||t.isStatic!==!0||typeof t.createdAt!=`number`)throw Error(`orphan or incompatible seed equipment link`);let i=n.blockIndex.find(e=>Fx(e)&&e.blockId===t.blockId);if(!Fx(i)||t.noteId!==i.noteId||t.blockContentId!==i.blockContentId||!Number.isFinite(t.createdAt))throw Error(`invalid seed equipment metadata`);a.add(String(t.id))}Qne(n,n.blockIndex)}return e}function Hx(e){return Vx([e])[0]}function Ux(e,t,n){return`${e}:${t}:${n}`}function Wx(e){let t=[];for(let[n,r]of Object.entries(e.metrics)){if(typeof r!=`string`&&typeof r!=`number`)continue;let e=String(r).trim().match(/^([+-]?\d+(?:\.\d+)?)\s*([A-Za-z%/][\w%/.-]*)$/);e?t.push({kind:`metric`,type:n,value:Number(e[1]),unit:e[2]}):t.push({kind:`metric`,type:n,value:r})}for(let[n,r]of Object.entries(e.summaries))t.push({kind:`metric`,type:`summaries.${n}`,value:r});for(let[n,r]of Object.entries(e.widgets??{}))t.push({kind:`metric`,type:`widgets.${n}`,value:r});for(let n of e.tags)t.push({kind:`tag`,slug:n});for(let n of e.functions)t.push({kind:`function`,name:n});return t}async function Gx(e,t){let n=ao(t.targetNotebookId);if(no(n))throw Error(`Notebook '${n}' is read-only and cannot store overrides.`);if(n===`notebook/journal`||n===`notebook/playground`)throw Error(`Property overrides belong in 'notebook/custom' or a shared user Notebook, not '${n}'.`);let r=t.slug.trim().toLowerCase();if(!r)throw Error(`Property override requires a non-empty canonical slug.`);let i=io(n),a=`override/${i}/${t.kind}/${r}`,o=`${t.kind}-override-${i}-${r}`,s=Date.now(),c=t.rawContent,l=Nb(c);(typeof l.id!=`string`||!l.id.trim())&&(c=wo(c,[`id`],o)),(typeof l.slug!=`string`||l.slug.trim()!==r)&&(c=wo(c,[`slug`],r));let u=t.title?.trim()||r,d;if(t.kind===`effort`){let e=Wl(c);if(e.errors.length>0)throw Error(e.errors.join(`
102
102
  `));u=e.effort.label||u,d={...e.effort,id:typeof l.id==`string`&&l.id.trim()?l.id.trim():o,slug:r,label:u,registrySource:`user`,ownerNoteId:a,sourceId:n,updatedAt:new Date(s).toISOString()}}else if(t.kind===`equipment`){let e=ql(c);if(e.errors.length>0)throw Error(e.errors.join(`
103
103
  `));u=e.equipment.label||u,d={...e.equipment,id:typeof l.id==`string`&&l.id.trim()?l.id.trim():o,slug:r,label:u,registrySource:`user`,ownerNoteId:a,sourceId:n,updatedAt:new Date(s).toISOString()}}else if(t.kind===`tag`){let e=t.category??`tag`,n=Yl(c,e);if(n.errors.length>0)throw Error(n.errors.join(`
104
104
  `));let i=n.tag.category||e;u=n.tag.label||u,d={id:n.tag.id||o,label:r,...i===`tag`?{}:{type:i},contributions:Wx(n.tag),createdAt:s}}else{let e=Wx(Yl(c,`tag`).tag);u=typeof l.label==`string`&&l.label.trim()||u,d={id:o,name:r,label:u,...typeof l.color==`string`&&l.color.trim()?{color:l.color.trim()}:{},...e.length>0?{contributions:e}:{},createdAt:s}}let f={id:Ux(n,t.kind,r),notebookId:n,kind:t.kind,slug:r,label:u,ownerNoteId:a,rawContent:c,payload:d,seedOrigin:`user`,updatedAt:s};return await e.transaction([`notes`,`block_revisions`,`property_overrides`,`tags`,`tag_types`],`readwrite`,async e=>{let r=await e.readonly(`notes`).get(n);if(r&&(r.feedOrigin===`feed`||r.seedOrigin===`seed`))throw Error(`Notebook '${n}' is feed-delivered and read-only.`);let i=await e.readonly(`notes`).get(a),o=(i?.sourceRevision??0)+1,l=mo(c,{sourceRevision:o,registeredWidgets:co}),p=Object.values(l).map(e=>({noteId:a,blockId:e.id,version:e.version,kind:e.kind,rawContent:c.slice(e.from,e.to),savedAt:s,...e.dialect?{dialect:e.dialect}:{},...e.sport?{sport:e.sport}:{}}));await e.readwrite(`notes`).put({id:a,title:u,rawContent:c,sourceRevision:o,blocks:l,createdAt:i?.createdAt??s,notebookId:n,notebookIds:[n],seedOrigin:`user`}),p.length>0&&await e.readwrite(`block_revisions`).putMany(p),await e.readwrite(`property_overrides`).put(f),n===`notebook/custom`&&(t.kind===`tag`?await e.readwrite(`tags`).put(d):t.kind===`tag-type`&&await e.readwrite(`tag_types`).put(d))}),f}async function Kx(e,t){let n;try{n=t?.notebookId?await e.readonly(`property_overrides`).getAllFromIndex(`by-notebook`,t.notebookId):t?.kind&&t?.slug?await e.readonly(`property_overrides`).getAllFromIndex(`by-kind-slug`,[t.kind,t.slug]):await e.readonly(`property_overrides`).getAll()}catch{return[]}return n.filter(e=>!(t?.notebookId&&e.notebookId!==t.notebookId||t?.kind&&e.kind!==t.kind||t?.slug&&e.slug!==t.slug))}function $ne(e){let t=[],n=e=>{if(!e||!e.trim())return;if(e.startsWith(`feed:`)){t.includes(e)||t.push(e);return}let n=ao(e);n!==`notebook/defaults`&&n!==`notebook/custom`&&n!==`notebook/journal`&&n!==`notebook/playground`&&(t.includes(n)||t.push(n))};if(e.note){let t=e.note.provenance?.feedSourceId??e.note.feedSourceId;t&&t!==`core`&&t!==`local`&&n(`feed:${t}`),e.note.provenance?.sourceNotebookId&&n(e.note.provenance.sourceNotebookId);for(let t of Xv(e.note))n(t);let r=Zv(e.note);r&&n(r)}return e.notebookId&&n(e.notebookId),t}async function qx(e,t={}){let n=[];try{n=await e.readonly(`property_overrides`).getAll()}catch{}let r=[],i=[],a=[],o=[];try{[r,i,a,o]=await Promise.all([e.readonly(`efforts`).getAll(),e.readonly(`equipment`).getAll(),e.readonly(`tags`).getAll(),e.readonly(`tag_types`).getAll()])}catch{}let s=new Map,c=new Map,l=new Map,u=new Map,d=new Map;for(let e of r)e.registrySource===`bundled`&&(!e.sourceId||e.sourceId===`core`||e.sourceId===`efforts`)&&(s.set(e.slug,e),d.set(`effort:${e.slug}`,`notebook/defaults`));for(let e of i)e.registrySource===`bundled`&&(!e.sourceId||e.sourceId===`core`||e.sourceId===`equipment`)&&(c.set(e.slug,e),d.set(`equipment:${e.slug}`,`notebook/defaults`));for(let e of a)l.set(e.label,e),d.set(`tag:${e.label}`,`notebook/defaults`);for(let e of o)u.set(e.name,e),d.set(`tag-type:${e.name}`,`notebook/defaults`);let f=t.notebookId?ao(t.notebookId):void 0,p=t.mode??`source-first`,m=$ne(t),h;if(h=f===`notebook/defaults`?[`notebook/defaults`]:p===`custom-runtime`||m.length===0?[`notebook/defaults`,...m,`notebook/custom`]:[`notebook/defaults`,`notebook/custom`,...m],h.includes(`notebook/custom`)){for(let e of r)e.registrySource===`user`&&!s.has(e.slug)&&(s.set(e.slug,e),d.set(`effort:${e.slug}`,`notebook/custom`));for(let e of i)e.registrySource===`user`&&!c.has(e.slug)&&(c.set(e.slug,e),d.set(`equipment:${e.slug}`,`notebook/custom`))}let g=new Map;for(let e of n){let t=g.get(e.notebookId)??[];t.push(e),g.set(e.notebookId,t)}for(let e of h){let t=g.get(e)??[];for(let n of t){let t=(e.startsWith(`feed:`),e);if(n.kind===`effort`){let e=n.payload??Wl(n.rawContent).effort;s.set(n.slug,{...e,slug:n.slug}),d.set(`effort:${n.slug}`,t)}else if(n.kind===`equipment`){let e=n.payload??ql(n.rawContent).equipment;c.set(n.slug,{...e,slug:n.slug}),d.set(`equipment:${n.slug}`,t)}else if(n.kind===`tag`){let e=n.payload;e&&(l.set(n.slug,e),d.set(`tag:${n.slug}`,t))}else if(n.kind===`tag-type`){let e=n.payload;e&&(u.set(n.slug,e),d.set(`tag-type:${n.slug}`,t))}}}let _=[...s.values()],v=[...c.values()],y=[...l.values()],b=[...u.values()],x=[...b.filter(e=>e.contributions&&e.contributions.length>0).map(e=>({slug:`category:${e.name}`,contributions:e.contributions??[]})),...y.map(e=>({slug:e.label,contributions:e.contributions??[]}))];return{efforts:_,equipment:v,tags:y,tagTypes:b,referenceIndex:fu({efforts:_,equipment:v}),tagIndex:Ha(x),originByKey:d}}async function ere(e,t){let n=ao(t.notebookId);if(ro(n))return[];let r,i;try{[r,i]=await Promise.all([e.readonly(`property_overrides`).getAllFromIndex(`by-notebook`,`notebook/custom`),e.readonly(`property_overrides`).getAllFromIndex(`by-notebook`,n)])}catch{return[]}let a=new Map(i.map(e=>[`${e.kind}:${e.slug}`,e])),o=new Map(r.map(e=>[`${e.kind}:${e.slug}`,e])),s=new Set;for(let e of t.effortSlugs??[])s.add(`effort:${e}`);for(let e of t.equipmentSlugs??[])s.add(`equipment:${e}`);for(let e of t.tagSlugs??[])s.add(`tag:${e}`);let c=[],l=Date.now();for(let e of s){if(a.has(e))continue;let t=o.get(e);if(!t)continue;let r={...t,id:Ux(n,t.kind,t.slug),notebookId:n,updatedAt:l};c.push(r),a.set(e,r)}return c.length>0&&await e.transaction([`property_overrides`],`readwrite`,async e=>{await e.readwrite(`property_overrides`).putMany(c)}),[...a.values()]}async function Jx(e){let t=await crypto.subtle.digest(`SHA-1`,new TextEncoder().encode(`${Ene}:${e}`)),n=new Uint8Array(t.slice(0,16));n[6]=n[6]&15|80,n[8]=n[8]&63|128;let r=Array.from(n,e=>e.toString(16).padStart(2,`0`)).join(``);return`${r.slice(0,8)}-${r.slice(8,12)}-${r.slice(12,16)}-${r.slice(16,20)}-${r.slice(20)}`}function Yx(e,t){if(Object.is(e,t))return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`)return!1;let n=Object.keys(e).filter(t=>Reflect.get(e,t)!==void 0),r=Object.keys(t).filter(e=>Reflect.get(t,e)!==void 0);return n.length===r.length&&n.every(n=>n in t&&Yx(Reflect.get(e,n),Reflect.get(t,n)))}function Xx(e){return(e.split(`/`).at(-1)??e).replace(/\.md$/,``).replace(/[-_]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function tre(e,t,n){let r=e.rawContent,i=0,a=r.length,o=t.length;for(;i<a&&i<o&&r[i]===t[i];)i++;for(;a>i&&o>i&&r[a-1]===t[o-1];)a--,o--;let s=Object.values(e.blocks).filter(e=>i<e.to&&a>e.from),c=go(s.length<=1?e.blocks:Object.fromEntries(Object.entries(e.blocks).filter(([,e])=>!s.includes(e))),[{from:i,to:a,insert:t.slice(i,o)}]),l=0;return mo(t,{sourceRevision:n,blocks:c,registeredWidgets:Qb,createId:()=>`seed:${e.id}:r${n}:${l++}`})}async function Zx(e,t,n,r,i,a,o,s,c,l,u,d,f){let p=new Set(s),m=e=>{let t=-1;for(let n of o)n.noteIds.has(e)&&n.rank>t&&(t=n.rank);return t},h=[],g=i;for(let[e,t]of c.entries()){if(!u.has(l[e]))continue;let r=n(t.content);r&&h.push({...r,registrySource:`bundled`,ownerNoteId:l[e],sourceId:g,sourcePath:t.path})}let _=await e.getMany(h.map(e=>e.slug)),v=h.filter((e,t)=>{let n=_[t];if(!n)return!0;if(n.registrySource!==`bundled`)return!1;let r;if(n.ownerNoteId===e.ownerNoteId||n.ownerNoteId&&p.has(n.ownerNoteId)&&m(n.ownerNoteId)<a)r=a;else{let e=n.ownerNoteId?m(n.ownerNoteId):-1;r=e>=0?e:$b(n.sourceId)}return a>=r&&!Yx(e,n)});v.length&&await e.putMany(v);let y=new Set(h.map(e=>e.slug)),b=new Map;for(let e of f){let t=d.get(e);if(!t||t.seedOrigin!==`seed`)continue;let r=n(t.rawContent)?.slug;r&&!y.has(r)&&b.set(r,e)}let x=[...b.keys()];if(x.length){let a=await e.getMany(x);for(let[s,c]of a.entries()){let a=x[s];if(!c||c.registrySource!==`bundled`)continue;let l=b.get(a);if(!(c.ownerNoteId===l&&(!c.sourceId||c.sourceId===i||c.sourceId===r)))continue;let u=!1;for(let i of o){let o=i.meta.chunks?.[r]?.noteIds??[];if(!o.length)continue;let s=await t.getMany(o);for(let t of s){if(!t||t.seedOrigin!==`seed`)continue;let r=n(t.rawContent);if(r&&r.slug===a){await e.put({...r,registrySource:`bundled`,ownerNoteId:t.id,sourceId:i.sourceId,sourcePath:t.sourcePath??``}),u=!0;break}}if(u)break}u||await e.delete(a)}}return v.length}async function Qx(e,t,n){if(!t.length)return;let r=await e.getMany(n),i=t.filter((e,t)=>!Yx(e,r[t]));i.length&&await e.putMany(i)}var nre=[`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`,`page`,`page_notes`,`tags`,`note_tags`,`efforts`,`equipment`,`property_overrides`,`meta`,`sessions`,`events`];async function rre(e){zx(e.manifest),Vx(e.rows);let t=await Promise.all(e.rows.map(e=>Jx(e.path))),n=new Map,r=new Map,i=new Map;for(let[a,o]of e.rows.entries()){let e=Nb(o.content).slug;typeof e==`string`&&e.trim()&&(n.set(e,await Jx(`page:${e}`)),r.set(t[a],await Jx(`pagenote:${e}:${o.path}`)));for(let{label:e}of Fb(o.content))i.has(e)||i.set(e,await Jx(`tag:${e}`))}return{write:e,ids:t,pagesBySlug:n,linkIds:r,tagIds:i}}async function $x(e,t){let n={totalNotes:0,totalEfforts:0,totalEquipment:0,totalBlocks:0,skippedUserOwned:0,deleted:0,addedNotes:0,updatedNotes:0};if(!t.length)return n;let r=await Promise.all(t.map(rre));return e.transaction(nre,`readwrite`,async e=>{let t={...n};for(let n of r){let r=await are(e,n);t.totalNotes+=r.totalNotes,t.totalEfforts+=r.totalEfforts,t.totalEquipment+=r.totalEquipment,t.totalBlocks+=r.totalBlocks,t.skippedUserOwned+=r.skippedUserOwned,t.deleted+=r.deleted,t.addedNotes+=r.addedNotes,t.updatedNotes+=r.updatedNotes}return t})}async function ire(e,t){return $x(e,[t])}async function are(e,t){let{write:n,ids:r,pagesBySlug:i,linkIds:a,tagIds:o}=t,s={totalNotes:0,totalEfforts:0,totalEquipment:0,totalBlocks:0,skippedUserOwned:0,deleted:0,addedNotes:0,updatedNotes:0},c=e.readwrite(`meta`),l=new Set;for(let e of await c.getAll()){let t=Xne(e?.key);t!==void 0&&l.add(t)}if(!Yx(await c.get(n.meta.key),n.expectedMeta))throw Error(`Seed checkpoint changed during import`);if(n.meta.schema!==9||n.manifest.schema!==9)throw Error(`Incompatible seed schema; recreate artifacts`);let u=e.readwrite(`notes`),d=n.chunkId?n.expectedMeta?.chunks[n.chunkId]?.noteIds??[]:[],f=new Set((n.chunkId?n.meta.chunks[n.chunkId]?.noteIds:void 0)??r),p=d.filter(e=>!f.has(e)),m=[...new Set([...r,...p])],h=await u.getMany(m),g=new Map(m.map((e,t)=>[e,h[t]])),_=n.meta.key.startsWith(`seed:`)?n.meta.key.slice(5):n.meta.key,v=kne(n.meta.key),y=$b(n.meta.key,n.meta.tier),b=[];for(let e of await c.getAll()){let t=e;if(!t||typeof t.key!=`string`||!t.key.startsWith(`seed:`)||t.key===n.meta.key)continue;let r=new Set;for(let e of Object.values(t.chunks??{}))for(let t of e.noteIds??[])r.add(t);b.push({key:t.key,sourceId:t.key.slice(5),rank:$b(t.key,t.tier),meta:t,noteIds:r})}b.sort((e,t)=>t.rank-e.rank);let x=e=>{let t=-1;for(let n of b)n.noteIds.has(e)&&n.rank>t&&(t=n.rank);return t},S=m.filter(e=>{if(l.has(e))return!1;let t=g.get(e);if(!t)return f.has(e);if(t.seedOrigin!==`seed`)return!1;let r=x(e);return f.has(e)?y>=r:r<0&&t.seedChunkId===n.chunkId}),C=new Set(S),w=e.readwrite(`block_revisions`),T=r.filter((e,t)=>C.has(e)&&g.get(e)?.rawContent!==n.rows[t].content),E=await w.getAllFromIndexMany(`by-note`,T),D=new Map(T.map((e,t)=>[e,E[t]])),O=e.readwrite(`block_index`),k=e.readwrite(`block_efforts`),A=e.readwrite(`block_equipment`),j=e.readwrite(`note_tags`),M=e.readwrite(`page_notes`),N=await O.getAllFromIndexMany(`by-note`,S),P=await k.getAllFromIndexMany(`by-note`,S),F=await A.getAllFromIndexMany(`by-note`,S),I=await j.getAllFromIndexMany(`by-note`,S),ee=await M.getAllFromIndexMany(`by-note`,S),L=new Map(S.map((e,t)=>[e,t])),te=e.readwrite(`tags`),R=[...o.keys()],ne=await te.getAllFromIndexMany(`by-label`,R),z=new Map(R.map((e,t)=>[e,ne[t][0]])),B=[],V=[],re=[],ie=[],ae=[],oe=[],se=[],ce=[],le=[],H=e.readwrite(`sessions`),ue=e.readwrite(`events`),U=n.rows.flatMap(e=>e.telemetry?.sessions.map(e=>e.id)??[]),de=await H.getMany(U),fe=new Map(U.map((e,t)=>[e,de[t]])),pe=[],me=[];for(let[e,t]of n.rows.entries()){let c=r[e],l=g.get(c);if(!C.has(c)){l&&l.seedOrigin!==`seed`&&s.skippedUserOwned++;continue}l?l.rawContent!==t.content&&s.updatedNotes++:s.addedNotes++,ho(t.content,t.blocks,1,{registeredWidgets:Qb});let u=l?l.sourceRevision+(l.rawContent===t.content?0:1):1,d=0,f=D.get(c)??[],p=l?l.rawContent===t.content?structuredClone(l.blocks):tre(l,t.content,u):f.length?mo(t.content,{sourceRevision:u,registeredWidgets:Qb,createId:()=>`seed:${c}:new${f.length}:${d++}`}):structuredClone(t.blocks);for(let e of Object.values(p)){let r=(D.get(c)??[]).filter(t=>t.blockId===e.id).sort((e,t)=>t.version-e.version)[0],i=t.content.slice(e.from,e.to);if(l?.rawContent===t.content)continue;let a=r&&r.kind===e.kind&&r.rawContent===i&&r.dialect===e.dialect&&r.sport===e.sport;e.version=l?a?r.version:(r?.version??0)+1:1,(!l||!a)&&re.push({noteId:c,blockId:e.id,version:e.version,kind:e.kind,rawContent:i,savedAt:n.meta.importedAt,...e.dialect?{dialect:e.dialect}:{},...e.sport?{sport:e.sport}:{}})}ho(t.content,p,u,{registeredWidgets:Qb});let m=Nb(t.content),h=typeof m.title==`string`&&m.title.trim()?m.title.trim():Xx(t.path),_=n.chunkId?jne(t.path,t.content,n.chunkId):void 0;if(!_)throw Error(`Unknown seed source family ${n.chunkId}`);let y=typeof m.date==`string`?m.date.match(/^(\d{4})-(\d{2})-(\d{2})$/):null,b;if(y){let e=Date.parse(`${m.date}T12:00:00Z`);if(!(Number.isFinite(e)&&new Date(e).getUTCMonth()===Number(y[2])-1&&new Date(e).getUTCDate()===Number(y[3])))throw Error(`invalid frontmatter date '${m.date}' in '${t.path}' — expected a real calendar day (YYYY-MM-DD)`);b=e}let x=t.commit??n.manifest.commit,S={...l,id:c,title:h,rawContent:t.content,sourceRevision:u,blocks:p,createdAt:n.manifest.version,...b===void 0?{}:{date:b},type:n.chunkId===`dashboards`?`dashboard`:`note`,sourceId:_,seedOrigin:`seed`,seedVersion:n.manifest.version,seedChunkId:n.chunkId??void 0,feedOrigin:`feed`,feedSourceId:v,sourcePath:t.path,...x?{seedCommit:x}:{}};b===void 0&&delete S.date,Yx(S,l)||V.push(S);let w=new Map(Object.values(p).map(e=>[`${e.from}:${e.to}`,e])),T=new Map(t.blockIndex.map(e=>[e.blockId,e])),E=new Map;for(let e of t.blockIndex){let n=w.get(`${e.from}:${e.to}`);if(!n||n.kind!==e.dataType)throw Error(`Orphan seed projection`);E.set(e.blockId,n.id);let r={...e,id:`${c}:${n.id}`,noteId:c,blockId:n.id,blockVersion:n.version,sourceRevision:u,noteTitle:h,sourceId:_,sourcePath:t.path,rawContent:t.content.slice(n.from,n.to)},i=N[L.get(c)].find(e=>e.id===r.id);(!i||i.isStatic===!0)&&se.push(r)}let O=new Map,k=new Set;for(let e of t.telemetry?.sessions??[]){if(T.get(e.blockId)?.dataType!==`wod`)throw Error(`Orphan seed session pin`);let t=fe.get(e.id);if(t&&t.noteId!==c)throw Error(`Seed session ${e.id} belongs to another note`);if(t?.origin){k.add(e.id);continue}let n=t?.blockId??E.get(e.blockId);if(!n)throw Error(`Orphan seed session pin`);let r=p[n];if(!t&&!r)throw Error(`Orphan seed session pin`);let i={...e,noteId:c,blockId:n,blockVersion:t?.blockVersion??r.version,blockContentId:t?.blockContentId??T.get(e.blockId)?.blockContentId};pe.push(i),O.set(i.id,i)}for(let e of t.telemetry?.events??[]){if(k.has(e.resultId))continue;let t=O.get(e.resultId);if(!t)throw Error(`Orphan seed event result`);me.push({...e,noteId:c,blockId:t.blockId,blockVersion:t.blockVersion,blockContentId:t.blockContentId})}for(let e of t.blockEfforts){let n=E.get(e.blockId);if(!n||T.get(e.blockId)?.dataType!==`wod`)throw Error(`Orphan seed effort link`);let r={...e,id:`${c}:${n}:${e.effortSlug}`,noteId:c,blockId:n,sourcePath:t.path},i=P[L.get(c)].find(e=>e.id===r.id);(!i||i.isStatic===!0)&&ce.push(i?{...r,createdAt:i.createdAt}:r)}for(let e of t.blockEquipment){let n=E.get(e.blockId);if(!n||T.get(e.blockId)?.dataType!==`wod`)throw Error(`Orphan seed equipment link`);let r={...e,id:`${c}:${n}:${e.equipmentSlug}`,noteId:c,blockId:n,sourcePath:t.path},i=F[L.get(c)].find(e=>e.id===r.id);(!i||i.isStatic===!0)&&le.push(i?{...r,createdAt:i.createdAt}:r)}let A=L.get(c),M=new Set;for(let e of Fb(t.content)){let t=z.get(e.label);t?e.type&&!t.type&&(t={...t,type:e.type},B.push(t),z.set(e.label,t)):(t={id:o.get(e.label),label:e.label,type:e.type,createdAt:n.meta.importedAt},B.push(t),z.set(e.label,t)),!M.has(t.id)&&(M.add(t.id),I[A].find(e=>e.tagId===t.id)||oe.push({id:`${c}:${t.id}`,noteId:c,tagId:t.id}))}for(let e of I[A])M.has(e.tagId)||await j.delete(e.id);let ee=m.slug;if(typeof ee==`string`&&i.has(ee)){let e=i.get(ee);ie.push({id:e,slug:ee,title:Xx(t.path),createdAt:n.manifest.version}),ae.push({id:a.get(c),pageId:e,noteId:c,createdAt:n.manifest.version})}s.totalNotes++,s.totalBlocks+=Object.keys(p).length}let he=new Set(se.map(e=>e.id)),ge=new Set(ce.map(e=>e.id)),_e=new Set(le.map(e=>e.id));for(let e of N)for(let t of e)t.isStatic===!0&&!he.has(t.id)&&await O.delete(t.id);for(let e of P)for(let t of e)t.isStatic===!0&&!ge.has(t.id)&&await k.delete(t.id);for(let e of F)for(let t of e)t.isStatic===!0&&!_e.has(t.id)&&await A.delete(t.id);for(let e of p){if(!C.has(e)||!g.get(e))continue;let t=L.get(e);await u.delete(e);for(let e of I[t])await j.delete(e.id);for(let e of ee[t])await M.delete(e.id);s.deleted++}let ve=async(t,i)=>{let a;try{a=e.readwrite(`property_overrides`)}catch{return}let o=v===`core`?[`notebook/defaults`]:[`feed:${v}`,...n.manifest.chunks.filter(e=>e.id.startsWith(`notebook.`)).map(e=>`notebook/${ox(e.id)}`)],s=new Set,c=[];for(let[e,a]of n.rows.entries()){let l=i(a.content);if(l)for(let i of o){let o=Ux(i,t,l.slug);s.add(o),c.push({id:o,notebookId:i,kind:t,slug:l.slug,label:l.label,ownerNoteId:r[e],rawContent:a.content,payload:l,seedOrigin:`seed`,feedSourceId:v,updatedAt:n.meta.importedAt})}}c.length>0&&await a.putMany(c);let l=await a.getAll();for(let e of l)e.seedOrigin===`seed`&&e.feedSourceId===v&&e.kind===t&&!s.has(e.id)&&await a.delete(e.id)};return n.chunkId===`efforts`&&(s.totalEfforts=await Zx(e.readwrite(`efforts`),u,Vl,`efforts`,_,y,b,d,n.rows,r,C,g,m),await ve(`effort`,Vl)),n.chunkId===`equipment`&&(s.totalEquipment=await Zx(e.readwrite(`equipment`),u,Hl,`equipment`,_,y,b,d,n.rows,r,C,g,m),await ve(`equipment`,Hl)),V.length&&await u.putMany(V),re.length&&await w.putMany(re),await Qx(O,se,se.map(e=>e.id)),await Qx(k,ce,ce.map(e=>e.id)),await Qx(A,le,le.map(e=>e.id)),await Qx(H,pe,pe.map(e=>e.id)),await Qx(ue,me,me.map(e=>e.id)),B.length&&await te.putMany([...new Map(B.map(e=>[e.id,e])).values()]),oe.length&&await j.putMany(oe),await Qx(e.readwrite(`page`),ie,ie.map(e=>e.id)),await Qx(M,ae,ae.map(e=>e.id)),await c.put(n.meta),s}function ore(e,t){let n=t.seedChunkId?e.filter(e=>e.chunkId===t.seedChunkId):[];return[...n.length>0?n:e].sort((e,t)=>t.rank-e.rank||(e.key<t.key?-1:+(e.key>t.key)))[0]}async function sre(e){return await e.transaction([`meta`,`notes`,`block_index`],`readwrite`,async e=>{let t=e.readwrite(`meta`),n=new Map;for(let e of await t.getAll()){let t=e;if(!t||typeof t.key!=`string`||!t.key.startsWith(`seed:`))continue;let r=t.key.slice(5),i=$b(t.key,t.tier);for(let[e,a]of Object.entries(t.chunks??{}))for(let o of a.noteIds??[]){let a=n.get(o)??[];a.push({sourceId:r,chunkId:e,rank:i,key:t.key}),n.set(o,a)}}if(n.size===0)return 0;let r=e.readwrite(`notes`),i=e.readwrite(`block_index`),a=[...n.keys()],o=await r.getMany(a),s=[];for(let e=0;e<a.length;e++){let t=a[e],i=o[e];if(!i||i.seedOrigin!==`seed`||i.feedSourceId)continue;let c=ore(n.get(t),i),l=i.sourceRevision+1,u=Object.fromEntries(Object.entries(i.blocks).map(([e,t])=>[e,{...t,sourceRevision:l}]));await r.put({...i,blocks:u,sourceRevision:l,feedOrigin:`feed`,feedSourceId:c.sourceId}),s.push({id:t,sourceRevision:l})}if(s.length>0){let e=new Map(s.map(e=>[e.id,e.sourceRevision])),t=(await i.getAllFromIndexMany(`by-note`,s.map(e=>e.id))).flatMap(t=>t.flatMap(t=>{let n=e.get(t.noteId);return n!==void 0&&t.sourceRevision!==n?[{...t,sourceRevision:n}]:[]}));t.length>0&&await i.putMany(t)}return s.length})}async function cre(e){return await e.transaction([`meta`,`notes`,`block_index`,`block_efforts`,`block_equipment`],`readwrite`,async e=>{let t=0,n=e.readwrite(`meta`);for(let e of await n.getAll()){let r=e;if(!r||typeof r.key!=`string`||!r.key.startsWith(`seed:`))continue;let i=r.chunks??{},a=!1,o={};for(let[e,t]of Object.entries(i)){let n=By(e);n!==e&&(a=!0),o[n]=o[n]&&o[n]!==t?{...o[n],noteIds:[...new Set([...o[n].noteIds??[],...t.noteIds??[]])]}:t}a&&(await n.put({...r,chunks:o}),t++)}for(let n of[`notes`,`block_index`,`block_efforts`,`block_equipment`]){let r=e.readwrite(n);for(let e of await r.getAll()){let n=e;Gy(n)&&(await r.put(Wy(n)),t++)}}return t})}var eS=`https://wod.wiki`,lre=`wod-feed-qr`;function ure(e=eS){return dre.replace(`__APP_ORIGIN__`,e)}var dre=`(function () {
@@ -750,7 +750,7 @@ ${t??`A WOD Wiki workout feed compiled from authored Markdown notes and optional
750
750
  `));e?o?r[o]?console.warn(`[canvas] duplicate named \`\`\`scroll:${o} block ignored`):r[o]=e:n===null?n=e:console.warn("[canvas] duplicate unnamed ```scroll block ignored"):console.warn("[canvas] ```scroll block ignored: missing or malformed stages"),s=[],o=null};for(let e of t){if(a){/^```\s*$/.test(e)?(c(),a=!1):s.push(e);continue}let t=e.match(/^```scroll(?::([\w-]+))?\s*$/);if(t){a=!0,o=t[1]??null;continue}i.push(e)}return a&&c(),{scroll:n,namedScrolls:r,body:i.join(`
751
751
  `)}}function qU(e){if(!e)return[];let t=[{token:`{{hero-carousel}}`,widget:`hero-carousel`}],n=[{kind:`prose`,text:e}];for(let{token:e,widget:r}of t){let t=[];for(let i of n){if(i.kind!==`prose`){t.push(i);continue}let n=i.text.split(e);for(let e=0;e<n.length;e++)e>0&&t.push({kind:`widget`,widget:r}),t.push({kind:`prose`,text:n[e]})}n=t}let r=/\{\{challenge:([^}]+)\}\}/g,i=[];for(let e of n){if(e.kind!==`prose`){i.push(e);continue}let t=e.text,n=0,a;for(r.lastIndex=0;(a=r.exec(t))!==null;)i.push({kind:`prose`,text:t.slice(n,a.index)}),i.push({kind:`challenge`,id:a[1].trim()}),n=a.index+a[0].length;i.push({kind:`prose`,text:t.slice(n)})}return n=i,n.filter(e=>e.kind!==`prose`||e.text!==``)}function JU(e){let t=/^```(\w+)\n([\s\S]*?)^```[ \t]*$/gm,n=[],r;for(;(r=t.exec(e))!==null;)n.push({start:r.index,end:r.index+r[0].length,type:r[1],content:r[2]});let i,a=[],o=[],s=[],c=[];for(let e=0;e<n.length;e++){let{type:t,content:r}=n[e];if(t===`view`)i=NU(r),c.push(null);else if(t===`command`)a.push(PU(r)),c.push(null);else if(t===`button`){let e=FU(r);o.push(e),c.push(e)}else t===`example`&&s.push(IU(r)),c.push(null)}let l=new Set([`view`,`command`,`example`]),u=[],d=0;for(let t=0;t<n.length;t++){let r=n[t],i=c[t];i?(u.push(...qU(e.slice(d,r.start))),u.push({kind:`button`,button:i}),d=r.end):l.has(r.type)&&(u.push(...qU(e.slice(d,r.start))),d=r.end)}return u.push(...qU(e.slice(d))),{proseChunks:u,view:i,commands:a,buttons:o,examples:s}}function YU(e,t=`/`){let{meta:n,body:r}=Oo(e);if(String(n.template??``)!==`canvas`)return null;let{quests:i,body:a}=RU(r),{scroll:o,namedScrolls:s,body:c}=KU(a),{chapters:l}=VU(c),u=String(n.route??t),d=[],f=null,p=e=>{let{proseChunks:t,view:n,commands:r,buttons:i,examples:a}=JU(e.lines.join(`
752
752
  `)),o=e.attrs.find(e=>e.startsWith(`#`))?.slice(1),s=e.attrs.filter(e=>!e.startsWith(`#`)),c=e=>s.includes(e),l=e=>s.find(t=>t.startsWith(`${e}:`))?.slice(e.length+1);d.push({id:o||kU(e.heading)||`section-${d.length}`,heading:e.heading,level:e.level,attrs:s,theme:l(`theme`)??`slate`,density:l(`density`)??`default`,isDark:c(`dark`),isFullBleed:c(`full-bleed`),isSticky:c(`sticky`),prose:DU({proseChunks:t}),proseChunks:t,view:n,commands:r,buttons:i,examples:a})},m=!1;for(let e of c.split(`
753
- `)){/^`{3,}/.test(e)&&(m=!m);let t=m?null:AU(e);t?(f&&p(f),f={heading:t.text,level:t.level,attrs:t.attrs,lines:[]}):f&&f.lines.push(e)}return f&&p(f),{template:`canvas`,route:u,type:n.type?String(n.type):void 0,sections:d,frontmatter:n,quests:i,chapters:l,scroll:o,namedScrolls:s}}function XU(e){if(!e)return`/`;let t=e.trim();return t.startsWith(`/`)||(t=`/`+t),t=t.replace(/\/+/g,`/`),t.length>1&&t.endsWith(`/`)&&(t=t.slice(0,-1)),t}function ZU(e,t){let n=XU(t);for(let t of e)if(t.route===n)return t.page;return null}function QU(e){return[XU(e)]}function $U(e,t){for(let n of QU(t)){let t=ZU(e,n);if(t!==null)return t}return null}function eW(e){let t=[];for(let[n,r]of Object.entries(e))if(n.match(/^markdown\/canvas\/(.+\.md)$/)){let e=YU(r);e&&e.route!==Q.home&&t.push({route:e.route,page:e});continue}return t}function tW(e,t){return $U(e,t)}function nW(){let e=nN();return(0,W.useMemo)(()=>e?eW(e):[],[e])}function rW(e){let t=nW();return(0,W.useMemo)(()=>tW(t,e),[t,e])}function iW({className:e,...t}){return(0,G.jsx)(`nav`,{...t,className:Oe(e,`flex flex-1 items-center gap-2 sm:gap-4 py-2.5 min-w-0`)})}var aW=(0,W.forwardRef)(function({current:e,className:t,children:n,...r},i){let a=Oe(`group relative flex min-w-0 min-h-11 min-w-11 items-center justify-center gap-3 rounded-lg p-2 text-left text-base/6 font-medium text-foreground sm:text-sm/5 sm:justify-start`,`[&>[data-slot=icon]]:size-6 [&>[data-slot=icon]]:shrink-0 [&>[data-slot=icon]]:fill-muted-foreground sm:[&>[data-slot=icon]]:size-5`,`[&>*:not(:nth-child(2)):last-child[data-slot=icon]]:ml-auto [&>*:not(:nth-child(2)):last-child[data-slot=icon]]:size-5 sm:[&>*:not(:nth-child(2)):last-child[data-slot=icon]]:size-4`,`[&>[data-slot=avatar]]:-m-0.5 [&>[data-slot=avatar]]:size-7 [&>[data-slot=avatar]]:[--avatar-radius:theme(borderRadius.md)] sm:[&>[data-slot=avatar]]:size-6`,`data-[hover]:bg-muted/50 data-[hover]:[&>[data-slot=icon]]:fill-foreground`,`data-[active]:bg-muted/50 data-[active]:[&>[data-slot=icon]]:fill-foreground`,`dark:data-[hover]:bg-white/5 dark:data-[hover]:[&>[data-slot=icon]]:fill-foreground`,`dark:data-[active]:bg-white/5 dark:data-[active]:[&>[data-slot=icon]]:fill-foreground`);return(0,G.jsxs)(`span`,{className:Oe(t,`relative`),children:[e&&(0,G.jsx)(_e.span,{layoutId:`current-indicator`,className:`absolute inset-x-2 -bottom-2.5 h-0.5 rounded-full bg-foreground`}),typeof r.href==`string`?(0,G.jsx)(eB,{...r,className:a,"data-current":e?`true`:void 0,"aria-current":e?`page`:void 0,ref:i,children:(0,G.jsx)($z,{children:n})}):(0,G.jsx)(Ce,{...r,className:Oe(`cursor-default`,a),"data-current":e?`true`:void 0,"aria-current":e?`page`:void 0,ref:i,children:(0,G.jsx)($z,{children:n})})]})}),$={WORKBENCH_ROOT:`workbench-root`,WORKBENCH_HEADER:`workbench-header`,WORKBENCH_RESET_BUTTON:`workbench-reset`,WORKBENCH_DOWNLOAD_BUTTON:`workbench-download`,TAB_PLAN:`tab-plan`,TAB_TRACK:`tab-track`,TAB_REVIEW:`tab-review`,TRACKER_PANEL:`tracker-panel`,TRACKER_NEXT_BUTTON:`tracker-next`,TRACKER_CURRENT_BLOCK_LABEL:`tracker-current-block`,TRACKER_ROUND_INDICATOR:`tracker-round`,TRACKER_REP_INDICATOR:`tracker-reps`,TRACKER_COMPLETION_BANNER:`tracker-completion`,TIMER_DISPLAY:`timer-display`,TIMER_VALUE:`timer-value`,TIMER_NEXT_BLOCK:`timer-next-block`,TIMER_STOP_SESSION:`timer-stop-session`,TIMER_PLAY_PAUSE:`timer-play-pause`,TIMER_UP_NEXT_CAPTION:`timer-up-next-caption`,TIMER_SURFACE_MINIMAL:`timer-surface-minimal`,TIMER_SURFACE_GENERAL:`timer-surface-general`,TIMER_METRIC_PROMPTS:`timer-metric-prompts`,TIMER_STACK_DRAWER_TOGGLE:`timer-stack-drawer-toggle`,TIMER_STACK_DRAWER:`timer-stack-drawer`,FOCUSED_DIALOG_CLOSE:`focused-dialog-close`,CLOCK_COMMAND_BOARD:`clock-command-board`,CLOCK_REP_COUNTER:`clock-rep-counter`,CLOCK_REP_VALUE:`clock-rep-value`,CLOCK_REP_MINUS:`clock-rep-minus`,CLOCK_REP_PLUS:`clock-rep-plus`,CLOCK_REP_SELECT:`clock-rep-select`,CLOCK_VALUES_BUTTON:`clock-values-button`,CLOCK_DRAFT_CHIP:`clock-draft-chip`,CLOCK_LEGEND:`clock-legend`,CLOCK_KEY_MODE_TOGGLE:`clock-key-mode-toggle`,CLOCK_KEY_CHECK_BUTTON:`clock-key-check-button`,CLOCK_KEY_CHECK_DIALOG:`clock-key-check-dialog`,CLOCK_STOP_CONFIRM:`clock-stop-confirm`,CLOCK_STOP_CONFIRM_ACCEPT:`clock-stop-confirm-accept`,CLOCK_STOP_CONFIRM_CANCEL:`clock-stop-confirm-cancel`,CLOCK_ENTRY_OVERLAY:`clock-entry-overlay`,CLOCK_ERROR:`clock-error`,REVIEW_PANEL:`review-panel`,REVIEW_RESULTS_TABLE:`review-results-table`,REVIEW_METRIC_ROW:`review-metric-row`,REVIEW_TOTAL_TIME:`review-total-time`,EDITOR_PANEL:`editor-panel`,EDITOR_CONTENT:`editor-content`,EDITOR_START_WORKOUT:`editor-start-workout`,TESTBENCH_ROOT:`testbench-root`,TESTBENCH_NEXT_BUTTON:`testbench-next`,TESTBENCH_RUNTIME_STACK:`testbench-runtime-stack`,TESTBENCH_MEMORY:`testbench-memory`,TESTBENCH_SCRIPT_EDITOR:`testbench-script-editor`,EFFORTS_ROOT:`efforts-root`,EFFORTS_SEARCH:`efforts-search`,EFFORTS_CREATE_BTN:`efforts-create-btn`,EFFORTS_EMPTY_STATE:`efforts-empty-state`,EFFORTS_LOADING:`efforts-loading`,EFFORT_DETAIL_ROOT:`effort-detail-root`,EFFORT_DETAIL_LABEL:`effort-detail-label`,EFFORT_DETAIL_ALIASES:`effort-detail-aliases`,EFFORT_DETAIL_ATTRIBUTES:`effort-detail-attributes`,EFFORT_DETAIL_SOURCE:`effort-detail-source`,EFFORT_DETAIL_EDIT_BTN:`effort-detail-edit-btn`,EFFORT_DETAIL_CLONE_BTN:`effort-detail-clone-btn`,EFFORT_DETAIL_SAVE_BTN:`effort-detail-save-btn`,EFFORT_DETAIL_CANCEL_BTN:`effort-detail-cancel-btn`,EFFORT_DETAIL_DELETE_BTN:`effort-detail-delete-btn`,EFFORT_DETAIL_NOTEBOOK_EDITOR:`effort-detail-notebook-editor`,EFFORT_DETAIL_ANALYTICS_PLACEHOLDER:`effort-detail-analytics-placeholder`,EFFORT_NOT_FOUND:`effort-not-found`,EFFORT_NOT_FOUND_CREATE_BTN:`effort-not-found-create-btn`,EFFORT_NOT_FOUND_ALIAS_BTN:`effort-not-found-alias-btn`,EFFORT_NOT_FOUND_ALIAS_SELECT:`effort-not-found-alias-select`,EFFORT_NOT_FOUND_ALIAS_CONFIRM:`effort-not-found-alias-confirm`,EFFORTS_NAV_ORIGIN_FILTER:`efforts-nav-origin-filter`,EFFORTS_NAV_DISCIPLINE_FILTER:`efforts-nav-discipline-filter`,EFFORTS_NAV_RECENT_WORKOUTS:`efforts-nav-recent-workouts`,EFFORTS_NAV_RECENT_WORKOUT_ITEM:`efforts-nav-recent-workout-item`,EQUIPMENT_DETAIL_ROOT:`equipment-detail-root`,EQUIPMENT_DETAIL_LABEL:`equipment-detail-label`,EQUIPMENT_DETAIL_SOURCE:`equipment-detail-source`,EQUIPMENT_DETAIL_CLONE_BTN:`equipment-detail-clone-btn`,EQUIPMENT_DETAIL_NOTEBOOK_EDITOR:`equipment-detail-notebook-editor`,EQUIPMENT_NOT_FOUND:`equipment-not-found`,EQUIPMENT_NOT_FOUND_CREATE_BTN:`equipment-not-found-create-btn`,EQUIPMENT_CREATE_BTN:`equipment-create-btn`,EQUIPMENT_LOAD_ERROR:`equipment-load-error`,COMMAND_PALETTE_TRIGGER:`command-palette-trigger`,COMMAND_PALETTE_INPUT:`command-palette-input`,COMMAND_PALETTE_RESULTS:`command-palette-results`,NAV_L1_HOME:`nav-l1-home`,NAV_L1_JOURNAL:`nav-l1-journal`,NAV_L1_LIBRARY:`nav-l1-library`,NAV_L1_DASHBOARDS:`nav-l1-dashboards`,NAV_L1_SEARCH:`nav-l1-search`,MOBILE_NAV_OPEN:`mobile-nav-open`,MOBILE_NAV_DRAWER:`mobile-nav-drawer`,MOBILE_NAV_CLOSE:`mobile-nav-close`,DRAWER_APPLY_BTN:`drawer-apply-btn`,NEW_ENTRY_PRIMARY:`new-entry-primary`,STREAM_VIEW:`queriable-stream-view`,STREAM_FEED_ITEM:`stream-feed-item`,STREAM_QUERY_BAR:`stream-query-bar`,SAVE_STREAM_QUERY:`save-stream-query`,REMOTE_NOTEBOOK_PREVIEW_BANNER:`remote-notebook-preview-banner`,WIDGET_COMPOSER_SUBSET:`widget-composer-subset`,WIDGET_COMPOSER_WQL:`widget-composer-wql`,WIDGET_COMPOSER_APPLY:`widget-composer-apply`,PROPERTY_TABLE:`property-table`,LIBRARY_ROW_NOTEBOOK:`library-row-notebook`,NOTEBOOKS_CREATE_BUTTON:`notebooks-create-button`,ENTRY_CREATE_TITLE_INPUT:`entry-create-title-input`,ENTRY_CREATE_DATE_INPUT:`entry-create-date-input`,ENTRY_CREATE_SUBMIT_BTN:`entry-create-submit-btn`,ENTRY_CREATE_CANCEL_BTN:`entry-create-cancel-btn`,NOTEBOOK_DIALOG_NAME_INPUT:`notebook-dialog-name-input`,NOTEBOOK_DIALOG_SAVE_BTN:`notebook-dialog-save-btn`,PLACEMENT_DIALOG:`placement-dialog`,PLACEMENT_DATE_INPUT:`placement-date-input`,PLACEMENT_SLUG_INPUT:`placement-slug-input`,PLACEMENT_ADD_BTN:`placement-add-btn`,PLACEMENT_MOVE_BTN:`placement-move-btn`,PLACEMENT_REMOVE_BTN:`placement-remove-btn`,PLACEMENT_CLONE_SUBMIT_BTN:`placement-clone-submit-btn`,PUBLICATION_PILL:`publication-pill`,PUBLICATION_PILL_POPOVER:`publication-pill-popover`,PROMOTION_PROVENANCE_ROW:`promotion-provenance-row`,PROMOTION_CLONE_READONLY_BTN:`promotion-clone-readonly-btn`,PROMOTION_NEW_NOTEBOOK_INPUT:`promotion-new-notebook-input`,PROMOTION_NEW_NOTEBOOK_SUBMIT:`promotion-new-notebook-submit`,PUBLICATION_NOTEBOOK_PUBLIC_TOGGLE:`publication-notebook-public-toggle`,PUBLICATION_EXPORT_REPO_ZIP_BTN:`publication-export-repo-zip-btn`,PROPERTY_OVERRIDE_SHEET:`property-override-sheet`,PROPERTY_OVERRIDE_EDITOR:`property-override-editor`,PROPERTY_OVERRIDE_SAVE_BTN:`property-override-save-btn`,PROPERTY_OVERRIDE_CANCEL_BTN:`property-override-cancel-btn`,TIMER_FULLSCREEN_OVERLAY:`timer-fullscreen-overlay`,TIMER_DETAIL_SURFACE:`timer-detail-surface`,SYNC_SUBSCRIBED_ONLY_TOGGLE:`sync-subscribed-only-toggle`,UNKNOWN_FEED_INTAKE_BANNER:`unknown-feed-intake-banner`,FEED_INTAKE_SUBSCRIBE:`feed-intake-subscribe`,FEED_INTAKE_ONCE:`feed-intake-once`,FEED_SUBSCRIPTION_INTAKE:`feed-subscription-intake`,REGISTERED_FEED_INTAKE_CARD:`registered-feed-intake-card`,REGISTERED_FEED_SUBSCRIBE_BTN:`registered-feed-subscribe-btn`,FEED_DETAIL_SUBSCRIBE_BUTTON:`feed-detail-subscribe-button`,HALTED_RUN_NOTICE:`halted-run-notice`,NOTEBOOK_NOT_FOUND:`notebook-not-found`,STREAM_QUERY_SYNTAX_HINT:`stream-query-syntax-hint`,DELETE_DASHBOARD_BUTTON:`delete-dashboard-button`,CONFIRM_DELETE_DASHBOARD:`confirm-delete-dashboard`,CONDITIONS_NAV_RECENT:`conditions-nav-recent`,LOAD_ZIP_INTAKE:`load-zip-intake`,BUNDLE_FILE_INPUT:`bundle-file-input`,BUNDLE_IMPORT_ERROR:`bundle-import-error`,AGENT_CONFIRM_DIALOG:`agent-confirm-dialog`,AGENT_CONFIRM_APPROVE:`agent-confirm-approve`,AGENT_CONFIRM_CANCEL:`agent-confirm-cancel`,WEBMCP_DEBUG_INSPECTOR:`webmcp-debug-inspector`},oW=_b({getEventsByTimeRange:(e,t)=>X.getEventsByTimeRange(e,t),getEventsByMetricDates:e=>X.getEventsByMetricDates(e),getEventsByResult:e=>X.getEventsByResult(e),getEventsForNote:e=>X.getEventsForNote(e),getEventsByContent:e=>X.getEventsByContent(e),scanAll:()=>X.scanAll(),appendEvents:e=>X.appendEvents(e),finalizeSummaries:(e,t)=>X.finalizeSummaries(e,t),deleteEvents:e=>X.deleteEvents(e)}),sW={getAllNotes:()=>X.getAllNotes(),getNotesByIds:async e=>[...(await X.getDetailBatches(e)).values()].map(e=>e.note),getNoteIdsForTag:async e=>new Set((await X.getNotesForTag(e)).map(e=>e.id)),getNoteTagLabels:async e=>(await X.getTagsForNote(e)).map(e=>e.label),queryDomain:async e=>{if(!X.queryDomain)return;let t=await X.queryDomain({...e,plan:`notes`});return t&&t.plan===`notes`?t:void 0}},cW={getAllBlocks:()=>X.getAllBlockIndex(),queryDomain:async e=>{if(!X.queryDomain)return;let t=await X.queryDomain({...e,plan:`blocks`});return t&&t.plan===`blocks`?t:void 0}},lW=class{async getAllEfforts(){let e=OM();return e.isInitialized()||await CM(e),[...e.list()]}},uW=new Ev,dW={events:[],notes:[]},fW={events:[],notes:[]};uW.set(`@session`,dW),uW.set(`@today`,fW);function pW(){let{runtime:e,activeNoteId:t}=vF.getState(),n=e?.getOutputStatements()??[];if(dW.notes=[],n.length===0)return dW.events=[],dW;let r=t??``;return dW.events=Rv(n.map(Tm),{noteId:r,resultId:`live:${r||`session`}`,origin:`playground`}),dW}function mW(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 ev(e.date??e.createdAt,r)}async function hW(e,t){let n=ev(e.instant,e.timeZone),r=av(n,e.timeZone),i=av(tv(n,1),e.timeZone),[a,o,s,c]=await Promise.all([X.getEventsByTimeRange(r,i),X.getAllNotes(),X.getAllPageNotes(),X.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)mW(t,d.get(t.id)??[],u,e.timeZone)===n&&f.push(t);t===vW&&(fW.events=l,fW.notes=f,pW())}var gW=null,_W=null,vW=0,yW=!1,bW=new Set;function xW(){for(let e of bW)e()}function SW(e,t){_W=t;let n=++vW;return gW=hW(e,n),gW.then(()=>{n===vW&&CW()},()=>{n===vW&&CW()}),gW}function CW(){yW=!0,xW()}function wW(){let e=J_(),t=ev(e.instant,e.timeZone);return!gW||_W!==t?SW(e,t):gW}function TW(){yW=!1;let e=J_();return SW(e,ev(e.instant,e.timeZone))}function EW(){return yW}function DW(e){return bW.add(e),()=>{bW.delete(e)}}async function OW(){await Promise.all([VN(),$N()])}var kW=class extends Fy{async runQuery(e,t){return await Promise.all([OW(),wW()]),super.runQuery(e,t)}async runPipeline(e,t){return await Promise.all([OW(),wW()]),super.runPipeline(e,t)}async runFind(e,t){return await Promise.all([OW(),wW()]),super.runFind(e,t)}async runRows(e,t){return await Promise.all([OW(),wW()]),super.runRows(e,t)}async run(e,t){return await Promise.all([OW(),wW()]),super.run(e,t)}};function AW(){return new kW({eventStore:oW,noteStore:sW,blockStore:cW,effortStore:new lW,blockEffortsStore:{getAllFromIndex:(e,t)=>X.getAllFromIndex(`block_efforts`,e,t)},blockEquipmentStore:{getAllFromIndex:(e,t)=>X.getAllFromIndex(`block_equipment`,e,t)},tagsStore:{getAllFromIndex:(e,t)=>X.getAllFromIndex(`tags`,e,t),getAll:()=>X.getAllTags()},noteTagsStore:{getAllFromIndex:(e,t)=>X.getAllFromIndex(`note_tags`,e,t)},pageStore:{getNotePages:e=>X.getNotePages(e),getPage:e=>X.getPage(e),getAllPages:()=>X.getAllPages(),getAllLinks:()=>X.getAllPageNotes()},relationStore:{getBatches:e=>X.getDetailBatches(e)},datasetStore:{getDataset:e=>e===`@session`?pW():uW.getDataset(e)},feedCatalogStore:lL,isNotebookSubscribed:(e,t)=>hI(e,t)})}var jW=AW();function MW(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?LV(a):`${t===`segment`?`Segment`:`Event`} ${n+1}`,date:typeof e.date==`string`?e.date:null,subtitle:o.length>0?o.join(` • `):void 0}}function NW(e){let t=e.parsed.family===`aggregate`?e.parsed.metric:`metric`;return e.series.map(e=>{let n=e.points.map(t=>`${t.value}${e.unit?` ${e.unit}`:``}`).join(` • `);return{id:`aggregate:${t}:${e.key}`,kind:`result`,sourceNotebook:`results`,sourceNote:e.label,title:`${t}: ${n}`,subtitle:e.label,date:null}})}function PW(e,t,n){e&&e({selected:Math.max(t?.selected??0,n.length),matched:n.length})}function FW(e){return typeof e==`object`&&!!e&&`runFind`in e}var IW=new class e{customService;noteTitleResolver;noteTagsResolver;noteBlockInfo;constructor(e){FW(e)?this.customService=e:(this.customService=e?.service,this.noteTitleResolver=e?.noteTitleResolver,this.noteBlockInfo=e?.noteBlockInfo??!1,this.noteTagsResolver=e?.noteTagsResolver),this.noteTitleResolver||=async e=>{try{let t=await X.getNote(e);return t?MC(t.title)||NC(t.rawContent??``):void 0}catch{return}}}get service(){return this.customService??jW}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,n){let r=new Set;for(let i of e){if(i.kind===`feed`||i.kind===`notebook`||i.isRemotePreview)continue;let e=!!(n&&Object.prototype.hasOwnProperty.call(n,i.id));i.sourceNotebook===`journal`&&!e&&r.add(i.id),t&&(!e&&(!i.title||!i.tags||i.tags.length===0)||e&&i.tags&&i.tags.length>0&&!i.typedTags)&&r.add(i.id)}if(r.size===0)return;let i=await X.getDetailBatches([...r]);for(let t of e){if(t.sourceNotebook!==`journal`)continue;let e=i.get(t.id),r=n?.[t.id]??Ja(e?.links??[],e?.pages??[]);t.placements=r;let a=Ya(r);t.pageId??=a.pageId,a.pageSlug&&(t.pageSlug=a.pageSlug)}if(t)for(let t of e){let e=i.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,n){let r=typeof e==`string`?Y(e):e;if(!r||r.error)return[];if(Th(r)){if(r.target===`effort`){let e=this.service.runFindEffort?await this.service.runFindEffort(r):await this.service.runFind(r),n=new Map(e.notes.map(e=>[e.id,e])),i=(e.efforts??[]).map(e=>e.ownerNoteId&&n.has(e.ownerNoteId)?AV(n.get(e.ownerNoteId)):BV(e));return PW(t,e.stages,i),i}if(r.target===`block`){let e=await this.service.runFind(r),n=e.blocks.map(IV);return await this.hydrateEntries(n,!0),PW(t,e.stages,n),n}if(r.target===`session`){let e=await this.service.runFind(r);t?.(e.stages);let n;if(this.noteTitleResolver&&e.runs){n=new Map;for(let t of e.runs)if(!n.has(t.noteId)){let e=await this.noteTitleResolver(t.noteId);e&&n.set(t.noteId,e)}}let i=QV(e,{noteTitles:n});return PW(t,e.stages,i),i}if(r.target===`segment`||r.target===`event`){let e=r.target,n=await this.service.runFind(r),i=(n.table?.rows??[]).map((t,n)=>MW(t,e,n));return PW(t,n.stages,i),i}let e=await this.service.runFind(r,n?.notebookPlane?{notebookPlane:n.notebookPlane}:void 0),i=e.notes.map(AV);if(this.noteTagsResolver?(await this.hydrateEntries(i,!1,e.placements),await Promise.all(i.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(i,!0,e.placements),PW(t,e.stages,i),this.noteBlockInfo)for(let t=0;t<i.length;t++){let n=i[t],r=e.notes[t];n.excerpt=FV(r.rawContent);try{ho(r.rawContent,r.blocks,r.sourceRevision)}catch{continue}let a=Object.values(r.blocks).sort((e,t)=>e.from-t.from).find(e=>e.kind===`wod`),o=a&&fo(r.rawContent).find(e=>e.from===a.from&&e.scriptBlock);if(a&&o?.scriptBlock){let e=o.scriptBlock.content,t=Ga(e);n.wodBlock={blockId:a.id,blockVersion:a.version,blockContentId:t,content:e},n.blockContentId=t}}return i}if(r.family===`aggregate`){if(!this.service.runQuery)return[];let e=await this.service.runQuery(r.raw),n=NW(e);return t?.({selected:e.stages?.selected??n.length,matched:n.length}),n}return[]}};async function LW(e,t=IW,n){return t.query(e,n)}function RW(e){return e?e.map(e=>e.kind===`wql`?`${e.id}|${e.query}|${e.limit??``}`:`s:${e.id}`).join(`;`):``}async function zW(e){try{let t=(await LW(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 BW(e){let t=RW(e),n=(0,W.useRef)(e);n.current=e;let[r,i]=(0,W.useState)(()=>e&&!e.some(e=>e.kind===`wql`)?e:[]);return(0,W.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`?zW(e):Promise.resolve(e))).then(e=>{t||i(e)}),()=>{t=!0}},[t]),r}function VW(){let[e]=ie(`h`,{shallow:!0}),[t]=ie(`s`,{shallow:!0}),{navState:n}=SR(),r=n.activeL3Id??``;return e||t||r||``}function HW({entry:e,active:t,onActivate:n,onFilter:r}){let i=e.onRun,a=e.filterTo,o=e.filterLabel??`Filter notes by ${e.label}`,s=e.runIcon===`link`?`View workout`:e.runIcon===`stop`?`Stop workout`:e.runIcon===`edit`?`Edit note`:`Start workout`,c=(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:K(`flex min-w-0 flex-1 items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors`,!i&&!a&&`w-full`,e.muted?`text-[11.5px]`:`text-[13px]`,t?`bg-primary/10 font-semibold text-primary`:K(`hover:bg-muted/60 hover:text-foreground`,e.muted?`text-muted-foreground/70`:`text-muted-foreground`)),children:[e.icon&&(0,G.jsx)(e.icon,{className:`size-4 shrink-0`}),e.timestamp&&(0,G.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/60`,children:e.timestamp}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 line-clamp-2 break-words`,title:e.label,children:e.label}),e.badge&&(0,G.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 font-mono text-[9.5px] uppercase tracking-wide text-muted-foreground/80`,children:e.badge})]});return!i&&!a?c:(0,G.jsxs)(`div`,{className:`group flex w-full items-center gap-0.5`,children:[c,a&&(0,G.jsx)(`button`,{type:`button`,"aria-label":o,title:o,"data-testid":`menu-filter-${e.id}`,onClick:()=>r(a),className:`flex size-7 max-lg:size-9 shrink-0 items-center justify-center rounded-md text-muted-foreground/55 transition-colors hover:bg-muted hover:text-foreground`,children:(0,G.jsx)(fr,{className:`size-3.5`})}),i&&(0,G.jsx)(`button`,{type:`button`,"aria-label":s,title:s,onClick:()=>e.onRun?.(),className:`flex size-6 max-lg:size-8 shrink-0 items-center justify-center rounded text-primary opacity-70 lg:opacity-0 transition-all group-hover:opacity-100 hover:bg-primary/10`,children:e.runIcon===`link`?(0,G.jsx)(bn,{className:`size-3.5`}):e.runIcon===`stop`?(0,G.jsx)(Nt,{className:`size-3.5`}):e.runIcon===`edit`?(0,G.jsx)(pr,{className:`size-3.5`}):(0,G.jsx)(Yn,{className:`size-3.5`})})]})}function UW({entries:e,activeId:t,onSection:n}){let r=lt(),{scrollToSection:i}=SR(),a=Yz(),o=e=>{if(a(),n)return n(e);if(e.onSelect)return e.onSelect();if(e.onRun)return e.onRun();if(e.to)return r(e.to);if(e.sectionId)return i(e.sectionId)},s=e=>{a(),r(e)};return(0,G.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>e.kind===`section`?e.entries.length===0?null:(0,G.jsxs)(`div`,{className:`mt-1 flex flex-col gap-0.5 first:mt-0`,children:[(0,G.jsx)(`div`,{className:`px-2 pb-1 pt-3 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:e.label}),(0,G.jsx)(UW,{entries:e.entries,activeId:t,onSection:n})]},e.id):e.kind===`wql`?null:e.kind===`widget`?(0,G.jsx)(`div`,{className:`px-1 py-1`,children:e.render()},e.id):(0,G.jsx)(HW,{entry:e,active:t!=null&&e.sectionId===t,onActivate:o,onFilter:s},e.id))})}function WW(){let e=lt(),{scrollToSection:t}=SR();return{navigate:(t,n)=>e(t,{replace:n?.replace}),setQueryParam:(e,t)=>{},scrollToSection:t}}function GW(){let e=WW(),t=Yz();return n=>{t(),aH(n.action,e)}}function KW(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 qW({items:e}){let{navState:t}=SR(),n=z(),r=GW();return(0,G.jsx)(iB,{children:e.map(e=>{let i=KW(e,t,n);return e.children&&e.children.length>0?(0,G.jsx)(uH,{title:e.label,count:e.children.length,defaultOpen:e.children.some(e=>KW(e,t,n)),collapsible:e.id!==`syntax-group`,children:e.children.map(e=>{let i=KW(e,t,n);return(0,G.jsxs)(oB,{onClick:()=>r(e),current:i,children:[e.icon&&(0,G.jsx)(e.icon,{"data-slot":`icon`}),(0,G.jsx)(sB,{children:e.label})]},e.id)})},e.id):(0,G.jsxs)(`div`,{className:`group relative flex items-center`,children:[(0,G.jsxs)(oB,{onClick:e.disabled?void 0:()=>r(e),current:i,disabled:e.disabled,"aria-label":e.disabled?`${e.label} (coming soon)`:void 0,className:K(`flex-1`,e.disabled&&`opacity-60`),children:[e.icon&&(0,G.jsx)(e.icon,{"data-slot":`icon`}),(0,G.jsx)(sB,{children:e.disabled?`+`:e.label})]}),e.onTogglePin&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e.onTogglePin?.()},title:e.pinned?`Unpin from sidebar`:`Pin to sidebar`,"aria-label":e.pinned?`Unpin ${e.label}`:`Pin ${e.label}`,className:`opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-1 text-muted-foreground hover:text-foreground transition-opacity`,children:(0,G.jsx)(L,{className:`size-3.5`})})]},e.id)})})}function JW({navSpec:e}){let{tree:t,navState:n,dispatch:r,contextNav:i}=SR(),a=z(),o=BW(e),s=(t??[]).find(e=>e?.id===n.activeL1Id)??null,c=i?.pathname===a.pathname?i:null;return(0,G.jsxs)(tB,{children:[(0,G.jsx)(nB,{children:(0,G.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,G.jsxs)(rB,{children:[(()=>{if(c||!s)return null;if(s.panel){let e=s.panel;return(0,G.jsx)(`div`,{className:`border-b border-border/40 pb-2 mb-2`,children:(0,G.jsx)(e,{item:s,navState:n,dispatch:r})})}return s.children&&s.children.length>0?(0,G.jsx)(`div`,{className:`border-b border-border/40 pb-2 mb-2`,children:(0,G.jsx)(qW,{items:s.children})}):null})(),c?(0,G.jsx)(`div`,{className:`pt-1`,children:(0,G.jsx)(UW,{entries:c.spec})}):o.length>0&&(0,G.jsx)(`div`,{className:`pt-1`,children:(0,G.jsx)(UW,{entries:o})})]})]})}var YW=`0.58.2220`,XW=`https://github.com/bitcobblers/wod-wiki/releases`;function ZW(e){return/-pr\.\d+$/.test(e)?XW:`${XW}/tag/v${e}`}function QW({onSearch:e,onCreate:t}){let{tree:n,navState:r,dispatch:i}=SR(),a=lt(),o=z(),s=Yz(),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`);o.pathname===`/`||o.pathname;let d=`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,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:()=>{s(),a(`/`)},title:`Wod Wiki home`,"aria-label":`Wod Wiki home`,"data-testid":$.NAV_L1_HOME,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,G.jsx)(ot,{size:17}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Wod Wiki home`}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:`Wod Wiki home`})]}),(0,G.jsx)(`nav`,{"aria-label":`Primary`,className:`flex flex-col items-center gap-1.5`,children:l.map(e=>{let t=e.icon,n=KW(e,r,o);return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{s(),i({type:`SET_ACTIVE_L1`,id:e.id}),aH(e.action,c)},title:e.label,"aria-label":e.label,"aria-current":n?`page`:void 0,"data-testid":`nav-l1-${e.id}`,className:K(`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,G.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,G.jsx)(t,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:e.label}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:e.label})]},e.id)})}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`button`,{type:`button`,onClick:e,title:`Search (⌘/)`,"aria-label":`Search`,"data-testid":$.NAV_L1_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,G.jsx)(An,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Search`}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:`Search (⌘/)`})]}),(0,G.jsxs)(`a`,{href:gU,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,G.jsx)(_U,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Buy Me a Coffee`}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:`Buy Me a Coffee`})]}),(0,G.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:K(`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,G.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,G.jsx)(tr,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Profile`}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:`Profile`})]}),(0,G.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:K(`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,G.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,G.jsx)(N,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Settings`}),(0,G.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`,YW,`)`]})]})]})}function $W({activations:e,activeSection:t,variant:n,deps:r,className:i}){return(0,G.jsx)(`nav`,{className:K(`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,G.jsx)(`button`,{onClick:()=>aH(e.action,r),className:K(`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 eG=class e{now;name=`tick`;timestamp;data;static _counter=0;constructor(t,n=gu){this.now=n;let r=this.now.nowMs();e._counter++,this.timestamp=new Date(r+e._counter),this.data=t}},tG=20,nG=e=>{let[t,n]=(0,W.useState)(`idle`),[r,i]=(0,W.useState)(0),[a,o]=(0,W.useState)(0),[s,c]=(0,W.useState)(null),l=(0,W.useRef)(null),u=(0,W.useRef)(null),d=(0,W.useCallback)(()=>{if(l.current&&=(clearInterval(l.current),null),u.current!==null){let t=e?.nowProvider?.nowMs()??gu.nowMs();i(t-u.current)}n(`idle`)},[e]),f=(0,W.useCallback)(()=>{if(e)try{let t=new eG(void 0,e.nowProvider);e.handle(t),o(e=>e+1)}catch{d(),n(`error`)}},[e,d]);(0,W.useEffect)(()=>{if(e)return e.subscribeToStack(r=>{if(r.blocks.length===0&&t!==`completed`){if(l.current&&=(clearInterval(l.current),null),u.current!==null){let t=e?.nowProvider?.nowMs()??gu.nowMs();i(t-u.current)}n(`completed`)}})},[e,t]),(0,W.useEffect)(()=>()=>{l.current&&=(clearInterval(l.current),null)},[]);let p=(0,W.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()??gu.nowMs();u.current=i-r,r===0&&c(i),l.current=setInterval(f,tG)},[e,t,r,f]),m=(0,W.useCallback)(()=>{if(l.current&&=(clearInterval(l.current),null),u.current!==null){let t=e?.nowProvider?.nowMs()??gu.nowMs();i(t-u.current)}if(e){let t=e.nowProvider?.now()??gu.now();e.handle({name:`timer:pause`,timestamp:t,data:{}})}n(`paused`)},[e]),h=(0,W.useCallback)(()=>{l.current&&=(clearInterval(l.current),null),i(0),o(0),n(`idle`),c(null),u.current=null},[e]),g=(0,W.useCallback)(()=>{!e||t===`running`||(n(`paused`),f())},[e,t,f]);return(0,W.useEffect)(()=>{if(t!==`running`||!u.current)return;let n=setInterval(()=>{i((e?.nowProvider?.nowMs()??gu.nowMs())-u.current)},100);return()=>clearInterval(n)},[t,e?.nowProvider]),(0,W.useEffect)(()=>()=>{l.current&&=(clearInterval(l.current),null)},[]),(0,W.useEffect)(()=>{h()},[e,h]),(0,W.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])};function rG(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,W.useState)(r);return(0,W.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 iG(e){return rG(e,`round`)}function aG(e){return rG(e,`display`)}function oG(e){let t=iG(e),n=aG(e);return(0,W.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 sG=(0,W.createContext)(void 0),cG=({runtime:e,children:t})=>(0,G.jsx)(sG.Provider,{value:e,children:t});function lG(){let e=(0,W.useContext)(sG);if(!e)throw Error(`useScriptRuntime must be used within ScriptRuntimeProvider`);return e}function uG(){return(0,W.useContext)(sG)??null}function dG(e){let t=lG(),n=e===void 0?t:e,[r,i]=(0,W.useState)(()=>n?.getOutputStatements?.()??[]);return(0,W.useEffect)(()=>{if(!n){i([]);return}return i(n.getOutputStatements()),n.subscribeToOutput?.(()=>{i(n.getOutputStatements())})},[n]),(0,W.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 fG(){let e=lG(),[t,n]=(0,W.useState)({type:`initial`,blocks:e.stack.blocks,depth:e.stack.count,clockTime:e.clock.currentDate});return(0,W.useEffect)(()=>e.subscribeToStack(e=>{n(e)}),[e]),t}function pG(){return fG().blocks}function mG(){let e=pG(),[t,n]=(0,W.useState)(0);return(0,W.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,W.useMemo)(()=>{for(let t of e){let e=t.getMemoryByTag(`metric:next`);if(e.length===0)continue;let n=La.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 hG(){let e=pG(),[t,n]=(0,W.useState)(0);return(0,W.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,W.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 gG(){let e=pG(),[t,n]=(0,W.useState)(0);return(0,W.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,W.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 _G(e){let t=lG(),n=(0,W.useMemo)(()=>t.stack.blocks.find(t=>t.key.toString()===e),[t,e]),[r,i]=(0,W.useState)(()=>n?.getMemoryByTag(`time`)[0]?.metrics[0]?.value);(0,W.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,W.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,W.useMemo)(()=>r?.spans??[],[r]),o=a.length>0&&a[a.length-1].ended===void 0,[s,c]=(0,W.useState)(Qu()),l=(0,W.useMemo)(()=>a.length===0?0:Xp(a,s),[a,s]);return(0,W.useEffect)(()=>{if(!o)return;let e,t=()=>{c(Qu()),e=requestAnimationFrame(t)};return t(),()=>cancelAnimationFrame(e)},[o]),{elapsed:l,isRunning:o,timeSpans:a}}function vG(e={}){let t=uG(),n=e.runtime===void 0?t:e.runtime,r=e.active??!0,[i,a]=(0,W.useState)({revision:0,skipFlash:!1,skipFlashKey:0});(0,W.useEffect)(()=>{if(!(!n||!r))return nm(n,({skipFlash:e,skipFlashKey:t})=>{a(n=>({revision:n.revision+1,skipFlash:e,skipFlashKey:t}))})},[n,r]);let[o,s]=(0,W.useState)(()=>Qu()),c=(0,W.useMemo)(()=>(i.revision,om(n,{nowMs:o,executionStatus:e.executionStatus,canNextOverride:e.canNextOverride,skipFlash:i.skipFlash,skipFlashKey:i.skipFlashKey})),[n,i.revision,i.skipFlash,i.skipFlashKey,o,e.executionStatus,e.canNextOverride]);return(0,W.useEffect)(()=>{if(!r||!c.isRunning||c.isPaused||typeof requestAnimationFrame!=`function`)return;let e=0,t=!0,n=()=>{t&&(s(Qu()),e=requestAnimationFrame(n))};return e=requestAnimationFrame(n),()=>{t=!1,cancelAnimationFrame(e)}},[r,c.isRunning,c.isPaused]),c}function yG(e){let t=uG(),n=e===void 0?t:e,[r,i]=(0,W.useState)(0);return(0,W.useEffect)(()=>{if(!n){i(0);return}return n.subscribeToOutput?.(()=>{i(e=>e+1)})},[n]),(0,W.useMemo)(()=>pm(n),[n,r])}function bG(e){let t=uG(),n=e===void 0?t:e,[r,i]=(0,W.useState)(0);return(0,W.useEffect)(()=>{if(!n)return;let e=n.subscribeToStack(()=>i(e=>e+1)),t=n.subscribeToOutput?.(()=>i(e=>e+1));return()=>{e(),t?.()}},[n]),(0,W.useMemo)(()=>gm(n),[n,r])}var xG=(0,W.createContext)(void 0),SG=(0,W.createContext)(null),CG=({factory:e,children:t})=>{let[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(null),u=(0,W.useRef)(e);u.current=e;let d=(0,W.useRef)(null),f=(0,W.useRef)(null),p=(0,W.useRef)(!1),m=(0,W.useCallback)(()=>{f.current&&=(f.current.dispose(),null),a(null),vF.getState().setSubscriptionManager(null),vF.getState().setRuntime(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,W.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 Yp(i);e.add(new Jp({id:`local`})),f.current=e,a(e),vF.getState().setRuntime(i),vF.getState().setSubscriptionManager(e)}else f.current=null,a(null),vF.getState().setRuntime(null),vF.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,W.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,G.jsx)(xG.Provider,{value:g,children:(0,G.jsx)(SG.Provider,{value:i,children:t})})};function wG({factory:e,children:t}){return(0,G.jsx)(CG,{factory:e,children:t})}var TG=`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`,EG=`flex flex-col flex-1 min-w-0 xl:max-w-[984px] 2xl:max-w-none min-h-screen lg:rounded-[2.5rem]`,DG=(0,W.createContext)(null);function OG({value:e,children:t}){return(0,G.jsx)(DG.Provider,{value:e,children:t})}function kG(){let e=(0,W.useContext)(DG),{dispatch:t,streamControls:n,analyticsControls:r,l3Items:i,l3Actions:a=[],secondarySpec:o}=SR(),s=(0,W.useMemo)(()=>{let e=Y(n?.query??``);return!e.error&&Th(e)&&e.filters.length>0},[n?.query]);return e||{railHasContent:!!(o&&o.length>0||i&&i.length>0||a&&a.length>0||n||r),hasAppliedFilters:s,openRightDrawer:()=>t({type:`SET_RIGHT_DRAWER`,open:!0})}}function AG(){let{railHasContent:e,hasAppliedFilters:t,openRightDrawer:n}=kG();return e?(0,G.jsxs)(q,{type:`button`,variant:`ghost`,size:`icon`,onClick:n,"aria-label":`Page options`,title:`Page options (⌘.)`,"data-testid":`l3-drawer-trigger`,className:`relative hidden lg:inline-flex 2xl:hidden text-muted-foreground hover:text-foreground`,children:[(0,G.jsx)(Nn,{className:`size-4`,"aria-hidden":`true`}),t&&(0,G.jsx)(`span`,{"data-testid":`header-filters-active`,className:`absolute top-1.5 right-1.5 size-2 rounded-full bg-amber-500`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Page options`})]}):null}function jG({id:e,title:t,subtitle:n,titleAccessory:r,actions:i,queryBar:a,subheader:o,titleTestId:s,className:c}){let{railHasContent:l}=kG(),u=!!(i||l);return(0,G.jsxs)(`div`,{id:e,"data-page-sticky-boundary":`true`,className:K(`max-lg:hidden lg:sticky lg:top-0 z-30 border-b border-border/50 bg-background/95 backdrop-blur-md transition-colors`,c),children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-2.5 sm:gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`h-5 w-1.5 shrink-0 rounded-full bg-primary`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h1`,{"data-testid":s,className:`text-base sm:text-lg font-black tracking-tight text-foreground leading-none truncate`,children:t}),n&&(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground truncate`,children:n})]}),r]})]}),a&&(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:a}),u&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0 ml-auto`,children:[i,(0,G.jsx)(AG,{})]})]}),o&&(0,G.jsx)(`div`,{className:`bg-background/40`,children:o})]})}function MG({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,W.useRef)(``),u=(0,W.useRef)(i),d=(0,W.useRef)(a),f=(0,W.useRef)(null),p=(0,W.useRef)(1);(0,W.useEffect)(()=>{u.current=i},[i]),(0,W.useEffect)(()=>{d.current=a},[a]);let m=e.filter(Boolean).join(`\0`),h=r.join(`,`),g=(0,W.useMemo)(()=>m?m.split(`\0`):[],[m]),_=(0,W.useMemo)(()=>h.split(`,`).map(Number),[h]),v=(0,W.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null)},[]);(0,W.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 NG({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]=ie(`s`,{defaultValue:o??a[0]?.id??``,shallow:!0,history:`replace`}),[f,p]=(0,W.useState)(c?.[0]?.id??``);if(MG({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}),MG({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,G.jsxs)(`div`,{className:K(`flex flex-col min-h-screen bg-background`,l),children:[s,(0,G.jsx)($W,{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,G.jsx)(`div`,{className:`flex-1`,children:c.map(e=>{let t=(0,G.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,G.jsx)(wG,{factory:e.runtimeFactory,children:t},e.id):t})})]})}return(0,G.jsx)(`div`,{className:K(`relative flex w-full min-h-screen justify-start items-start`,l),children:(0,G.jsxs)(`div`,{className:K(EG,TG),children:[(0,G.jsx)(jG,{title:e,titleAccessory:t,actions:n,subheader:r}),(0,G.jsx)(`div`,{className:`flex-1`,children:i})]})})}var PG=`[data-page-sticky-boundary="true"]`,FG=0;function IG(e,t=FG){if(typeof document>`u`)return e;let n=Array.from(document.querySelectorAll(PG)).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 LG(e,t=FG){let[n,r]=(0,W.useState)(e);return(0,W.useEffect)(()=>{let n=0,i=()=>r(IG(e,t)),a=()=>{cancelAnimationFrame(n),n=requestAnimationFrame(i)};i(),window.addEventListener(`scroll`,a,{passive:!0}),window.addEventListener(`resize`,i);let o=typeof ResizeObserver>`u`?void 0:new ResizeObserver(i);document.querySelectorAll(PG).forEach(e=>o?.observe(e));let s=typeof MutationObserver>`u`?void 0:new MutationObserver(()=>{document.querySelectorAll(PG).forEach(e=>o?.observe(e)),i()});return typeof document<`u`&&document.body&&s?.observe(document.body,{childList:!0,subtree:!0}),()=>{s?.disconnect(),o?.disconnect(),cancelAnimationFrame(n),window.removeEventListener(`scroll`,a),window.removeEventListener(`resize`,i)}},[e,t]),n}function RG({top:e,label:t,icon:n,badge:r,meta:i,testId:a,className:o}){return(0,G.jsxs)(`div`,{"data-testid":a,className:K(`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,G.jsx)(`span`,{className:`min-w-0 truncate text-xs font-bold text-foreground`,children:t}),r,i&&(0,G.jsx)(`span`,{className:`ml-auto shrink-0 pl-2 font-mono text-[10px] text-muted-foreground`,children:i})]})}var zG=(0,W.createContext)(null),BG=(0,W.createContext)(null);function VG({children:e}){let[t,n]=(0,W.useState)(null);return(0,G.jsx)(BG.Provider,{value:n,children:(0,G.jsx)(zG.Provider,{value:t,children:e})})}function HG({className:e}){let t=(0,W.useContext)(BG);return(0,G.jsx)(`div`,{ref:t,className:e,"data-testid":`mobile-query-slot`})}function UG(){return(0,W.useContext)(zG)}function WG({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,G.jsxs)(`div`,{className:K(`relative flex w-full min-h-screen justify-start items-start`,d),children:[(0,G.jsxs)(`div`,{className:K(EG,TG),children:[(0,G.jsx)(jG,{title:t,subtitle:n,titleTestId:r,actions:i}),(0,G.jsx)(`main`,{className:`flex-1 min-w-0 max-w-full`,children:e})]}),s&&a&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/95 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,G.jsx)(`div`,{className:`flex justify-end p-4`,children:(0,G.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,G.jsx)(`div`,{className:`flex-1 min-h-0`,children:a})]})}),c&&o&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/95 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,G.jsx)(`div`,{className:`flex justify-end p-4`,children:(0,G.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,G.jsx)(`div`,{className:`flex-1 min-h-0`,children:o})]})})]})}function GG(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 KG=W.createContext(null);function qG(){let e=W.useContext(KG);if(!e)throw Error(`DropdownMenu components must be used inside a DropdownMenu`);return e}function JG(){let e=W.useContext(KG);return W.useCallback(()=>{e?.setIsOpen(!1)},[e])}var YG=({children:e,open:t,onOpenChange:n})=>{let r=W.useContext(KG),i=W.useId(),a=r?`${r.portalChain}/${i}`:i,[o,s]=W.useState(t??!1),c=W.useRef(null),[l,u]=W.useState(-1),d=W.useRef(new Map),[,f]=W.useReducer(e=>e+1,0);W.useEffect(()=>{t!==void 0&&s(t)},[t]);let p=W.useCallback(e=>{s(e),u(-1),n?.(e)},[n]),m=W.useCallback((e,t)=>{d.current.set(e,t),f()},[]),h=W.useCallback(e=>{d.current.delete(e),f()},[]),g=W.useCallback(e=>Array.from(d.current.keys()).indexOf(e),[]),_=d.current.size,v=W.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,G.jsx)(KG.Provider,{value:v,children:(0,G.jsx)(`div`,{ref:c,className:`relative inline-block`,children:e})})},XG=W.forwardRef(({className:e,children:t,asChild:n,...r},i)=>{let{isOpen:a,setIsOpen:o}=qG(),s=e=>{e.stopPropagation(),o(!a)};return n&&W.isValidElement(t)?W.cloneElement(t,{...r,onClick:s}):(0,G.jsx)(`button`,{ref:i,className:e,onClick:s,...r,children:t})});XG.displayName=`DropdownMenuTrigger`;var ZG=W.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}=qG(),p=W.useRef(null),m=a||p,[h,g]=W.useState({top:0,bottom:0,left:0,width:0}),_=r===`bottom`,[v,y]=W.useState(!1);W.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]),W.useLayoutEffect(()=>{if(!o||!_||!m.current)return;let e=m.current.getBoundingClientRect();y(h.top+e.height>window.innerHeight)},[o,_,h.top,m]),W.useEffect(()=>{if(!o||u===0)return;let e=setTimeout(()=>{l(0)},0);return()=>clearTimeout(e)},[o,u,l]),W.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%)`),cE.createPortal((0,G.jsx)(`div`,{ref:m,role:`menu`,"data-dropdown-chain":f,className:K(`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)});ZG.displayName=`DropdownMenuContent`;var QG=W.forwardRef(({className:e,disabled:t,inset:n,onClick:r,onKeyDown:i,...a},o)=>{let{setIsOpen:s,registerItem:c,unregisterItem:l,getItemIndex:u,activeIndex:d}=qG(),f=W.useId(),p=W.useRef(null),m=W.useCallback(e=>{p.current=e,typeof o==`function`?o(e):o&&(o.current=e)},[o]);W.useEffect(()=>(c(f,p),()=>l(f)),[f,c,l]);let h=u(f)===d;return W.useEffect(()=>{h&&p.current?.focus()},[h]),(0,G.jsx)(`div`,{ref:m,role:`menuitem`,tabIndex:t?-1:h?0:-1,"aria-disabled":t,"data-active":h?`true`:void 0,className:K(`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})});QG.displayName=`DropdownMenuItem`;var $G=W.forwardRef(({className:e,inset:t,...n},r)=>(0,G.jsx)(`div`,{ref:r,className:K(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));$G.displayName=`DropdownMenuLabel`;var eK=W.forwardRef(({className:e,...t},n)=>(0,G.jsx)(`div`,{ref:n,className:K(`-mx-1 my-1 h-px bg-muted`,e),...t}));eK.displayName=`DropdownMenuSeparator`;var tK=[{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`}],nK=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function rK(e,t){return new Date(e,t+1,0).getDate()}function iK(e,t){let n=new Date(e,t,1).getDay();return n===0?6:n-1}function aK(e,t){let n=Y(e);if(n.error)return e;if(!t||t===`all`)return yg({...n,window:void 0});let r=Y(`:note ${t}`);return r.error||r.family!==`find`||!r.window?e:yg({...n,window:r.window})}function oK(e){let t=Y(e);return t.error||t.family===`pipeline`?null:`window`in t?t.window??null:null}function sK({query:e,onQueryChange:t,highlightDates:n=new Set,className:r}){let i=(0,W.useMemo)(()=>oK(e),[e]),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(()=>new Date),l=s.getFullYear(),u=s.getMonth(),d=(0,W.useMemo)(()=>i?i.kind===`relative`?`last ${i.size}${i.unit}`:i.kind===`param`?`last $${i.param}${i.unit?` ${i.unit}`:``}`:i.end?`from ${i.start} to ${i.end}`:`from ${i.start}`:`All time`,[i]),f=(0,W.useMemo)(()=>{if(!i||i.kind===`param`)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:Iz(t),end:Iz(e)}},[i]),p=(0,W.useMemo)(()=>{let e=rK(l,u),t=iK(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(aK(e,`from ${n} to ${n}`));else{let[r,i]=a<=n?[a,n]:[n,a];o(null),t(aK(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=Iz(new Date);return(0,G.jsxs)(`div`,{className:K(`relative inline-flex items-center`,r),children:[(0,G.jsxs)(YG,{children:[(0,G.jsx)(XG,{asChild:!0,children:(0,G.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,G.jsx)(jt,{className:`size-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`font-mono text-xs`,children:d}),(0,G.jsx)(dt,{className:`size-3 text-muted-foreground`,"aria-hidden":`true`})]})}),(0,G.jsxs)(ZG,{align:`end`,className:`w-72 p-3`,children:[(0,G.jsx)(`div`,{className:`mb-3 flex flex-wrap gap-1 border-b border-border/60 pb-2`,children:tK.map(n=>{let r=n.value===`all`?!i:i?.kind===`relative`&&`last ${i.size}${i.unit}`===n.value;return(0,G.jsx)(`button`,{type:`button`,"data-testid":`wql-window-preset-${n.value}`,onClick:()=>{o(null),t(aK(e,n.value))},className:K(`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,G.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,G.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,G.jsx)(V,{className:`size-4`})}),(0,G.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:_}),(0,G.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,G.jsx)(gt,{className:`size-4`})})]}),(0,G.jsx)(`div`,{className:`mb-1 grid grid-cols-7 gap-1`,children:nK.map(e=>(0,G.jsx)(`div`,{className:`text-center text-[10px] font-medium text-muted-foreground`,children:e},e))}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,"data-testid":`wql-calendar-grid`,children:p.map((e,t)=>{if(e===null)return(0,G.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,G.jsxs)(`button`,{type:`button`,"data-testid":`wql-calendar-day-${r}`,onClick:()=>m(r),className:K(`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,G.jsx)(`span`,{children:e}),d&&!o&&!s&&(0,G.jsx)(`span`,{className:`absolute bottom-0.5 size-1 rounded-full bg-primary`})]},r)})}),a&&(0,G.jsxs)(`div`,{className:`mt-2 text-center text-[10px] text-muted-foreground`,children:[`Select second date to complete range (starting from `,a,`)`]})]})]}),i&&(0,G.jsx)(`button`,{type:`button`,"data-testid":`wql-window-picker-clear`,onClick:()=>{o(null),t(aK(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,G.jsx)(Bn,{className:`size-3.5`})})]})}function cK({onOpen:e}){let t=JG(),n=Yz();return(0,G.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{t(),n(),e()},"data-testid":`query-settings-trigger`,className:`w-full justify-start gap-2 rounded-lg text-xs`,children:[(0,G.jsx)(Nn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`truncate`,children:`Query settings`})]})}function lK(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 uK=[{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??``)}],dK={note:uK,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?``:RV(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`sessionLoad`,label:`Session Load`,level:`session`,defaultVisible:!0,align:`right`,getValue:e=>{if(e.execution?.loadLbs!=null)return`${e.execution.loadLbs.toLocaleString()} ${e.execution.volumeUnit??`lbs`}`;if(e.execution?.sessionLoadAu!=null)return`${Number.isInteger(e.execution.sessionLoadAu)?e.execution.sessionLoadAu.toLocaleString():Number(e.execution.sessionLoadAu.toFixed(1)).toLocaleString()} AU`},formatValue:e=>e==null?``:String(e)}],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?``:RV(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`totalTonnage`,label:`Total Tonnage`,level:`result`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.loadLbs==null?void 0:`${e.execution.loadLbs.toLocaleString()} ${e.execution.volumeUnit??`lbs`}`,formatValue:e=>e==null?``:String(e)},{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?``:RV(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==null?void 0:`${e.execution.loadLbs.toLocaleString()} ${e.execution.volumeUnit??`lbs`}`,formatValue:e=>e==null?``:String(e)},{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 fK(e){return dK[e]??uK}function pK(e){return fK(e).filter(e=>e.defaultVisible).map(e=>e.id)}var mK=[4,8,16],hK=`sum:totalVolume{}`;function gK(e){let t=Number.parseInt(e??``,10);return mK.includes(t)?t:16}function _K(e={}){let{defaultQuery:t=hK,runOnLanding:n=!1}=e,[r,i]=ee(),a=r.get(`q`)??``,o=gK(r.get(`weeks`)),[s,c]=(0,W.useState)(()=>a&&!Y(a).error?a:t),[l,u]=(0,W.useState)(a||(n?t:``)),d=(0,W.useRef)(s);d.current=s;let f=(0,W.useRef)(r);f.current=r;let p=(0,W.useRef)(!0),m=(0,W.useRef)(a);m.current=a;let h=(0,W.useRef)(a);(0,W.useEffect)(()=>{a!==h.current&&(h.current=a,d.current!==a&&(p.current=!0,c(a&&!Y(a).error?a:t),u(a||(n?t:``))))},[a,t,n]);let g=(0,W.useRef)(t);return(0,W.useEffect)(()=>{t!==g.current&&(g.current=t,!a&&(c(t),u(n?t:``)))},[t,a,n]),{draft:s,setDraft:(0,W.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,W.useCallback)(e=>{let t=e??d.current;if(Y(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,W.useCallback)(e=>{let t=new URLSearchParams(f.current);t.set(`weeks`,String(e)),i(t,{replace:!0})},[i])}}var vK=[{id:`cards`,label:`Cards`,icon:Zn},{id:`rows`,label:`Rows`,icon:Lr},{id:`feed`,label:`Feed`,icon:p},{id:`agenda`,label:`Agenda`,icon:It},{id:`planner`,label:`Planner`,icon:nee}];function yK({streamControls:e}){let t=e.availableLayouts;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,"data-testid":`l3-stream-controls`,children:[e.onOpenQuerySettings&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`This page`}),(0,G.jsx)(cK,{onOpen:e.onOpenQuerySettings})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Date window`}),(0,G.jsx)(sK,{query:e.query,onQueryChange:e.onQueryChange,className:`w-full justify-between`})]}),e.availableGroupDims.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Group by`}),(0,G.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,G.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,G.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>e.onToggleGroupDim(t.id),className:`size-3.5 rounded border-border accent-primary cursor-pointer`}),(0,G.jsx)(`span`,{children:t.label})]},t.id)})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Layout`}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-1`,"data-testid":`l3-layout-options`,children:vK.filter(e=>!t||t.includes(e.id)).map(t=>{let n=t.icon,r=e.settings.layout===t.id;return(0,G.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,G.jsx)(n,{"aria-hidden":!0,className:`size-3`}),t.label]},t.id)})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Fields`}),(0,G.jsx)(`div`,{className:`flex flex-col gap-0.5`,"data-testid":`l3-field-options`,children:fK(e.level).map(t=>{let n=e.settings.visibleFields.includes(t.id);return(0,G.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,G.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>e.onToggleField(t.id),className:`size-3.5 rounded border-border accent-primary cursor-pointer`}),(0,G.jsx)(`span`,{children:t.label})]},t.id)})})]}),(0,G.jsx)(BH,{})]})}function bK({controls:e}){let{unit:t,setUnit:n}=RT(),r=e.showRange!==!1,i=e.showUnits!==!1,a=e.weeks!==void 0&&e.onWeeksChange!==void 0;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,"data-testid":`l3-analytics-controls`,children:[e.onOpenQuerySettings&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`This page`}),(0,G.jsx)(cK,{onOpen:e.onOpenQuerySettings})]}),r&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Date range`}),a?(0,G.jsx)(`div`,{className:`flex flex-col gap-0.5`,"data-testid":`l3-range-options`,children:mK.map(t=>{let n=e.weeks===t;return(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":n,onClick:()=>e.onWeeksChange?.(t),"data-testid":`l3-range-${t}w`,className:K(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs transition-colors`,n?`bg-primary/10 font-semibold text-primary`:`text-foreground/80 hover:bg-muted/60 hover:text-foreground`),children:[(0,G.jsx)(`span`,{className:`w-3.5 text-primary`,children:n?(0,G.jsx)(xt,{className:`size-3.5`,"aria-hidden":`true`}):null}),(0,G.jsxs)(`span`,{children:[`Past `,t,` weeks`]})]},t)})}):(0,G.jsx)(kT,{})]}),i&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[`Units`,e.unitForced?` — pinned by query`:``]}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-1`,"data-testid":`l3-unit-options`,children:[`kg`,`lb`].map(r=>{let i=t===r;return(0,G.jsx)(`button`,{type:`button`,disabled:!!e.unitForced,"aria-pressed":i,onClick:()=>n(r),"data-testid":`l3-unit-${r}`,className:K(`flex min-h-8 items-center justify-center rounded-md border px-2 py-1 text-xs font-medium transition-colors`,e.unitForced?`border-transparent text-muted-foreground/50 cursor-not-allowed`:i?`border-border/80 bg-card text-foreground shadow-sm`:`border-transparent text-muted-foreground hover:text-foreground`),children:r},r)})})]})]})}function xK({action:e}){let t=Yz(),n=e.icon;return(0,G.jsxs)(`button`,{type:`button`,disabled:e.disabled,"data-testid":e.testId,onClick:()=>{e.disabled||(t(),e.onRun())},className:K(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[13px] transition-colors`,e.disabled?`cursor-not-allowed text-muted-foreground/45`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[n&&(0,G.jsx)(n,{className:`size-4 shrink-0`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.label,children:e.label})]})}function SK({spec:e,pageAction:t}){let{l3Items:n,l3Actions:r=[],streamControls:i,analyticsControls:a}=SR(),o=BW(e),s=(0,W.useMemo)(()=>GG(n),[n]),c=VW(),l=!!(i||a),u=o.length>0||s.length>0,d=r.length>0||!!t;return!l&&!u&&!d?null:(0,G.jsxs)(`div`,{className:`flex flex-col px-3 py-4 gap-4`,children:[l&&(0,G.jsxs)(`div`,{className:K(`flex flex-col gap-4`,(u||d)&&`pb-3 border-b border-border/50`),children:[i&&(0,G.jsx)(yK,{streamControls:i}),a&&(0,G.jsx)(bK,{controls:a})]}),o.length>0&&(0,G.jsx)(UW,{entries:o,activeId:c}),s.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-col`,children:[(0,G.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,G.jsx)(UW,{entries:s,activeId:c})]}),d&&(0,G.jsxs)(`div`,{"data-testid":`l3-actions`,className:K(`flex flex-col gap-0.5`,u&&`pt-2 border-t border-border/50`),children:[(0,G.jsx)(`div`,{className:`px-2 pb-1 pt-1 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Actions`}),r.map(e=>(0,G.jsx)(xK,{action:e},e.id)),t&&(0,G.jsx)(`div`,{className:K(r.length>0&&`pt-1`),children:t})]})]})}var CK=1023;function wK(e){return e===`/`?`canvas:home`:`canvas:${e.replace(/^\//,``)}`}function TK(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);if(r===null)return null;let i=t[r],{meta:a,body:o}=Oo(i),s=new Set([`search`,`template`,`route`,`type`,`title`,`description`,`subtitle`,`section`,`order`]);return Object.keys(a).some(e=>!s.has(e.trim().toLowerCase()))?i:o};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 EK(e){return(e.examples??[]).length>0||e.commands.some(e=>e.pipeline.length>0)}function DK(e){let t=new Map,n=null;for(let r of e)EK(r)&&(n=r),t.set(r.id,n);return t}function OK(){let[e,t]=(0,W.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: ${CK}px)`).matches);return(0,W.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(max-width: ${CK}px)`),n=e=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}var kK=`wodwiki:fabAlignment`,AK=[{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 jK(){try{return MK(localStorage.getItem(kK))}catch{return}}function MK(e){return e===`right`||e===`left`?e:void 0}var NK=typeof window>`u`?void 0:jK();typeof window<`u`&&window.addEventListener(`storage`,e=>{e.key===kK&&(NK=MK(e.newValue))});function PK(e){NK=e;try{e===`right`?localStorage.removeItem(kK):localStorage.setItem(kK,e)}catch{}window.dispatchEvent(new StorageEvent(`storage`,{key:kK,newValue:e}))}function FK(){let[e,t]=(0,W.useState)(()=>NK??`right`);return(0,W.useEffect)(()=>{let e=e=>{e.key===kK&&t(MK(e.newValue)??`right`)};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),[e,PK]}function IK({onOpen:e}){return(0,G.jsxs)(`button`,{type:`button`,onClick:e,"aria-label":`Search`,title:`Search`,"data-testid":`search-fab`,className:K(`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,G.jsx)(An,{className:`size-6`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Search`})]})}var LK=(0,W.createContext)(null),RK=(0,W.createContext)(!1),zK=(0,W.createContext)(null);function BK(){return(0,W.useContext)(LK)!==null}function VK({primary:e,navbar:t,children:n,label:r,fallback:i=!1}){let a=(0,W.useContext)(LK),o=(0,W.useContext)(RK),s=OK(),c=(0,W.useId)(),l=a!==null&&!o&&s&&!i,u=a!==null&&i,d=W.Children.toArray(n).length>0,f=(0,W.useMemo)(()=>(0,G.jsx)(RK.Provider,{value:!0,children:n}),[n]),p=l||u,m=(0,W.useRef)(null);return m.current={id:c,primary:e,navbar:t,children:f,hasContent:d,label:r??`Page options`,fallback:i},(0,W.useEffect)(()=>{if(p)return a.register(m.current),()=>a.unregister(c)},[p,a,c]),(0,W.useEffect)(()=>{p&&a.register(m.current)},[p,a,e,t,f,d,r,i]),i||a&&s&&!o?null:(0,G.jsx)(RK.Provider,{value:!0,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t,e,n]})})}function HK({onSearch:e,children:t}){let[n,r]=(0,W.useState)([]),i=(0,W.useCallback)(e=>r(t=>{let n=t.findIndex(t=>t.id===e.id);if(n===-1)return[...t,e];let r=t[n];if(r.primary===e.primary&&r.navbar===e.navbar&&r.children===e.children&&r.hasContent===e.hasContent&&r.label===e.label&&r.fallback===e.fallback)return t;let i=[...t];return i[n]=e,i}),[]),a=(0,W.useCallback)(e=>r(t=>t.filter(t=>t.id!==e)),[]),o=(0,W.useMemo)(()=>({register:i,unregister:a}),[i,a]),s=(0,W.useMemo)(()=>{for(let e=n.length-1;e>=0;--e)if(!n[e].fallback)return n[e].navbar??null;return null},[n]);return(0,G.jsx)(LK.Provider,{value:o,children:(0,G.jsxs)(zK.Provider,{value:s,children:[t,(0,G.jsx)(WK,{registrations:n,onSearch:e})]})})}function UK(){let e=(0,W.useContext)(zK);return e?(0,G.jsx)(G.Fragment,{children:e}):null}function WK({registrations:e,onSearch:t}){let n=OK(),[r]=FK(),i=uE(),[a,o]=(0,W.useState)(!1),s=(0,W.useCallback)(()=>o(!1),[]),c=(0,W.useRef)(null),l=(0,W.useRef)(null),u=(0,W.useRef)(null),d=(0,W.useMemo)(()=>{for(let t=e.length-1;t>=0;--t)if(!e[t].fallback)return e[t]},[e]),f=(0,W.useMemo)(()=>{for(let t=e.length-1;t>=0;--t)if(e[t].fallback)return e[t]},[e]);(0,W.useLayoutEffect)(()=>{a&&c.current?.focus({preventScroll:!0})},[a]);let p=!!(d?.hasContent||f?.hasContent);return!n||!t&&!d&&!f?null:(0,G.jsxs)(`div`,{"data-testid":`actions-dock`,className:K(`lg:hidden relative z-40 mt-4 flex flex-col items-center gap-2`,`transition-[transform,visibility] duration-200 ease-out`,r===`left`?`self-start items-start`:`self-end items-end`),children:[(0,G.jsxs)(`div`,{className:`relative z-40 flex flex-col items-center gap-2`,children:[t&&(0,G.jsx)(IK,{onOpen:()=>{o(!1),t()}}),d?.primary&&(0,G.jsx)(`div`,{className:`[&_button]:min-h-11 [&_button]:min-w-11`,children:d.primary})]}),a&&p&&(0,G.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-hidden":`true`,className:`fixed inset-0 z-30 cursor-default`,onClick:()=>o(!1)}),(0,G.jsx)(`div`,{ref:c,role:`dialog`,"aria-label":d?.label??f?.label??`Page options`,tabIndex:-1,hidden:!a||!p,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),o(!1))},className:K(a&&p?`flex`:`hidden`,`relative z-40 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,G.jsxs)(Jz,{close:s,children:[(0,G.jsx)(`div`,{ref:l,className:`contents`,children:d?.children}),d?.children&&f?.children&&(0,G.jsx)(`div`,{className:`my-1 border-t border-border/60`,"aria-hidden":`true`}),(0,G.jsx)(`div`,{ref:u,className:`contents`,children:f?.children})]})}),p&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":d?.label??f?.label??`Page options`,title:d?.label??f?.label??`Page options`,"aria-expanded":a,"data-testid":`actions-overflow`,className:K(`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,G.jsx)(le,{className:`size-6`}):(0,G.jsx)(Qn,{className:`size-6`}),(0,G.jsx)(`span`,{className:`sr-only`,children:d?.label??f?.label??`Page options`})]})]})}var GK=null,KK=new Set;function qK(e){GK=e;for(let e of KK)e();return()=>{if(GK===e){GK=null;for(let e of KK)e()}}}function JK(){return GK}function YK(e){return KK.add(e),()=>{KK.delete(e)}}function XK(){return(0,W.useSyncExternalStore)(YK,JK,()=>null)}var ZK=null,QK=new Set;function $K(e){ZK=e;for(let e of QK)e();return()=>{if(ZK===e){ZK=null;for(let e of QK)e()}}}function eq(){return ZK}function tq(e){return QK.add(e),()=>{QK.delete(e)}}function nq(){return(0,W.useSyncExternalStore)(tq,eq,()=>null)}var rq=null,iq=new Set;function aq(e){rq=e;for(let e of iq)e();return()=>{if(rq===e){rq=null;for(let e of iq)e()}}}function oq(){return rq}function sq(e){return iq.add(e),()=>{iq.delete(e)}}function cq(){return(0,W.useSyncExternalStore)(sq,oq,()=>null)}var lq=0,uq=new Set;function dq(e){if(!e)return()=>{};lq+=1;for(let e of uq)e();let t=!1;return()=>{if(!t){t=!0,lq=Math.max(0,lq-1);for(let e of uq)e()}}}function fq(){return lq>0}function pq(e){return uq.add(e),()=>{uq.delete(e)}}function mq(){return(0,W.useSyncExternalStore)(pq,fq,()=>!1)}function hq(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 gq(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}var _q=[`samples-movement`,`samples-results`],vq=`wodwiki.seedSubscriptions`,yq=`wodwiki.seedAutoSync`;function bq(e){try{let t=typeof localStorage<`u`?localStorage.getItem(e):null;if(!t)return new Set;let n=JSON.parse(t);return!n||typeof n!=`object`||Array.isArray(n)?new Set:new Set(Object.keys(n))}catch{return new Set}}function xq(e){let t=new Set(e.map(e=>e.id)),n=bq(vq),r=bq(yq),i=[];for(let e of _q)t.has(e)&&(n.has(e)||(mI(e,!0),i.push(e)),r.has(e)||xI(e,!0));return i}var Sq=`idle`,Cq=null,wq=!1,Tq=!1,Eq=new Set,Dq=null,Oq=null;function kq(){for(let e of Eq)e()}function Aq(e){typeof document>`u`||(document.documentElement.dataset.feedState=e)}function jq(e){typeof document>`u`||(e===null?delete document.documentElement.dataset.feedOutcome:document.documentElement.dataset.feedOutcome=e)}function Mq(e){typeof document>`u`||(e?document.documentElement.dataset.feedImportPending=`true`:delete document.documentElement.dataset.feedImportPending)}Aq(Sq);function Nq(e){Sq!==e&&(Sq=e,Aq(e),kq())}function Pq(e){wq!==e&&(wq=e,Mq(e),kq())}function Fq(){Dq&&=(clearTimeout(Dq),null),Oq&&=(Oq.close(),null)}function Iq(e){Cq=e,kq()}function Lq(){Fq(),jq(null);let e=Cq!==null,t=!wq;if(Cq=null,wq=!0,Mq(!0),Sq===`preparing`){(e||t)&&kq();return}Nq(`preparing`)}function Rq(){Sq===`preparing`&&Nq(`ready`)}function zq(e){switch(jq(e),e){case`busy`:if(Sq!==`preparing`&&!wq)return;typeof BroadcastChannel<`u`&&!Oq&&(Oq=new BroadcastChannel(ex),Oq.onmessage=e=>{e.data?.kind===`seed-imported`&&(Fq(),Tq=!1,Pq(!1),Nq(`ready`))}),Dq=setTimeout(()=>{AL({onProgress:Iq}).then(zq)},wI);break;case`error`:Fq(),Tq||Pq(!1),Nq(`error`);break;default:Fq(),Tq||Pq(!1),Nq(`ready`)}}function Bq(){return Sq===`idle`?`ready`:Sq}function Vq(){return wq}function Hq(){return Cq}function Uq(e){return Eq.add(e),()=>Eq.delete(e)}function Wq(){return(0,W.useSyncExternalStore)(Uq,Bq)}function Gq(){return(0,W.useSyncExternalStore)(Uq,Vq)}function Kq(){return(0,W.useSyncExternalStore)(Uq,Hq)}var qq=null;function Jq(e={}){return Pw(`feedStart`),(e.isEnabled??uL)()&&Pq(!0),qq??=Xq(e).finally(()=>{Pw(`feedSettled`)}),qq}async function Yq(e,t){for(let n of e)if(!(n.id===`core`||!pI(n.id)||!bI(n.id)))try{let e=await t.getSeedMeta(ix(n.id));if(!e||e.seedVersion<=0)return!0}catch{return!0}return!1}async function Xq(e){let t=t=>{Iq(t),e.onProgress?.(t)},n=e.sources??dL();await HL(e).catch(e=>console.error(`[feedSync] notebook vocabulary migration failed`,e)),await BL(e).catch(e=>console.error(`[feedSync] checkpoint adoption failed`,e)),await SI(n,e.storage).catch(e=>console.error(`[feedSync] subscription migration failed`,e)),xq(n);let r=e.storage??QF(),i;try{i=await r.getSeedMeta(ix(`core`))}catch{i=void 0}let a=!i||i.seedVersion<=0;if(a?(Tq=!0,Lq()):(await Yq(n,r)&&(Tq=!0),zq(`current`)),await VL(e).catch(e=>console.error(`[feedSync] feed provenance repair failed`,e)),a){try{let r=await AL({...e,sources:n,onProgress:t,onFirstPaint:()=>Rq()});r!==`busy`&&r!==`error`&&Rq(),r!==`busy`&&r!==`error`&&n.some(e=>e.id!==`core`&&pI(e.id))&&await AL({...e,sources:n.filter(e=>e.id!==`core`),onProgress:t}).catch(e=>console.error(`[feedSync] background boot sync failed`,e)),Tq=!1,zq(r)}finally{Tq&&(Tq=!1,Pq(!1))}return}try{await AL({...e,sources:n,onProgress:t}).catch(e=>console.error(`[feedSync] background boot sync failed`,e))}finally{Tq&&(Tq=!1,Pq(!1))}}function Zq(){let[e,t]=(0,W.useState)(null);return(0,W.useEffect)(()=>{let e=!1,n=()=>{LL().then(n=>{e||t(!n.libraryImported)}).catch(()=>{e||t(!0)})};n();let r=Ew(()=>n()),i=SL(()=>n()),a=null;if(typeof BroadcastChannel<`u`)try{a=new BroadcastChannel(ex),a.onmessage=()=>n()}catch{}return()=>{e=!0,r(),i(),a?.close()}},[]),e}function Qq(){return(0,G.jsx)(`svg`,{"data-slot":`icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,className:`[&>[data-slot=icon]]:size-5`,children:(0,G.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 $q(){return(0,G.jsx)(`svg`,{"data-slot":`icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,className:`[&>[data-slot=icon]]:size-5`,children:(0,G.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 eJ(){let{tree:e,navState:t,contextNav:n}=SR(),r=z(),i=Yz();return!e.find(e=>e.id===t.activeL1Id)?.applyFooter||n?.pathname===r.pathname?null:(0,G.jsx)(`div`,{className:`shrink-0 border-t border-border/50 bg-card p-3`,children:(0,G.jsx)(`button`,{type:`button`,onClick:i,"data-testid":$.DRAWER_APPLY_BTN,className:`h-11 w-full rounded-lg bg-primary text-sm font-medium text-primary-foreground`,children:`Apply`})})}function tJ({open:e,close:t,onSearch:n,children:r}){return(0,G.jsxs)(it,{open:e,onClose:t,className:`fixed inset-0 z-50 lg:hidden`,children:[(0,G.jsx)(_,{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,G.jsx)(S,{transition:!0,"data-testid":$.MOBILE_NAV_DRAWER,className:`fixed inset-y-0 left-0 w-full transition duration-300 ease-out data-closed:-translate-x-full`,children:(0,G.jsx)(Jz,{close:t,children:(0,G.jsxs)(`div`,{className:`flex h-full min-h-0 bg-card`,children:[(0,G.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,G.jsx)(QW,{onSearch:()=>{t(),n?.()}})}),(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,G.jsx)(`div`,{className:`flex items-center px-4 pt-3`,children:(0,G.jsxs)(Mn,{as:aW,"aria-label":`Close navigation`,title:`Close navigation`,"data-testid":$.MOBILE_NAV_CLOSE,children:[(0,G.jsx)($q,{}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Close navigation`})]})}),(0,G.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:r}),(0,G.jsx)(eJ,{})]})]})})})]})}function nJ({open:e,close:t,children:n}){return(0,W.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(e.stopPropagation(),t())};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),e?(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 2xl:hidden`,"data-testid":`l3-right-drawer`,children:[(0,G.jsx)(`div`,{"aria-hidden":`true`,onClick:t,className:`fixed inset-0 bg-black/25 dark:bg-black/40 transition-opacity`}),(0,G.jsx)(`div`,{role:`region`,"aria-label":`Page options panel`,className:`fixed inset-y-0 right-0 flex h-full min-h-0 w-full lg:w-80 flex-col bg-card lg:border-l lg:border-border/60 lg:shadow-2xl animate-in slide-in-from-right duration-200`,children:(0,G.jsxs)(Jz,{close:t,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/40 px-4 py-2.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Page options`}),(0,G.jsxs)(aW,{onClick:t,"aria-label":`Close page options`,title:`Close page options`,children:[(0,G.jsx)($q,{}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Close page options`})]})]}),(0,G.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:n}),(0,G.jsx)(`div`,{className:`shrink-0 border-t border-border/50 bg-card p-3 lg:hidden`,children:(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`h-11 w-full rounded-lg bg-primary text-sm font-medium text-primary-foreground`,children:`Apply`})})]})})]}):null}function rJ({navbar:e,sidebar:t,onSearch:n,secondary:r,pageAction:i,hideDesktopSidebar:a,children:o}){let[s,c]=(0,W.useState)(!1),{navState:l,dispatch:u,streamControls:d,analyticsControls:f,l3Items:p,l3Actions:m=[]}=SR(),h=!!l?.rightDrawerOpen,g=(0,W.useCallback)(e=>u({type:`SET_RIGHT_DRAWER`,open:e}),[u]),_=(0,W.useCallback)(()=>g(!0),[g]),v=(0,W.useCallback)(()=>g(!1),[g]),y=!!(r&&r.length>0||p&&p.length>0||m&&m.length>0||d||f||i),b=(0,W.useMemo)(()=>{let e=Y(d?.query??``);return!e.error&&Th(e)&&e.filters.length>0},[d?.query]),x=(0,W.useMemo)(()=>({railHasContent:y,hasAppliedFilters:b,openRightDrawer:_}),[y,b,_]);return(0,W.useEffect)(()=>{if(!s&&!h)return;let e=()=>{c(!1),g(!1)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[s,h,g]),(0,W.useEffect)(()=>{if(!y)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`.`&&!e.shiftKey&&!e.altKey){if(window.innerWidth>=1520)return;e.preventDefault(),g(!h)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y,h,g]),(0,G.jsx)(OG,{value:x,children:(0,G.jsx)(VG,{children:(0,G.jsx)(HK,{onSearch:n,children:(0,G.jsx)(`div`,{className:`relative isolate flex min-h-svh w-full bg-background max-lg:flex-col lg:flex-row`,children:(0,G.jsxs)(`div`,{className:`flex flex-1 w-full max-lg:flex-col lg:flex-row`,children:[(0,G.jsxs)(`nav`,{"aria-label":`Main`,className:`hidden lg:flex`,children:[(0,G.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,G.jsx)(QW,{onSearch:n??(()=>{})})}),(0,G.jsx)(`div`,{className:K(`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`,a&&`lg:hidden`),children:t})]}),(0,G.jsx)(tJ,{open:s,close:()=>c(!1),onSearch:n,children:t}),(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col min-w-0 xl:max-w-[984px] 2xl:max-w-none`,children:[(0,G.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,G.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,G.jsxs)(aW,{onClick:()=>c(!0),"aria-label":`Open navigation`,title:`Open navigation`,"data-testid":$.MOBILE_NAV_OPEN,children:[(0,G.jsx)(Qq,{}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Open navigation`})]})}),(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:e}),y&&(0,G.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,G.jsxs)(aW,{onClick:_,"aria-label":`Open page options`,title:`Open page options`,children:[(0,G.jsxs)(`span`,{className:`relative inline-flex`,children:[(0,G.jsx)(Nn,{className:`size-5`}),b&&(0,G.jsx)(`span`,{"data-testid":`drawer-filters-active`,className:`absolute -top-1 -right-1 size-2 rounded-full bg-amber-500`,"aria-hidden":`true`})]}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Open page options`})]})})]}),(0,G.jsxs)(iJ,{children:[(0,G.jsx)(`div`,{className:`grow w-full max-lg:pb-48 lg:overflow-visible`,children:o}),(0,G.jsx)(aJ,{})]})]}),(0,G.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,G.jsx)(SK,{spec:r,pageAction:i})}),(0,G.jsx)(nJ,{open:h,close:v,children:(0,G.jsx)(SK,{spec:r,pageAction:i})})]})})})})})}function iJ({children:e}){let t=z(),n=mq(),r=Wq(),i=Gq(),a=Kq(),o=n||r===`preparing`||i,s=i&&r!==`preparing`&&t.pathname!==`/`,c=s?gq(a):null;return(0,G.jsxs)(`main`,{"aria-busy":o,"data-agent-status":o?`loading`:`ready`,className:`flex flex-1 flex-col lg:min-w-0`,children:[e,s&&(0,G.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`boot-import-progress`,className:`pointer-events-none fixed bottom-4 right-4 z-30 flex items-center gap-2 rounded-lg border border-border bg-card/95 px-3 py-1.5 text-xs text-foreground shadow-sm`,children:[(0,G.jsx)(`span`,{children:a?hq(a):`Importing library…`}),c&&(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:c})]})]})}function aJ(){let e=(0,W.useRef)(null),[t,n]=(0,W.useState)(0);return(0,W.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,W.useEffect)(()=>(document.documentElement.style.setProperty(`--thumb-dock-lift`,`${t}px`),()=>document.documentElement.style.setProperty(`--thumb-dock-lift`,`0px`)),[t]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:K(`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,G.jsx)(`div`,{ref:e,className:`w-full min-w-0`,children:(0,G.jsx)(HG,{className:`flex w-full min-w-0`})})}),(0,G.jsx)(`div`,{className:`lg:hidden`,"aria-hidden":`true`,style:{height:t}})]})}function oJ(e){let t=e.indexOf(`markdown`);return t!==-1&&e.length>t+2?e[t+2]:`General`}function sJ(e){return String(Mo(Oo(e).meta,`search`)??``).toLowerCase()===`hidden`}function cJ(e){let t=Mo(Oo(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 lJ(e){return Object.entries(e).map(([e,t])=>{let n=e.split(`/`),r=n[n.length-1].replace(`.md`,``),i=t,a=Mo(Oo(i).meta,`title`);return{id:e,name:r,displayName:typeof a==`string`&&a.trim()?a.trim():NM(r),category:oJ(n),content:i,date:cJ(i),searchHidden:sJ(i)}})}function uJ(){let e=nN();return(0,W.useMemo)(()=>e?lJ(e):[],[e])}var dJ={};function fJ(e,t){let{canvasPage:n,workoutItems:r,selectWorkout:i}=t;if(e===`/`)return[];if(n){let t=/^\/notebook\//.test(e),a=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=DU(e).split(`
753
+ `)){/^`{3,}/.test(e)&&(m=!m);let t=m?null:AU(e);t?(f&&p(f),f={heading:t.text,level:t.level,attrs:t.attrs,lines:[]}):f&&f.lines.push(e)}return f&&p(f),{template:`canvas`,route:u,type:n.type?String(n.type):void 0,sections:d,frontmatter:n,quests:i,chapters:l,scroll:o,namedScrolls:s}}function XU(e){if(!e)return`/`;let t=e.trim();return t.startsWith(`/`)||(t=`/`+t),t=t.replace(/\/+/g,`/`),t.length>1&&t.endsWith(`/`)&&(t=t.slice(0,-1)),t}function ZU(e,t){let n=XU(t);for(let t of e)if(t.route===n)return t.page;return null}function QU(e){return[XU(e)]}function $U(e,t){for(let n of QU(t)){let t=ZU(e,n);if(t!==null)return t}return null}function eW(e){let t=[];for(let[n,r]of Object.entries(e))if(n.match(/^markdown\/canvas\/(.+\.md)$/)){let e=YU(r);e&&e.route!==Q.home&&t.push({route:e.route,page:e});continue}return t}function tW(e,t){return $U(e,t)}function nW(){let e=nN();return(0,W.useMemo)(()=>e?eW(e):[],[e])}function rW(e){let t=nW();return(0,W.useMemo)(()=>tW(t,e),[t,e])}function iW({className:e,...t}){return(0,G.jsx)(`nav`,{...t,className:Oe(e,`flex flex-1 items-center gap-2 sm:gap-4 py-2.5 min-w-0`)})}var aW=(0,W.forwardRef)(function({current:e,className:t,children:n,...r},i){let a=Oe(`group relative flex min-w-0 min-h-11 min-w-11 items-center justify-center gap-3 rounded-lg p-2 text-left text-base/6 font-medium text-foreground sm:text-sm/5 sm:justify-start`,`[&>[data-slot=icon]]:size-6 [&>[data-slot=icon]]:shrink-0 [&>[data-slot=icon]]:fill-muted-foreground sm:[&>[data-slot=icon]]:size-5`,`[&>*:not(:nth-child(2)):last-child[data-slot=icon]]:ml-auto [&>*:not(:nth-child(2)):last-child[data-slot=icon]]:size-5 sm:[&>*:not(:nth-child(2)):last-child[data-slot=icon]]:size-4`,`[&>[data-slot=avatar]]:-m-0.5 [&>[data-slot=avatar]]:size-7 [&>[data-slot=avatar]]:[--avatar-radius:theme(borderRadius.md)] sm:[&>[data-slot=avatar]]:size-6`,`data-[hover]:bg-muted/50 data-[hover]:[&>[data-slot=icon]]:fill-foreground`,`data-[active]:bg-muted/50 data-[active]:[&>[data-slot=icon]]:fill-foreground`,`dark:data-[hover]:bg-white/5 dark:data-[hover]:[&>[data-slot=icon]]:fill-foreground`,`dark:data-[active]:bg-white/5 dark:data-[active]:[&>[data-slot=icon]]:fill-foreground`);return(0,G.jsxs)(`span`,{className:Oe(t,`relative`),children:[e&&(0,G.jsx)(_e.span,{layoutId:`current-indicator`,className:`absolute inset-x-2 -bottom-2.5 h-0.5 rounded-full bg-foreground`}),typeof r.href==`string`?(0,G.jsx)(eB,{...r,className:a,"data-current":e?`true`:void 0,"aria-current":e?`page`:void 0,ref:i,children:(0,G.jsx)($z,{children:n})}):(0,G.jsx)(Ce,{...r,className:Oe(`cursor-default`,a),"data-current":e?`true`:void 0,"aria-current":e?`page`:void 0,ref:i,children:(0,G.jsx)($z,{children:n})})]})}),$={WORKBENCH_ROOT:`workbench-root`,WORKBENCH_HEADER:`workbench-header`,WORKBENCH_RESET_BUTTON:`workbench-reset`,WORKBENCH_DOWNLOAD_BUTTON:`workbench-download`,TAB_PLAN:`tab-plan`,TAB_TRACK:`tab-track`,TAB_REVIEW:`tab-review`,TRACKER_PANEL:`tracker-panel`,TRACKER_NEXT_BUTTON:`tracker-next`,TRACKER_CURRENT_BLOCK_LABEL:`tracker-current-block`,TRACKER_ROUND_INDICATOR:`tracker-round`,TRACKER_REP_INDICATOR:`tracker-reps`,TRACKER_COMPLETION_BANNER:`tracker-completion`,TIMER_DISPLAY:`timer-display`,TIMER_VALUE:`timer-value`,TIMER_NEXT_BLOCK:`timer-next-block`,TIMER_STOP_SESSION:`timer-stop-session`,TIMER_PLAY_PAUSE:`timer-play-pause`,TIMER_UP_NEXT_CAPTION:`timer-up-next-caption`,TIMER_SURFACE_MINIMAL:`timer-surface-minimal`,TIMER_SURFACE_GENERAL:`timer-surface-general`,TIMER_METRIC_PROMPTS:`timer-metric-prompts`,TIMER_STACK_DRAWER_TOGGLE:`timer-stack-drawer-toggle`,TIMER_STACK_DRAWER:`timer-stack-drawer`,FOCUSED_DIALOG_CLOSE:`focused-dialog-close`,CLOCK_COMMAND_BOARD:`clock-command-board`,CLOCK_REP_COUNTER:`clock-rep-counter`,CLOCK_REP_VALUE:`clock-rep-value`,CLOCK_REP_MINUS:`clock-rep-minus`,CLOCK_REP_PLUS:`clock-rep-plus`,CLOCK_REP_SELECT:`clock-rep-select`,CLOCK_VALUES_BUTTON:`clock-values-button`,CLOCK_DRAFT_CHIP:`clock-draft-chip`,CLOCK_LEGEND:`clock-legend`,CLOCK_KEY_MODE_TOGGLE:`clock-key-mode-toggle`,CLOCK_KEY_CHECK_BUTTON:`clock-key-check-button`,CLOCK_KEY_CHECK_DIALOG:`clock-key-check-dialog`,CLOCK_STOP_CONFIRM:`clock-stop-confirm`,CLOCK_STOP_CONFIRM_ACCEPT:`clock-stop-confirm-accept`,CLOCK_STOP_CONFIRM_CANCEL:`clock-stop-confirm-cancel`,CLOCK_ENTRY_OVERLAY:`clock-entry-overlay`,CLOCK_ERROR:`clock-error`,REVIEW_PANEL:`review-panel`,REVIEW_RESULTS_TABLE:`review-results-table`,REVIEW_METRIC_ROW:`review-metric-row`,REVIEW_TOTAL_TIME:`review-total-time`,EDITOR_PANEL:`editor-panel`,EDITOR_CONTENT:`editor-content`,EDITOR_START_WORKOUT:`editor-start-workout`,TESTBENCH_ROOT:`testbench-root`,TESTBENCH_NEXT_BUTTON:`testbench-next`,TESTBENCH_RUNTIME_STACK:`testbench-runtime-stack`,TESTBENCH_MEMORY:`testbench-memory`,TESTBENCH_SCRIPT_EDITOR:`testbench-script-editor`,EFFORTS_ROOT:`efforts-root`,EFFORTS_SEARCH:`efforts-search`,EFFORTS_CREATE_BTN:`efforts-create-btn`,EFFORTS_EMPTY_STATE:`efforts-empty-state`,EFFORTS_LOADING:`efforts-loading`,EFFORT_DETAIL_ROOT:`effort-detail-root`,EFFORT_DETAIL_LABEL:`effort-detail-label`,EFFORT_DETAIL_ALIASES:`effort-detail-aliases`,EFFORT_DETAIL_ATTRIBUTES:`effort-detail-attributes`,EFFORT_DETAIL_SOURCE:`effort-detail-source`,EFFORT_DETAIL_EDIT_BTN:`effort-detail-edit-btn`,EFFORT_DETAIL_CLONE_BTN:`effort-detail-clone-btn`,EFFORT_DETAIL_SAVE_BTN:`effort-detail-save-btn`,EFFORT_DETAIL_CANCEL_BTN:`effort-detail-cancel-btn`,EFFORT_DETAIL_DELETE_BTN:`effort-detail-delete-btn`,EFFORT_DETAIL_NOTEBOOK_EDITOR:`effort-detail-notebook-editor`,EFFORT_DETAIL_ANALYTICS_PLACEHOLDER:`effort-detail-analytics-placeholder`,EFFORT_NOT_FOUND:`effort-not-found`,EFFORT_NOT_FOUND_CREATE_BTN:`effort-not-found-create-btn`,EFFORT_NOT_FOUND_ALIAS_BTN:`effort-not-found-alias-btn`,EFFORT_NOT_FOUND_ALIAS_SELECT:`effort-not-found-alias-select`,EFFORT_NOT_FOUND_ALIAS_CONFIRM:`effort-not-found-alias-confirm`,EFFORTS_NAV_ORIGIN_FILTER:`efforts-nav-origin-filter`,EFFORTS_NAV_DISCIPLINE_FILTER:`efforts-nav-discipline-filter`,EFFORTS_NAV_RECENT_WORKOUTS:`efforts-nav-recent-workouts`,EFFORTS_NAV_RECENT_WORKOUT_ITEM:`efforts-nav-recent-workout-item`,EQUIPMENT_DETAIL_ROOT:`equipment-detail-root`,EQUIPMENT_DETAIL_LABEL:`equipment-detail-label`,EQUIPMENT_DETAIL_SOURCE:`equipment-detail-source`,EQUIPMENT_DETAIL_CLONE_BTN:`equipment-detail-clone-btn`,EQUIPMENT_DETAIL_NOTEBOOK_EDITOR:`equipment-detail-notebook-editor`,EQUIPMENT_NOT_FOUND:`equipment-not-found`,EQUIPMENT_NOT_FOUND_CREATE_BTN:`equipment-not-found-create-btn`,EQUIPMENT_CREATE_BTN:`equipment-create-btn`,EQUIPMENT_LOAD_ERROR:`equipment-load-error`,COMMAND_PALETTE_TRIGGER:`command-palette-trigger`,COMMAND_PALETTE_INPUT:`command-palette-input`,COMMAND_PALETTE_RESULTS:`command-palette-results`,NAV_L1_HOME:`nav-l1-home`,NAV_L1_JOURNAL:`nav-l1-journal`,NAV_L1_LIBRARY:`nav-l1-library`,NAV_L1_DASHBOARDS:`nav-l1-dashboards`,NAV_L1_SEARCH:`nav-l1-search`,MOBILE_NAV_OPEN:`mobile-nav-open`,MOBILE_NAV_DRAWER:`mobile-nav-drawer`,MOBILE_NAV_CLOSE:`mobile-nav-close`,DRAWER_APPLY_BTN:`drawer-apply-btn`,NEW_ENTRY_PRIMARY:`new-entry-primary`,STREAM_VIEW:`queriable-stream-view`,STREAM_FEED_ITEM:`stream-feed-item`,STREAM_QUERY_BAR:`stream-query-bar`,SAVE_STREAM_QUERY:`save-stream-query`,REMOTE_NOTEBOOK_PREVIEW_BANNER:`remote-notebook-preview-banner`,WIDGET_COMPOSER_SUBSET:`widget-composer-subset`,WIDGET_COMPOSER_WQL:`widget-composer-wql`,WIDGET_COMPOSER_APPLY:`widget-composer-apply`,PROPERTY_TABLE:`property-table`,LIBRARY_ROW_NOTEBOOK:`library-row-notebook`,NOTEBOOKS_CREATE_BUTTON:`notebooks-create-button`,ENTRY_CREATE_TITLE_INPUT:`entry-create-title-input`,ENTRY_CREATE_DATE_INPUT:`entry-create-date-input`,ENTRY_CREATE_SUBMIT_BTN:`entry-create-submit-btn`,ENTRY_CREATE_CANCEL_BTN:`entry-create-cancel-btn`,NOTEBOOK_DIALOG_NAME_INPUT:`notebook-dialog-name-input`,NOTEBOOK_DIALOG_SAVE_BTN:`notebook-dialog-save-btn`,PLACEMENT_DIALOG:`placement-dialog`,PLACEMENT_DATE_INPUT:`placement-date-input`,PLACEMENT_SLUG_INPUT:`placement-slug-input`,PLACEMENT_ADD_BTN:`placement-add-btn`,PLACEMENT_MOVE_BTN:`placement-move-btn`,PLACEMENT_REMOVE_BTN:`placement-remove-btn`,PLACEMENT_CLONE_SUBMIT_BTN:`placement-clone-submit-btn`,PUBLICATION_PILL:`publication-pill`,PUBLICATION_PILL_POPOVER:`publication-pill-popover`,PROMOTION_PROVENANCE_ROW:`promotion-provenance-row`,PROMOTION_CLONE_READONLY_BTN:`promotion-clone-readonly-btn`,PROMOTION_NEW_NOTEBOOK_INPUT:`promotion-new-notebook-input`,PROMOTION_NEW_NOTEBOOK_SUBMIT:`promotion-new-notebook-submit`,PUBLICATION_NOTEBOOK_PUBLIC_TOGGLE:`publication-notebook-public-toggle`,PUBLICATION_EXPORT_REPO_ZIP_BTN:`publication-export-repo-zip-btn`,PROPERTY_OVERRIDE_SHEET:`property-override-sheet`,PROPERTY_OVERRIDE_EDITOR:`property-override-editor`,PROPERTY_OVERRIDE_SAVE_BTN:`property-override-save-btn`,PROPERTY_OVERRIDE_CANCEL_BTN:`property-override-cancel-btn`,TIMER_FULLSCREEN_OVERLAY:`timer-fullscreen-overlay`,TIMER_DETAIL_SURFACE:`timer-detail-surface`,SYNC_SUBSCRIBED_ONLY_TOGGLE:`sync-subscribed-only-toggle`,UNKNOWN_FEED_INTAKE_BANNER:`unknown-feed-intake-banner`,FEED_INTAKE_SUBSCRIBE:`feed-intake-subscribe`,FEED_INTAKE_ONCE:`feed-intake-once`,FEED_SUBSCRIPTION_INTAKE:`feed-subscription-intake`,REGISTERED_FEED_INTAKE_CARD:`registered-feed-intake-card`,REGISTERED_FEED_SUBSCRIBE_BTN:`registered-feed-subscribe-btn`,FEED_DETAIL_SUBSCRIBE_BUTTON:`feed-detail-subscribe-button`,HALTED_RUN_NOTICE:`halted-run-notice`,NOTEBOOK_NOT_FOUND:`notebook-not-found`,STREAM_QUERY_SYNTAX_HINT:`stream-query-syntax-hint`,DELETE_DASHBOARD_BUTTON:`delete-dashboard-button`,CONFIRM_DELETE_DASHBOARD:`confirm-delete-dashboard`,CONDITIONS_NAV_RECENT:`conditions-nav-recent`,LOAD_ZIP_INTAKE:`load-zip-intake`,BUNDLE_FILE_INPUT:`bundle-file-input`,BUNDLE_IMPORT_ERROR:`bundle-import-error`,AGENT_CONFIRM_DIALOG:`agent-confirm-dialog`,AGENT_CONFIRM_APPROVE:`agent-confirm-approve`,AGENT_CONFIRM_CANCEL:`agent-confirm-cancel`,WEBMCP_DEBUG_INSPECTOR:`webmcp-debug-inspector`,tour:{HOME_TOUR:`home-tour`,HERO:`tour-hero`,HERO_RESET_SHARED:`tour-hero-reset-shared`,SECTION_EDITOR:`tour-section-editor`,WHY_WATCH_AGAIN:`tour-why-watch-again`,WHY_VIDEO:`tour-why-video`,WHY_VIDEO_SKIP:`tour-why-video-skip`,SCROLL_HINT:`tour-scroll-hint`,SECTION_INSIGHTS:`tour-section-insights`,INSIGHTS_EMPTY:`tour-insights-empty`,INSIGHTS_RUN:`tour-insights-run`,INSIGHTS:`tour-insights`,INSIGHTS_TIMELINE:`tour-insights-timeline`,INSIGHTS_IMPATIENCE:`tour-insights-impatience`,INSIGHTS_REACTION:`tour-insights-reaction`,PANE_BACK_TO_EDITOR:`tour-pane-back-to-editor`,STICKY_PANE:`tour-sticky-pane`,SESSION_DASHBOARD:`tour-session-dashboard`,SESSION_DASHBOARD_SOURCE:`tour-session-dashboard-source`,WOD_BLOCK_REGION:`tour-wod-block-region`,RUN_BUTTON_REGION:`tour-run-button-region`,JUMP_SECTION:`tour-jump-section`,LEARN:`tour-learn`,FOOTER:`tour-footer`,CHAPTER_PICKER:`tour-chapter-picker`,CAPTIONS:`tour-captions`,RING:`tour-ring`}},oW=_b({getEventsByTimeRange:(e,t)=>X.getEventsByTimeRange(e,t),getEventsByMetricDates:e=>X.getEventsByMetricDates(e),getEventsByResult:e=>X.getEventsByResult(e),getEventsForNote:e=>X.getEventsForNote(e),getEventsByContent:e=>X.getEventsByContent(e),scanAll:()=>X.scanAll(),appendEvents:e=>X.appendEvents(e),finalizeSummaries:(e,t)=>X.finalizeSummaries(e,t),deleteEvents:e=>X.deleteEvents(e)}),sW={getAllNotes:()=>X.getAllNotes(),getNotesByIds:async e=>[...(await X.getDetailBatches(e)).values()].map(e=>e.note),getNoteIdsForTag:async e=>new Set((await X.getNotesForTag(e)).map(e=>e.id)),getNoteTagLabels:async e=>(await X.getTagsForNote(e)).map(e=>e.label),queryDomain:async e=>{if(!X.queryDomain)return;let t=await X.queryDomain({...e,plan:`notes`});return t&&t.plan===`notes`?t:void 0}},cW={getAllBlocks:()=>X.getAllBlockIndex(),queryDomain:async e=>{if(!X.queryDomain)return;let t=await X.queryDomain({...e,plan:`blocks`});return t&&t.plan===`blocks`?t:void 0}},lW=class{async getAllEfforts(){let e=OM();return e.isInitialized()||await CM(e),[...e.list()]}},uW=new Ev,dW={events:[],notes:[]},fW={events:[],notes:[]};uW.set(`@session`,dW),uW.set(`@today`,fW);function pW(){let{runtime:e,activeNoteId:t}=vF.getState(),n=e?.getOutputStatements()??[];if(dW.notes=[],n.length===0)return dW.events=[],dW;let r=t??``;return dW.events=Rv(n.map(Tm),{noteId:r,resultId:`live:${r||`session`}`,origin:`playground`}),dW}function mW(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 ev(e.date??e.createdAt,r)}async function hW(e,t){let n=ev(e.instant,e.timeZone),r=av(n,e.timeZone),i=av(tv(n,1),e.timeZone),[a,o,s,c]=await Promise.all([X.getEventsByTimeRange(r,i),X.getAllNotes(),X.getAllPageNotes(),X.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)mW(t,d.get(t.id)??[],u,e.timeZone)===n&&f.push(t);t===vW&&(fW.events=l,fW.notes=f,pW())}var gW=null,_W=null,vW=0,yW=!1,bW=new Set;function xW(){for(let e of bW)e()}function SW(e,t){_W=t;let n=++vW;return gW=hW(e,n),gW.then(()=>{n===vW&&CW()},()=>{n===vW&&CW()}),gW}function CW(){yW=!0,xW()}function wW(){let e=J_(),t=ev(e.instant,e.timeZone);return!gW||_W!==t?SW(e,t):gW}function TW(){yW=!1;let e=J_();return SW(e,ev(e.instant,e.timeZone))}function EW(){return yW}function DW(e){return bW.add(e),()=>{bW.delete(e)}}async function OW(){await Promise.all([VN(),$N()])}var kW=class extends Fy{async runQuery(e,t){return await Promise.all([OW(),wW()]),super.runQuery(e,t)}async runPipeline(e,t){return await Promise.all([OW(),wW()]),super.runPipeline(e,t)}async runFind(e,t){return await Promise.all([OW(),wW()]),super.runFind(e,t)}async runRows(e,t){return await Promise.all([OW(),wW()]),super.runRows(e,t)}async run(e,t){return await Promise.all([OW(),wW()]),super.run(e,t)}};function AW(){return new kW({eventStore:oW,noteStore:sW,blockStore:cW,effortStore:new lW,blockEffortsStore:{getAllFromIndex:(e,t)=>X.getAllFromIndex(`block_efforts`,e,t)},blockEquipmentStore:{getAllFromIndex:(e,t)=>X.getAllFromIndex(`block_equipment`,e,t)},tagsStore:{getAllFromIndex:(e,t)=>X.getAllFromIndex(`tags`,e,t),getAll:()=>X.getAllTags()},noteTagsStore:{getAllFromIndex:(e,t)=>X.getAllFromIndex(`note_tags`,e,t)},pageStore:{getNotePages:e=>X.getNotePages(e),getPage:e=>X.getPage(e),getAllPages:()=>X.getAllPages(),getAllLinks:()=>X.getAllPageNotes()},relationStore:{getBatches:e=>X.getDetailBatches(e)},datasetStore:{getDataset:e=>e===`@session`?pW():uW.getDataset(e)},feedCatalogStore:lL,isNotebookSubscribed:(e,t)=>hI(e,t)})}var jW=AW();function MW(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?LV(a):`${t===`segment`?`Segment`:`Event`} ${n+1}`,date:typeof e.date==`string`?e.date:null,subtitle:o.length>0?o.join(` • `):void 0}}function NW(e){let t=e.parsed.family===`aggregate`?e.parsed.metric:`metric`;return e.series.map(e=>{let n=e.points.map(t=>`${t.value}${e.unit?` ${e.unit}`:``}`).join(` • `);return{id:`aggregate:${t}:${e.key}`,kind:`result`,sourceNotebook:`results`,sourceNote:e.label,title:`${t}: ${n}`,subtitle:e.label,date:null}})}function PW(e,t,n){e&&e({selected:Math.max(t?.selected??0,n.length),matched:n.length})}function FW(e){return typeof e==`object`&&!!e&&`runFind`in e}var IW=new class e{customService;noteTitleResolver;noteTagsResolver;noteBlockInfo;constructor(e){FW(e)?this.customService=e:(this.customService=e?.service,this.noteTitleResolver=e?.noteTitleResolver,this.noteBlockInfo=e?.noteBlockInfo??!1,this.noteTagsResolver=e?.noteTagsResolver),this.noteTitleResolver||=async e=>{try{let t=await X.getNote(e);return t?MC(t.title)||NC(t.rawContent??``):void 0}catch{return}}}get service(){return this.customService??jW}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,n){let r=new Set;for(let i of e){if(i.kind===`feed`||i.kind===`notebook`||i.isRemotePreview)continue;let e=!!(n&&Object.prototype.hasOwnProperty.call(n,i.id));i.sourceNotebook===`journal`&&!e&&r.add(i.id),t&&(!e&&(!i.title||!i.tags||i.tags.length===0)||e&&i.tags&&i.tags.length>0&&!i.typedTags)&&r.add(i.id)}if(r.size===0)return;let i=await X.getDetailBatches([...r]);for(let t of e){if(t.sourceNotebook!==`journal`)continue;let e=i.get(t.id),r=n?.[t.id]??Ja(e?.links??[],e?.pages??[]);t.placements=r;let a=Ya(r);t.pageId??=a.pageId,a.pageSlug&&(t.pageSlug=a.pageSlug)}if(t)for(let t of e){let e=i.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,n){let r=typeof e==`string`?Y(e):e;if(!r||r.error)return[];if(Th(r)){if(r.target===`effort`){let e=this.service.runFindEffort?await this.service.runFindEffort(r):await this.service.runFind(r),n=new Map(e.notes.map(e=>[e.id,e])),i=(e.efforts??[]).map(e=>e.ownerNoteId&&n.has(e.ownerNoteId)?AV(n.get(e.ownerNoteId)):BV(e));return PW(t,e.stages,i),i}if(r.target===`block`){let e=await this.service.runFind(r),n=e.blocks.map(IV);return await this.hydrateEntries(n,!0),PW(t,e.stages,n),n}if(r.target===`session`){let e=await this.service.runFind(r);t?.(e.stages);let n;if(this.noteTitleResolver&&e.runs){n=new Map;for(let t of e.runs)if(!n.has(t.noteId)){let e=await this.noteTitleResolver(t.noteId);e&&n.set(t.noteId,e)}}let i=QV(e,{noteTitles:n});return PW(t,e.stages,i),i}if(r.target===`segment`||r.target===`event`){let e=r.target,n=await this.service.runFind(r),i=(n.table?.rows??[]).map((t,n)=>MW(t,e,n));return PW(t,n.stages,i),i}let e=await this.service.runFind(r,n?.notebookPlane?{notebookPlane:n.notebookPlane}:void 0),i=e.notes.map(AV);if(this.noteTagsResolver?(await this.hydrateEntries(i,!1,e.placements),await Promise.all(i.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(i,!0,e.placements),PW(t,e.stages,i),this.noteBlockInfo)for(let t=0;t<i.length;t++){let n=i[t],r=e.notes[t];n.excerpt=FV(r.rawContent);try{ho(r.rawContent,r.blocks,r.sourceRevision)}catch{continue}let a=Object.values(r.blocks).sort((e,t)=>e.from-t.from).find(e=>e.kind===`wod`),o=a&&fo(r.rawContent).find(e=>e.from===a.from&&e.scriptBlock);if(a&&o?.scriptBlock){let e=o.scriptBlock.content,t=Ga(e);n.wodBlock={blockId:a.id,blockVersion:a.version,blockContentId:t,content:e},n.blockContentId=t}}return i}if(r.family===`aggregate`){if(!this.service.runQuery)return[];let e=await this.service.runQuery(r.raw),n=NW(e);return t?.({selected:e.stages?.selected??n.length,matched:n.length}),n}return[]}};async function LW(e,t=IW,n){return t.query(e,n)}function RW(e){return e?e.map(e=>e.kind===`wql`?`${e.id}|${e.query}|${e.limit??``}`:`s:${e.id}`).join(`;`):``}async function zW(e){try{let t=(await LW(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 BW(e){let t=RW(e),n=(0,W.useRef)(e);n.current=e;let[r,i]=(0,W.useState)(()=>e&&!e.some(e=>e.kind===`wql`)?e:[]);return(0,W.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`?zW(e):Promise.resolve(e))).then(e=>{t||i(e)}),()=>{t=!0}},[t]),r}function VW(){let[e]=ie(`h`,{shallow:!0}),[t]=ie(`s`,{shallow:!0}),{navState:n}=SR(),r=n.activeL3Id??``;return e||t||r||``}function HW({entry:e,active:t,onActivate:n,onFilter:r}){let i=e.onRun,a=e.filterTo,o=e.filterLabel??`Filter notes by ${e.label}`,s=e.runIcon===`link`?`View workout`:e.runIcon===`stop`?`Stop workout`:e.runIcon===`edit`?`Edit note`:`Start workout`,c=(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:K(`flex min-w-0 flex-1 items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors`,!i&&!a&&`w-full`,e.muted?`text-[11.5px]`:`text-[13px]`,t?`bg-primary/10 font-semibold text-primary`:K(`hover:bg-muted/60 hover:text-foreground`,e.muted?`text-muted-foreground/70`:`text-muted-foreground`)),children:[e.icon&&(0,G.jsx)(e.icon,{className:`size-4 shrink-0`}),e.timestamp&&(0,G.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/60`,children:e.timestamp}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 line-clamp-2 break-words`,title:e.label,children:e.label}),e.badge&&(0,G.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 font-mono text-[9.5px] uppercase tracking-wide text-muted-foreground/80`,children:e.badge})]});return!i&&!a?c:(0,G.jsxs)(`div`,{className:`group flex w-full items-center gap-0.5`,children:[c,a&&(0,G.jsx)(`button`,{type:`button`,"aria-label":o,title:o,"data-testid":`menu-filter-${e.id}`,onClick:()=>r(a),className:`flex size-7 max-lg:size-9 shrink-0 items-center justify-center rounded-md text-muted-foreground/55 transition-colors hover:bg-muted hover:text-foreground`,children:(0,G.jsx)(fr,{className:`size-3.5`})}),i&&(0,G.jsx)(`button`,{type:`button`,"aria-label":s,title:s,onClick:()=>e.onRun?.(),className:`flex size-6 max-lg:size-8 shrink-0 items-center justify-center rounded text-primary opacity-70 lg:opacity-0 transition-all group-hover:opacity-100 hover:bg-primary/10`,children:e.runIcon===`link`?(0,G.jsx)(bn,{className:`size-3.5`}):e.runIcon===`stop`?(0,G.jsx)(Nt,{className:`size-3.5`}):e.runIcon===`edit`?(0,G.jsx)(pr,{className:`size-3.5`}):(0,G.jsx)(Yn,{className:`size-3.5`})})]})}function UW({entries:e,activeId:t,onSection:n}){let r=lt(),{scrollToSection:i}=SR(),a=Yz(),o=e=>{if(a(),n)return n(e);if(e.onSelect)return e.onSelect();if(e.onRun)return e.onRun();if(e.to)return r(e.to);if(e.sectionId)return i(e.sectionId)},s=e=>{a(),r(e)};return(0,G.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>e.kind===`section`?e.entries.length===0?null:(0,G.jsxs)(`div`,{className:`mt-1 flex flex-col gap-0.5 first:mt-0`,children:[(0,G.jsx)(`div`,{className:`px-2 pb-1 pt-3 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:e.label}),(0,G.jsx)(UW,{entries:e.entries,activeId:t,onSection:n})]},e.id):e.kind===`wql`?null:e.kind===`widget`?(0,G.jsx)(`div`,{className:`px-1 py-1`,children:e.render()},e.id):(0,G.jsx)(HW,{entry:e,active:t!=null&&e.sectionId===t,onActivate:o,onFilter:s},e.id))})}function WW(){let e=lt(),{scrollToSection:t}=SR();return{navigate:(t,n)=>e(t,{replace:n?.replace}),setQueryParam:(e,t)=>{},scrollToSection:t}}function GW(){let e=WW(),t=Yz();return n=>{t(),aH(n.action,e)}}function KW(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 qW({items:e}){let{navState:t}=SR(),n=z(),r=GW();return(0,G.jsx)(iB,{children:e.map(e=>{let i=KW(e,t,n);return e.children&&e.children.length>0?(0,G.jsx)(uH,{title:e.label,count:e.children.length,defaultOpen:e.children.some(e=>KW(e,t,n)),collapsible:e.id!==`syntax-group`,children:e.children.map(e=>{let i=KW(e,t,n);return(0,G.jsxs)(oB,{onClick:()=>r(e),current:i,children:[e.icon&&(0,G.jsx)(e.icon,{"data-slot":`icon`}),(0,G.jsx)(sB,{children:e.label})]},e.id)})},e.id):(0,G.jsxs)(`div`,{className:`group relative flex items-center`,children:[(0,G.jsxs)(oB,{onClick:e.disabled?void 0:()=>r(e),current:i,disabled:e.disabled,"aria-label":e.disabled?`${e.label} (coming soon)`:void 0,className:K(`flex-1`,e.disabled&&`opacity-60`),children:[e.icon&&(0,G.jsx)(e.icon,{"data-slot":`icon`}),(0,G.jsx)(sB,{children:e.disabled?`+`:e.label})]}),e.onTogglePin&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e.onTogglePin?.()},title:e.pinned?`Unpin from sidebar`:`Pin to sidebar`,"aria-label":e.pinned?`Unpin ${e.label}`:`Pin ${e.label}`,className:`opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-1 text-muted-foreground hover:text-foreground transition-opacity`,children:(0,G.jsx)(L,{className:`size-3.5`})})]},e.id)})})}function JW({navSpec:e}){let{tree:t,navState:n,dispatch:r,contextNav:i}=SR(),a=z(),o=BW(e),s=(t??[]).find(e=>e?.id===n.activeL1Id)??null,c=i?.pathname===a.pathname?i:null;return(0,G.jsxs)(tB,{children:[(0,G.jsx)(nB,{children:(0,G.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,G.jsxs)(rB,{children:[(()=>{if(c||!s)return null;if(s.panel){let e=s.panel;return(0,G.jsx)(`div`,{className:`border-b border-border/40 pb-2 mb-2`,children:(0,G.jsx)(e,{item:s,navState:n,dispatch:r})})}return s.children&&s.children.length>0?(0,G.jsx)(`div`,{className:`border-b border-border/40 pb-2 mb-2`,children:(0,G.jsx)(qW,{items:s.children})}):null})(),c?(0,G.jsx)(`div`,{className:`pt-1`,children:(0,G.jsx)(UW,{entries:c.spec})}):o.length>0&&(0,G.jsx)(`div`,{className:`pt-1`,children:(0,G.jsx)(UW,{entries:o})})]})]})}var YW=`0.59.2236`,XW=`https://github.com/bitcobblers/wod-wiki/releases`;function ZW(e){return/-pr\.\d+$/.test(e)?XW:`${XW}/tag/v${e}`}function QW({onSearch:e,onCreate:t}){let{tree:n,navState:r,dispatch:i}=SR(),a=lt(),o=z(),s=Yz(),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`);o.pathname===`/`||o.pathname;let d=`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,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:()=>{s(),a(`/`)},title:`Wod Wiki home`,"aria-label":`Wod Wiki home`,"data-testid":$.NAV_L1_HOME,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,G.jsx)(ot,{size:17}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Wod Wiki home`}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:`Wod Wiki home`})]}),(0,G.jsx)(`nav`,{"aria-label":`Primary`,className:`flex flex-col items-center gap-1.5`,children:l.map(e=>{let t=e.icon,n=KW(e,r,o);return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{s(),i({type:`SET_ACTIVE_L1`,id:e.id}),aH(e.action,c)},title:e.label,"aria-label":e.label,"aria-current":n?`page`:void 0,"data-testid":`nav-l1-${e.id}`,className:K(`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,G.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,G.jsx)(t,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:e.label}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:e.label})]},e.id)})}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`button`,{type:`button`,onClick:e,title:`Search (⌘/)`,"aria-label":`Search`,"data-testid":$.NAV_L1_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,G.jsx)(An,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Search`}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:`Search (⌘/)`})]}),(0,G.jsxs)(`a`,{href:gU,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,G.jsx)(_U,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Buy Me a Coffee`}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:`Buy Me a Coffee`})]}),(0,G.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:K(`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,G.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,G.jsx)(tr,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Profile`}),(0,G.jsx)(`span`,{role:`tooltip`,className:d,children:`Profile`})]}),(0,G.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:K(`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,G.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,G.jsx)(N,{className:`size-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Settings`}),(0,G.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`,YW,`)`]})]})]})}function $W({activations:e,activeSection:t,variant:n,deps:r,className:i}){return(0,G.jsx)(`nav`,{className:K(`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,G.jsx)(`button`,{onClick:()=>aH(e.action,r),className:K(`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 eG=class e{now;name=`tick`;timestamp;data;static _counter=0;constructor(t,n=gu){this.now=n;let r=this.now.nowMs();e._counter++,this.timestamp=new Date(r+e._counter),this.data=t}},tG=20,nG=e=>{let[t,n]=(0,W.useState)(`idle`),[r,i]=(0,W.useState)(0),[a,o]=(0,W.useState)(0),[s,c]=(0,W.useState)(null),l=(0,W.useRef)(null),u=(0,W.useRef)(null),d=(0,W.useCallback)(()=>{if(l.current&&=(clearInterval(l.current),null),u.current!==null){let t=e?.nowProvider?.nowMs()??gu.nowMs();i(t-u.current)}n(`idle`)},[e]),f=(0,W.useCallback)(()=>{if(e)try{let t=new eG(void 0,e.nowProvider);e.handle(t),o(e=>e+1)}catch{d(),n(`error`)}},[e,d]);(0,W.useEffect)(()=>{if(e)return e.subscribeToStack(r=>{if(r.blocks.length===0&&t!==`completed`){if(l.current&&=(clearInterval(l.current),null),u.current!==null){let t=e?.nowProvider?.nowMs()??gu.nowMs();i(t-u.current)}n(`completed`)}})},[e,t]),(0,W.useEffect)(()=>()=>{l.current&&=(clearInterval(l.current),null)},[]);let p=(0,W.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()??gu.nowMs();u.current=i-r,r===0&&c(i),l.current=setInterval(f,tG)},[e,t,r,f]),m=(0,W.useCallback)(()=>{if(l.current&&=(clearInterval(l.current),null),u.current!==null){let t=e?.nowProvider?.nowMs()??gu.nowMs();i(t-u.current)}if(e){let t=e.nowProvider?.now()??gu.now();e.handle({name:`timer:pause`,timestamp:t,data:{}})}n(`paused`)},[e]),h=(0,W.useCallback)(()=>{l.current&&=(clearInterval(l.current),null),i(0),o(0),n(`idle`),c(null),u.current=null},[e]),g=(0,W.useCallback)(()=>{!e||t===`running`||(n(`paused`),f())},[e,t,f]);return(0,W.useEffect)(()=>{if(t!==`running`||!u.current)return;let n=setInterval(()=>{i((e?.nowProvider?.nowMs()??gu.nowMs())-u.current)},100);return()=>clearInterval(n)},[t,e?.nowProvider]),(0,W.useEffect)(()=>()=>{l.current&&=(clearInterval(l.current),null)},[]),(0,W.useEffect)(()=>{h()},[e,h]),(0,W.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])};function rG(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,W.useState)(r);return(0,W.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 iG(e){return rG(e,`round`)}function aG(e){return rG(e,`display`)}function oG(e){let t=iG(e),n=aG(e);return(0,W.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 sG=(0,W.createContext)(void 0),cG=({runtime:e,children:t})=>(0,G.jsx)(sG.Provider,{value:e,children:t});function lG(){let e=(0,W.useContext)(sG);if(!e)throw Error(`useScriptRuntime must be used within ScriptRuntimeProvider`);return e}function uG(){return(0,W.useContext)(sG)??null}function dG(e){let t=lG(),n=e===void 0?t:e,[r,i]=(0,W.useState)(()=>n?.getOutputStatements?.()??[]);return(0,W.useEffect)(()=>{if(!n){i([]);return}return i(n.getOutputStatements()),n.subscribeToOutput?.(()=>{i(n.getOutputStatements())})},[n]),(0,W.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 fG(){let e=lG(),[t,n]=(0,W.useState)({type:`initial`,blocks:e.stack.blocks,depth:e.stack.count,clockTime:e.clock.currentDate});return(0,W.useEffect)(()=>e.subscribeToStack(e=>{n(e)}),[e]),t}function pG(){return fG().blocks}function mG(){let e=pG(),[t,n]=(0,W.useState)(0);return(0,W.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,W.useMemo)(()=>{for(let t of e){let e=t.getMemoryByTag(`metric:next`);if(e.length===0)continue;let n=La.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 hG(){let e=pG(),[t,n]=(0,W.useState)(0);return(0,W.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,W.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 gG(){let e=pG(),[t,n]=(0,W.useState)(0);return(0,W.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,W.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 _G(e){let t=lG(),n=(0,W.useMemo)(()=>t.stack.blocks.find(t=>t.key.toString()===e),[t,e]),[r,i]=(0,W.useState)(()=>n?.getMemoryByTag(`time`)[0]?.metrics[0]?.value);(0,W.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,W.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,W.useMemo)(()=>r?.spans??[],[r]),o=a.length>0&&a[a.length-1].ended===void 0,[s,c]=(0,W.useState)(Qu()),l=(0,W.useMemo)(()=>a.length===0?0:Xp(a,s),[a,s]);return(0,W.useEffect)(()=>{if(!o)return;let e,t=()=>{c(Qu()),e=requestAnimationFrame(t)};return t(),()=>cancelAnimationFrame(e)},[o]),{elapsed:l,isRunning:o,timeSpans:a}}function vG(e={}){let t=uG(),n=e.runtime===void 0?t:e.runtime,r=e.active??!0,[i,a]=(0,W.useState)({revision:0,skipFlash:!1,skipFlashKey:0});(0,W.useEffect)(()=>{if(!(!n||!r))return nm(n,({skipFlash:e,skipFlashKey:t})=>{a(n=>({revision:n.revision+1,skipFlash:e,skipFlashKey:t}))})},[n,r]);let[o,s]=(0,W.useState)(()=>Qu()),c=(0,W.useMemo)(()=>(i.revision,om(n,{nowMs:o,executionStatus:e.executionStatus,canNextOverride:e.canNextOverride,skipFlash:i.skipFlash,skipFlashKey:i.skipFlashKey})),[n,i.revision,i.skipFlash,i.skipFlashKey,o,e.executionStatus,e.canNextOverride]);return(0,W.useEffect)(()=>{if(!r||!c.isRunning||c.isPaused||typeof requestAnimationFrame!=`function`)return;let e=0,t=!0,n=()=>{t&&(s(Qu()),e=requestAnimationFrame(n))};return e=requestAnimationFrame(n),()=>{t=!1,cancelAnimationFrame(e)}},[r,c.isRunning,c.isPaused]),c}function yG(e){let t=uG(),n=e===void 0?t:e,[r,i]=(0,W.useState)(0);return(0,W.useEffect)(()=>{if(!n){i(0);return}return n.subscribeToOutput?.(()=>{i(e=>e+1)})},[n]),(0,W.useMemo)(()=>pm(n),[n,r])}function bG(e){let t=uG(),n=e===void 0?t:e,[r,i]=(0,W.useState)(0);return(0,W.useEffect)(()=>{if(!n)return;let e=n.subscribeToStack(()=>i(e=>e+1)),t=n.subscribeToOutput?.(()=>i(e=>e+1));return()=>{e(),t?.()}},[n]),(0,W.useMemo)(()=>gm(n),[n,r])}var xG=(0,W.createContext)(void 0),SG=(0,W.createContext)(null),CG=({factory:e,children:t})=>{let[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(null),u=(0,W.useRef)(e);u.current=e;let d=(0,W.useRef)(null),f=(0,W.useRef)(null),p=(0,W.useRef)(!1),m=(0,W.useCallback)(()=>{f.current&&=(f.current.dispose(),null),a(null),vF.getState().setSubscriptionManager(null),vF.getState().setRuntime(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,W.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 Yp(i);e.add(new Jp({id:`local`})),f.current=e,a(e),vF.getState().setRuntime(i),vF.getState().setSubscriptionManager(e)}else f.current=null,a(null),vF.getState().setRuntime(null),vF.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,W.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,G.jsx)(xG.Provider,{value:g,children:(0,G.jsx)(SG.Provider,{value:i,children:t})})};function wG({factory:e,children:t}){return(0,G.jsx)(CG,{factory:e,children:t})}var TG=`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`,EG=`flex flex-col flex-1 min-w-0 xl:max-w-[984px] 2xl:max-w-none min-h-screen lg:rounded-[2.5rem]`,DG=(0,W.createContext)(null);function OG({value:e,children:t}){return(0,G.jsx)(DG.Provider,{value:e,children:t})}function kG(){let e=(0,W.useContext)(DG),{dispatch:t,streamControls:n,analyticsControls:r,l3Items:i,l3Actions:a=[],secondarySpec:o}=SR(),s=(0,W.useMemo)(()=>{let e=Y(n?.query??``);return!e.error&&Th(e)&&e.filters.length>0},[n?.query]);return e||{railHasContent:!!(o&&o.length>0||i&&i.length>0||a&&a.length>0||n||r),hasAppliedFilters:s,openRightDrawer:()=>t({type:`SET_RIGHT_DRAWER`,open:!0})}}function AG(){let{railHasContent:e,hasAppliedFilters:t,openRightDrawer:n}=kG();return e?(0,G.jsxs)(q,{type:`button`,variant:`ghost`,size:`icon`,onClick:n,"aria-label":`Page options`,title:`Page options (⌘.)`,"data-testid":`l3-drawer-trigger`,className:`relative hidden lg:inline-flex 2xl:hidden text-muted-foreground hover:text-foreground`,children:[(0,G.jsx)(Nn,{className:`size-4`,"aria-hidden":`true`}),t&&(0,G.jsx)(`span`,{"data-testid":`header-filters-active`,className:`absolute top-1.5 right-1.5 size-2 rounded-full bg-amber-500`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Page options`})]}):null}function jG({id:e,title:t,subtitle:n,titleAccessory:r,actions:i,queryBar:a,subheader:o,titleTestId:s,className:c}){let{railHasContent:l}=kG(),u=!!(i||l);return(0,G.jsxs)(`div`,{id:e,"data-page-sticky-boundary":`true`,className:K(`max-lg:hidden lg:sticky lg:top-0 z-30 border-b border-border/50 bg-background/95 backdrop-blur-md transition-colors`,c),children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-2.5 sm:gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`h-5 w-1.5 shrink-0 rounded-full bg-primary`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h1`,{"data-testid":s,className:`text-base sm:text-lg font-black tracking-tight text-foreground leading-none truncate`,children:t}),n&&(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground truncate`,children:n})]}),r]})]}),a&&(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:a}),u&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0 ml-auto`,children:[i,(0,G.jsx)(AG,{})]})]}),o&&(0,G.jsx)(`div`,{className:`bg-background/40`,children:o})]})}function MG({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,W.useRef)(``),u=(0,W.useRef)(i),d=(0,W.useRef)(a),f=(0,W.useRef)(null),p=(0,W.useRef)(1);(0,W.useEffect)(()=>{u.current=i},[i]),(0,W.useEffect)(()=>{d.current=a},[a]);let m=e.filter(Boolean).join(`\0`),h=r.join(`,`),g=(0,W.useMemo)(()=>m?m.split(`\0`):[],[m]),_=(0,W.useMemo)(()=>h.split(`,`).map(Number),[h]),v=(0,W.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null)},[]);(0,W.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 NG({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]=ie(`s`,{defaultValue:o??a[0]?.id??``,shallow:!0,history:`replace`}),[f,p]=(0,W.useState)(c?.[0]?.id??``);if(MG({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}),MG({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,G.jsxs)(`div`,{className:K(`flex flex-col min-h-screen bg-background`,l),children:[s,(0,G.jsx)($W,{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,G.jsx)(`div`,{className:`flex-1`,children:c.map(e=>{let t=(0,G.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,G.jsx)(wG,{factory:e.runtimeFactory,children:t},e.id):t})})]})}return(0,G.jsx)(`div`,{className:K(`relative flex w-full min-h-screen justify-start items-start`,l),children:(0,G.jsxs)(`div`,{className:K(EG,TG),children:[(0,G.jsx)(jG,{title:e,titleAccessory:t,actions:n,subheader:r}),(0,G.jsx)(`div`,{className:`flex-1`,children:i})]})})}var PG=`[data-page-sticky-boundary="true"]`,FG=0;function IG(e,t=FG){if(typeof document>`u`)return e;let n=Array.from(document.querySelectorAll(PG)).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 LG(e,t=FG){let[n,r]=(0,W.useState)(e);return(0,W.useEffect)(()=>{let n=0,i=()=>r(IG(e,t)),a=()=>{cancelAnimationFrame(n),n=requestAnimationFrame(i)};i(),window.addEventListener(`scroll`,a,{passive:!0}),window.addEventListener(`resize`,i);let o=typeof ResizeObserver>`u`?void 0:new ResizeObserver(i);document.querySelectorAll(PG).forEach(e=>o?.observe(e));let s=typeof MutationObserver>`u`?void 0:new MutationObserver(()=>{document.querySelectorAll(PG).forEach(e=>o?.observe(e)),i()});return typeof document<`u`&&document.body&&s?.observe(document.body,{childList:!0,subtree:!0}),()=>{s?.disconnect(),o?.disconnect(),cancelAnimationFrame(n),window.removeEventListener(`scroll`,a),window.removeEventListener(`resize`,i)}},[e,t]),n}function RG({top:e,label:t,icon:n,badge:r,meta:i,testId:a,className:o}){return(0,G.jsxs)(`div`,{"data-testid":a,className:K(`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,G.jsx)(`span`,{className:`min-w-0 truncate text-xs font-bold text-foreground`,children:t}),r,i&&(0,G.jsx)(`span`,{className:`ml-auto shrink-0 pl-2 font-mono text-[10px] text-muted-foreground`,children:i})]})}var zG=(0,W.createContext)(null),BG=(0,W.createContext)(null);function VG({children:e}){let[t,n]=(0,W.useState)(null);return(0,G.jsx)(BG.Provider,{value:n,children:(0,G.jsx)(zG.Provider,{value:t,children:e})})}function HG({className:e}){let t=(0,W.useContext)(BG);return(0,G.jsx)(`div`,{ref:t,className:e,"data-testid":`mobile-query-slot`})}function UG(){return(0,W.useContext)(zG)}function WG({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,G.jsxs)(`div`,{className:K(`relative flex w-full min-h-screen justify-start items-start`,d),children:[(0,G.jsxs)(`div`,{className:K(EG,TG),children:[(0,G.jsx)(jG,{title:t,subtitle:n,titleTestId:r,actions:i}),(0,G.jsx)(`main`,{className:`flex-1 min-w-0 max-w-full`,children:e})]}),s&&a&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/95 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,G.jsx)(`div`,{className:`flex justify-end p-4`,children:(0,G.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,G.jsx)(`div`,{className:`flex-1 min-h-0`,children:a})]})}),c&&o&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/95 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,G.jsx)(`div`,{className:`flex justify-end p-4`,children:(0,G.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,G.jsx)(`div`,{className:`flex-1 min-h-0`,children:o})]})})]})}function GG(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 KG=W.createContext(null);function qG(){let e=W.useContext(KG);if(!e)throw Error(`DropdownMenu components must be used inside a DropdownMenu`);return e}function JG(){let e=W.useContext(KG);return W.useCallback(()=>{e?.setIsOpen(!1)},[e])}var YG=({children:e,open:t,onOpenChange:n})=>{let r=W.useContext(KG),i=W.useId(),a=r?`${r.portalChain}/${i}`:i,[o,s]=W.useState(t??!1),c=W.useRef(null),[l,u]=W.useState(-1),d=W.useRef(new Map),[,f]=W.useReducer(e=>e+1,0);W.useEffect(()=>{t!==void 0&&s(t)},[t]);let p=W.useCallback(e=>{s(e),u(-1),n?.(e)},[n]),m=W.useCallback((e,t)=>{d.current.set(e,t),f()},[]),h=W.useCallback(e=>{d.current.delete(e),f()},[]),g=W.useCallback(e=>Array.from(d.current.keys()).indexOf(e),[]),_=d.current.size,v=W.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,G.jsx)(KG.Provider,{value:v,children:(0,G.jsx)(`div`,{ref:c,className:`relative inline-block`,children:e})})},XG=W.forwardRef(({className:e,children:t,asChild:n,...r},i)=>{let{isOpen:a,setIsOpen:o}=qG(),s=e=>{e.stopPropagation(),o(!a)};return n&&W.isValidElement(t)?W.cloneElement(t,{...r,onClick:s}):(0,G.jsx)(`button`,{ref:i,className:e,onClick:s,...r,children:t})});XG.displayName=`DropdownMenuTrigger`;var ZG=W.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}=qG(),p=W.useRef(null),m=a||p,[h,g]=W.useState({top:0,bottom:0,left:0,width:0}),_=r===`bottom`,[v,y]=W.useState(!1);W.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]),W.useLayoutEffect(()=>{if(!o||!_||!m.current)return;let e=m.current.getBoundingClientRect();y(h.top+e.height>window.innerHeight)},[o,_,h.top,m]),W.useEffect(()=>{if(!o||u===0)return;let e=setTimeout(()=>{l(0)},0);return()=>clearTimeout(e)},[o,u,l]),W.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%)`),cE.createPortal((0,G.jsx)(`div`,{ref:m,role:`menu`,"data-dropdown-chain":f,className:K(`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)});ZG.displayName=`DropdownMenuContent`;var QG=W.forwardRef(({className:e,disabled:t,inset:n,onClick:r,onKeyDown:i,...a},o)=>{let{setIsOpen:s,registerItem:c,unregisterItem:l,getItemIndex:u,activeIndex:d}=qG(),f=W.useId(),p=W.useRef(null),m=W.useCallback(e=>{p.current=e,typeof o==`function`?o(e):o&&(o.current=e)},[o]);W.useEffect(()=>(c(f,p),()=>l(f)),[f,c,l]);let h=u(f)===d;return W.useEffect(()=>{h&&p.current?.focus()},[h]),(0,G.jsx)(`div`,{ref:m,role:`menuitem`,tabIndex:t?-1:h?0:-1,"aria-disabled":t,"data-active":h?`true`:void 0,className:K(`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})});QG.displayName=`DropdownMenuItem`;var $G=W.forwardRef(({className:e,inset:t,...n},r)=>(0,G.jsx)(`div`,{ref:r,className:K(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));$G.displayName=`DropdownMenuLabel`;var eK=W.forwardRef(({className:e,...t},n)=>(0,G.jsx)(`div`,{ref:n,className:K(`-mx-1 my-1 h-px bg-muted`,e),...t}));eK.displayName=`DropdownMenuSeparator`;var tK=[{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`}],nK=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function rK(e,t){return new Date(e,t+1,0).getDate()}function iK(e,t){let n=new Date(e,t,1).getDay();return n===0?6:n-1}function aK(e,t){let n=Y(e);if(n.error)return e;if(!t||t===`all`)return yg({...n,window:void 0});let r=Y(`:note ${t}`);return r.error||r.family!==`find`||!r.window?e:yg({...n,window:r.window})}function oK(e){let t=Y(e);return t.error||t.family===`pipeline`?null:`window`in t?t.window??null:null}function sK({query:e,onQueryChange:t,highlightDates:n=new Set,className:r}){let i=(0,W.useMemo)(()=>oK(e),[e]),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(()=>new Date),l=s.getFullYear(),u=s.getMonth(),d=(0,W.useMemo)(()=>i?i.kind===`relative`?`last ${i.size}${i.unit}`:i.kind===`param`?`last $${i.param}${i.unit?` ${i.unit}`:``}`:i.end?`from ${i.start} to ${i.end}`:`from ${i.start}`:`All time`,[i]),f=(0,W.useMemo)(()=>{if(!i||i.kind===`param`)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:Iz(t),end:Iz(e)}},[i]),p=(0,W.useMemo)(()=>{let e=rK(l,u),t=iK(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(aK(e,`from ${n} to ${n}`));else{let[r,i]=a<=n?[a,n]:[n,a];o(null),t(aK(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=Iz(new Date);return(0,G.jsxs)(`div`,{className:K(`relative inline-flex items-center`,r),children:[(0,G.jsxs)(YG,{children:[(0,G.jsx)(XG,{asChild:!0,children:(0,G.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,G.jsx)(jt,{className:`size-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`font-mono text-xs`,children:d}),(0,G.jsx)(dt,{className:`size-3 text-muted-foreground`,"aria-hidden":`true`})]})}),(0,G.jsxs)(ZG,{align:`end`,className:`w-72 p-3`,children:[(0,G.jsx)(`div`,{className:`mb-3 flex flex-wrap gap-1 border-b border-border/60 pb-2`,children:tK.map(n=>{let r=n.value===`all`?!i:i?.kind===`relative`&&`last ${i.size}${i.unit}`===n.value;return(0,G.jsx)(`button`,{type:`button`,"data-testid":`wql-window-preset-${n.value}`,onClick:()=>{o(null),t(aK(e,n.value))},className:K(`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,G.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,G.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,G.jsx)(V,{className:`size-4`})}),(0,G.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:_}),(0,G.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,G.jsx)(gt,{className:`size-4`})})]}),(0,G.jsx)(`div`,{className:`mb-1 grid grid-cols-7 gap-1`,children:nK.map(e=>(0,G.jsx)(`div`,{className:`text-center text-[10px] font-medium text-muted-foreground`,children:e},e))}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,"data-testid":`wql-calendar-grid`,children:p.map((e,t)=>{if(e===null)return(0,G.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,G.jsxs)(`button`,{type:`button`,"data-testid":`wql-calendar-day-${r}`,onClick:()=>m(r),className:K(`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,G.jsx)(`span`,{children:e}),d&&!o&&!s&&(0,G.jsx)(`span`,{className:`absolute bottom-0.5 size-1 rounded-full bg-primary`})]},r)})}),a&&(0,G.jsxs)(`div`,{className:`mt-2 text-center text-[10px] text-muted-foreground`,children:[`Select second date to complete range (starting from `,a,`)`]})]})]}),i&&(0,G.jsx)(`button`,{type:`button`,"data-testid":`wql-window-picker-clear`,onClick:()=>{o(null),t(aK(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,G.jsx)(Bn,{className:`size-3.5`})})]})}function cK({onOpen:e}){let t=JG(),n=Yz();return(0,G.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{t(),n(),e()},"data-testid":`query-settings-trigger`,className:`w-full justify-start gap-2 rounded-lg text-xs`,children:[(0,G.jsx)(Nn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`truncate`,children:`Query settings`})]})}function lK(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 uK=[{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??``)}],dK={note:uK,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?``:RV(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`sessionLoad`,label:`Session Load`,level:`session`,defaultVisible:!0,align:`right`,getValue:e=>{if(e.execution?.loadLbs!=null)return`${e.execution.loadLbs.toLocaleString()} ${e.execution.volumeUnit??`lbs`}`;if(e.execution?.sessionLoadAu!=null)return`${Number.isInteger(e.execution.sessionLoadAu)?e.execution.sessionLoadAu.toLocaleString():Number(e.execution.sessionLoadAu.toFixed(1)).toLocaleString()} AU`},formatValue:e=>e==null?``:String(e)}],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?``:RV(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`totalTonnage`,label:`Total Tonnage`,level:`result`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.loadLbs==null?void 0:`${e.execution.loadLbs.toLocaleString()} ${e.execution.volumeUnit??`lbs`}`,formatValue:e=>e==null?``:String(e)},{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?``:RV(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==null?void 0:`${e.execution.loadLbs.toLocaleString()} ${e.execution.volumeUnit??`lbs`}`,formatValue:e=>e==null?``:String(e)},{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 fK(e){return dK[e]??uK}function pK(e){return fK(e).filter(e=>e.defaultVisible).map(e=>e.id)}var mK=[4,8,16],hK=`sum:totalVolume{}`;function gK(e){let t=Number.parseInt(e??``,10);return mK.includes(t)?t:16}function _K(e={}){let{defaultQuery:t=hK,runOnLanding:n=!1}=e,[r,i]=ee(),a=r.get(`q`)??``,o=gK(r.get(`weeks`)),[s,c]=(0,W.useState)(()=>a&&!Y(a).error?a:t),[l,u]=(0,W.useState)(a||(n?t:``)),d=(0,W.useRef)(s);d.current=s;let f=(0,W.useRef)(r);f.current=r;let p=(0,W.useRef)(!0),m=(0,W.useRef)(a);m.current=a;let h=(0,W.useRef)(a);(0,W.useEffect)(()=>{a!==h.current&&(h.current=a,d.current!==a&&(p.current=!0,c(a&&!Y(a).error?a:t),u(a||(n?t:``))))},[a,t,n]);let g=(0,W.useRef)(t);return(0,W.useEffect)(()=>{t!==g.current&&(g.current=t,!a&&(c(t),u(n?t:``)))},[t,a,n]),{draft:s,setDraft:(0,W.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,W.useCallback)(e=>{let t=e??d.current;if(Y(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,W.useCallback)(e=>{let t=new URLSearchParams(f.current);t.set(`weeks`,String(e)),i(t,{replace:!0})},[i])}}var vK=[{id:`cards`,label:`Cards`,icon:Zn},{id:`rows`,label:`Rows`,icon:Lr},{id:`feed`,label:`Feed`,icon:p},{id:`agenda`,label:`Agenda`,icon:It},{id:`planner`,label:`Planner`,icon:nee}];function yK({streamControls:e}){let t=e.availableLayouts;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,"data-testid":`l3-stream-controls`,children:[e.onOpenQuerySettings&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`This page`}),(0,G.jsx)(cK,{onOpen:e.onOpenQuerySettings})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Date window`}),(0,G.jsx)(sK,{query:e.query,onQueryChange:e.onQueryChange,className:`w-full justify-between`})]}),e.availableGroupDims.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Group by`}),(0,G.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,G.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,G.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>e.onToggleGroupDim(t.id),className:`size-3.5 rounded border-border accent-primary cursor-pointer`}),(0,G.jsx)(`span`,{children:t.label})]},t.id)})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Layout`}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-1`,"data-testid":`l3-layout-options`,children:vK.filter(e=>!t||t.includes(e.id)).map(t=>{let n=t.icon,r=e.settings.layout===t.id;return(0,G.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,G.jsx)(n,{"aria-hidden":!0,className:`size-3`}),t.label]},t.id)})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Fields`}),(0,G.jsx)(`div`,{className:`flex flex-col gap-0.5`,"data-testid":`l3-field-options`,children:fK(e.level).map(t=>{let n=e.settings.visibleFields.includes(t.id);return(0,G.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,G.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>e.onToggleField(t.id),className:`size-3.5 rounded border-border accent-primary cursor-pointer`}),(0,G.jsx)(`span`,{children:t.label})]},t.id)})})]}),(0,G.jsx)(BH,{})]})}function bK({controls:e}){let{unit:t,setUnit:n}=RT(),r=e.showRange!==!1,i=e.showUnits!==!1,a=e.weeks!==void 0&&e.onWeeksChange!==void 0;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,"data-testid":`l3-analytics-controls`,children:[e.onOpenQuerySettings&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`This page`}),(0,G.jsx)(cK,{onOpen:e.onOpenQuerySettings})]}),r&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Date range`}),a?(0,G.jsx)(`div`,{className:`flex flex-col gap-0.5`,"data-testid":`l3-range-options`,children:mK.map(t=>{let n=e.weeks===t;return(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":n,onClick:()=>e.onWeeksChange?.(t),"data-testid":`l3-range-${t}w`,className:K(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs transition-colors`,n?`bg-primary/10 font-semibold text-primary`:`text-foreground/80 hover:bg-muted/60 hover:text-foreground`),children:[(0,G.jsx)(`span`,{className:`w-3.5 text-primary`,children:n?(0,G.jsx)(xt,{className:`size-3.5`,"aria-hidden":`true`}):null}),(0,G.jsxs)(`span`,{children:[`Past `,t,` weeks`]})]},t)})}):(0,G.jsx)(kT,{})]}),i&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[`Units`,e.unitForced?` — pinned by query`:``]}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-1`,"data-testid":`l3-unit-options`,children:[`kg`,`lb`].map(r=>{let i=t===r;return(0,G.jsx)(`button`,{type:`button`,disabled:!!e.unitForced,"aria-pressed":i,onClick:()=>n(r),"data-testid":`l3-unit-${r}`,className:K(`flex min-h-8 items-center justify-center rounded-md border px-2 py-1 text-xs font-medium transition-colors`,e.unitForced?`border-transparent text-muted-foreground/50 cursor-not-allowed`:i?`border-border/80 bg-card text-foreground shadow-sm`:`border-transparent text-muted-foreground hover:text-foreground`),children:r},r)})})]})]})}function xK({action:e}){let t=Yz(),n=e.icon;return(0,G.jsxs)(`button`,{type:`button`,disabled:e.disabled,"data-testid":e.testId,onClick:()=>{e.disabled||(t(),e.onRun())},className:K(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[13px] transition-colors`,e.disabled?`cursor-not-allowed text-muted-foreground/45`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[n&&(0,G.jsx)(n,{className:`size-4 shrink-0`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.label,children:e.label})]})}function SK({spec:e,pageAction:t}){let{l3Items:n,l3Actions:r=[],streamControls:i,analyticsControls:a}=SR(),o=BW(e),s=(0,W.useMemo)(()=>GG(n),[n]),c=VW(),l=!!(i||a),u=o.length>0||s.length>0,d=r.length>0||!!t;return!l&&!u&&!d?null:(0,G.jsxs)(`div`,{className:`flex flex-col px-3 py-4 gap-4`,children:[l&&(0,G.jsxs)(`div`,{className:K(`flex flex-col gap-4`,(u||d)&&`pb-3 border-b border-border/50`),children:[i&&(0,G.jsx)(yK,{streamControls:i}),a&&(0,G.jsx)(bK,{controls:a})]}),o.length>0&&(0,G.jsx)(UW,{entries:o,activeId:c}),s.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-col`,children:[(0,G.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,G.jsx)(UW,{entries:s,activeId:c})]}),d&&(0,G.jsxs)(`div`,{"data-testid":`l3-actions`,className:K(`flex flex-col gap-0.5`,u&&`pt-2 border-t border-border/50`),children:[(0,G.jsx)(`div`,{className:`px-2 pb-1 pt-1 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Actions`}),r.map(e=>(0,G.jsx)(xK,{action:e},e.id)),t&&(0,G.jsx)(`div`,{className:K(r.length>0&&`pt-1`),children:t})]})]})}var CK=1023;function wK(e){return e===`/`?`canvas:home`:`canvas:${e.replace(/^\//,``)}`}function TK(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);if(r===null)return null;let i=t[r],{meta:a,body:o}=Oo(i),s=new Set([`search`,`template`,`route`,`type`,`title`,`description`,`subtitle`,`section`,`order`]);return Object.keys(a).some(e=>!s.has(e.trim().toLowerCase()))?i:o};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 EK(e){return(e.examples??[]).length>0||e.commands.some(e=>e.pipeline.length>0)}function DK(e){let t=new Map,n=null;for(let r of e)EK(r)&&(n=r),t.set(r.id,n);return t}function OK(){let[e,t]=(0,W.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: ${CK}px)`).matches);return(0,W.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(max-width: ${CK}px)`),n=e=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}var kK=`wodwiki:fabAlignment`,AK=[{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 jK(){try{return MK(localStorage.getItem(kK))}catch{return}}function MK(e){return e===`right`||e===`left`?e:void 0}var NK=typeof window>`u`?void 0:jK();typeof window<`u`&&window.addEventListener(`storage`,e=>{e.key===kK&&(NK=MK(e.newValue))});function PK(e){NK=e;try{e===`right`?localStorage.removeItem(kK):localStorage.setItem(kK,e)}catch{}window.dispatchEvent(new StorageEvent(`storage`,{key:kK,newValue:e}))}function FK(){let[e,t]=(0,W.useState)(()=>NK??`right`);return(0,W.useEffect)(()=>{let e=e=>{e.key===kK&&t(MK(e.newValue)??`right`)};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),[e,PK]}function IK({onOpen:e}){return(0,G.jsxs)(`button`,{type:`button`,onClick:e,"aria-label":`Search`,title:`Search`,"data-testid":`search-fab`,className:K(`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,G.jsx)(An,{className:`size-6`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Search`})]})}var LK=(0,W.createContext)(null),RK=(0,W.createContext)(!1),zK=(0,W.createContext)(null);function BK(){return(0,W.useContext)(LK)!==null}function VK({primary:e,navbar:t,children:n,label:r,fallback:i=!1}){let a=(0,W.useContext)(LK),o=(0,W.useContext)(RK),s=OK(),c=(0,W.useId)(),l=a!==null&&!o&&s&&!i,u=a!==null&&i,d=W.Children.toArray(n).length>0,f=(0,W.useMemo)(()=>(0,G.jsx)(RK.Provider,{value:!0,children:n}),[n]),p=l||u,m=(0,W.useRef)(null);return m.current={id:c,primary:e,navbar:t,children:f,hasContent:d,label:r??`Page options`,fallback:i},(0,W.useEffect)(()=>{if(p)return a.register(m.current),()=>a.unregister(c)},[p,a,c]),(0,W.useEffect)(()=>{p&&a.register(m.current)},[p,a,e,t,f,d,r,i]),i||a&&s&&!o?null:(0,G.jsx)(RK.Provider,{value:!0,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t,e,n]})})}function HK({onSearch:e,children:t}){let[n,r]=(0,W.useState)([]),i=(0,W.useCallback)(e=>r(t=>{let n=t.findIndex(t=>t.id===e.id);if(n===-1)return[...t,e];let r=t[n];if(r.primary===e.primary&&r.navbar===e.navbar&&r.children===e.children&&r.hasContent===e.hasContent&&r.label===e.label&&r.fallback===e.fallback)return t;let i=[...t];return i[n]=e,i}),[]),a=(0,W.useCallback)(e=>r(t=>t.filter(t=>t.id!==e)),[]),o=(0,W.useMemo)(()=>({register:i,unregister:a}),[i,a]),s=(0,W.useMemo)(()=>{for(let e=n.length-1;e>=0;--e)if(!n[e].fallback)return n[e].navbar??null;return null},[n]);return(0,G.jsx)(LK.Provider,{value:o,children:(0,G.jsxs)(zK.Provider,{value:s,children:[t,(0,G.jsx)(WK,{registrations:n,onSearch:e})]})})}function UK(){let e=(0,W.useContext)(zK);return e?(0,G.jsx)(G.Fragment,{children:e}):null}function WK({registrations:e,onSearch:t}){let n=OK(),[r]=FK(),i=uE(),[a,o]=(0,W.useState)(!1),s=(0,W.useCallback)(()=>o(!1),[]),c=(0,W.useRef)(null),l=(0,W.useRef)(null),u=(0,W.useRef)(null),d=(0,W.useMemo)(()=>{for(let t=e.length-1;t>=0;--t)if(!e[t].fallback)return e[t]},[e]),f=(0,W.useMemo)(()=>{for(let t=e.length-1;t>=0;--t)if(e[t].fallback)return e[t]},[e]);(0,W.useLayoutEffect)(()=>{a&&c.current?.focus({preventScroll:!0})},[a]);let p=!!(d?.hasContent||f?.hasContent);return!n||!t&&!d&&!f?null:(0,G.jsxs)(`div`,{"data-testid":`actions-dock`,className:K(`lg:hidden relative z-40 mt-4 flex flex-col items-center gap-2`,`transition-[transform,visibility] duration-200 ease-out`,r===`left`?`self-start items-start`:`self-end items-end`),children:[(0,G.jsxs)(`div`,{className:`relative z-40 flex flex-col items-center gap-2`,children:[t&&(0,G.jsx)(IK,{onOpen:()=>{o(!1),t()}}),d?.primary&&(0,G.jsx)(`div`,{className:`[&_button]:min-h-11 [&_button]:min-w-11`,children:d.primary})]}),a&&p&&(0,G.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-hidden":`true`,className:`fixed inset-0 z-30 cursor-default`,onClick:()=>o(!1)}),(0,G.jsx)(`div`,{ref:c,role:`dialog`,"aria-label":d?.label??f?.label??`Page options`,tabIndex:-1,hidden:!a||!p,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),o(!1))},className:K(a&&p?`flex`:`hidden`,`relative z-40 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,G.jsxs)(Jz,{close:s,children:[(0,G.jsx)(`div`,{ref:l,className:`contents`,children:d?.children}),d?.children&&f?.children&&(0,G.jsx)(`div`,{className:`my-1 border-t border-border/60`,"aria-hidden":`true`}),(0,G.jsx)(`div`,{ref:u,className:`contents`,children:f?.children})]})}),p&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":d?.label??f?.label??`Page options`,title:d?.label??f?.label??`Page options`,"aria-expanded":a,"data-testid":`actions-overflow`,className:K(`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,G.jsx)(le,{className:`size-6`}):(0,G.jsx)(Qn,{className:`size-6`}),(0,G.jsx)(`span`,{className:`sr-only`,children:d?.label??f?.label??`Page options`})]})]})}var GK=null,KK=new Set;function qK(e){GK=e;for(let e of KK)e();return()=>{if(GK===e){GK=null;for(let e of KK)e()}}}function JK(){return GK}function YK(e){return KK.add(e),()=>{KK.delete(e)}}function XK(){return(0,W.useSyncExternalStore)(YK,JK,()=>null)}var ZK=null,QK=new Set;function $K(e){ZK=e;for(let e of QK)e();return()=>{if(ZK===e){ZK=null;for(let e of QK)e()}}}function eq(){return ZK}function tq(e){return QK.add(e),()=>{QK.delete(e)}}function nq(){return(0,W.useSyncExternalStore)(tq,eq,()=>null)}var rq=null,iq=new Set;function aq(e){rq=e;for(let e of iq)e();return()=>{if(rq===e){rq=null;for(let e of iq)e()}}}function oq(){return rq}function sq(e){return iq.add(e),()=>{iq.delete(e)}}function cq(){return(0,W.useSyncExternalStore)(sq,oq,()=>null)}var lq=0,uq=new Set;function dq(e){if(!e)return()=>{};lq+=1;for(let e of uq)e();let t=!1;return()=>{if(!t){t=!0,lq=Math.max(0,lq-1);for(let e of uq)e()}}}function fq(){return lq>0}function pq(e){return uq.add(e),()=>{uq.delete(e)}}function mq(){return(0,W.useSyncExternalStore)(pq,fq,()=>!1)}function hq(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 gq(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}var _q=[`samples-movement`,`samples-results`],vq=`wodwiki.seedSubscriptions`,yq=`wodwiki.seedAutoSync`;function bq(e){try{let t=typeof localStorage<`u`?localStorage.getItem(e):null;if(!t)return new Set;let n=JSON.parse(t);return!n||typeof n!=`object`||Array.isArray(n)?new Set:new Set(Object.keys(n))}catch{return new Set}}function xq(e){let t=new Set(e.map(e=>e.id)),n=bq(vq),r=bq(yq),i=[];for(let e of _q)t.has(e)&&(n.has(e)||(mI(e,!0),i.push(e)),r.has(e)||xI(e,!0));return i}var Sq=`idle`,Cq=null,wq=!1,Tq=!1,Eq=new Set,Dq=null,Oq=null;function kq(){for(let e of Eq)e()}function Aq(e){typeof document>`u`||(document.documentElement.dataset.feedState=e)}function jq(e){typeof document>`u`||(e===null?delete document.documentElement.dataset.feedOutcome:document.documentElement.dataset.feedOutcome=e)}function Mq(e){typeof document>`u`||(e?document.documentElement.dataset.feedImportPending=`true`:delete document.documentElement.dataset.feedImportPending)}Aq(Sq);function Nq(e){Sq!==e&&(Sq=e,Aq(e),kq())}function Pq(e){wq!==e&&(wq=e,Mq(e),kq())}function Fq(){Dq&&=(clearTimeout(Dq),null),Oq&&=(Oq.close(),null)}function Iq(e){Cq=e,kq()}function Lq(){Fq(),jq(null);let e=Cq!==null,t=!wq;if(Cq=null,wq=!0,Mq(!0),Sq===`preparing`){(e||t)&&kq();return}Nq(`preparing`)}function Rq(){Sq===`preparing`&&Nq(`ready`)}function zq(e){switch(jq(e),e){case`busy`:if(Sq!==`preparing`&&!wq)return;typeof BroadcastChannel<`u`&&!Oq&&(Oq=new BroadcastChannel(ex),Oq.onmessage=e=>{e.data?.kind===`seed-imported`&&(Fq(),Tq=!1,Pq(!1),Nq(`ready`))}),Dq=setTimeout(()=>{AL({onProgress:Iq}).then(zq)},wI);break;case`error`:Fq(),Tq||Pq(!1),Nq(`error`);break;default:Fq(),Tq||Pq(!1),Nq(`ready`)}}function Bq(){return Sq===`idle`?`ready`:Sq}function Vq(){return wq}function Hq(){return Cq}function Uq(e){return Eq.add(e),()=>Eq.delete(e)}function Wq(){return(0,W.useSyncExternalStore)(Uq,Bq)}function Gq(){return(0,W.useSyncExternalStore)(Uq,Vq)}function Kq(){return(0,W.useSyncExternalStore)(Uq,Hq)}var qq=null;function Jq(e={}){return Pw(`feedStart`),(e.isEnabled??uL)()&&Pq(!0),qq??=Xq(e).finally(()=>{Pw(`feedSettled`)}),qq}async function Yq(e,t){for(let n of e)if(!(n.id===`core`||!pI(n.id)||!bI(n.id)))try{let e=await t.getSeedMeta(ix(n.id));if(!e||e.seedVersion<=0)return!0}catch{return!0}return!1}async function Xq(e){let t=t=>{Iq(t),e.onProgress?.(t)},n=e.sources??dL();await HL(e).catch(e=>console.error(`[feedSync] notebook vocabulary migration failed`,e)),await BL(e).catch(e=>console.error(`[feedSync] checkpoint adoption failed`,e)),await SI(n,e.storage).catch(e=>console.error(`[feedSync] subscription migration failed`,e)),xq(n);let r=e.storage??QF(),i;try{i=await r.getSeedMeta(ix(`core`))}catch{i=void 0}let a=!i||i.seedVersion<=0;if(a?(Tq=!0,Lq()):(await Yq(n,r)&&(Tq=!0),zq(`current`)),await VL(e).catch(e=>console.error(`[feedSync] feed provenance repair failed`,e)),a){try{let r=await AL({...e,sources:n,onProgress:t,onFirstPaint:()=>Rq()});r!==`busy`&&r!==`error`&&Rq(),r!==`busy`&&r!==`error`&&n.some(e=>e.id!==`core`&&pI(e.id))&&await AL({...e,sources:n.filter(e=>e.id!==`core`),onProgress:t}).catch(e=>console.error(`[feedSync] background boot sync failed`,e)),Tq=!1,zq(r)}finally{Tq&&(Tq=!1,Pq(!1))}return}try{await AL({...e,sources:n,onProgress:t}).catch(e=>console.error(`[feedSync] background boot sync failed`,e))}finally{Tq&&(Tq=!1,Pq(!1))}}function Zq(){let[e,t]=(0,W.useState)(null);return(0,W.useEffect)(()=>{let e=!1,n=()=>{LL().then(n=>{e||t(!n.libraryImported)}).catch(()=>{e||t(!0)})};n();let r=Ew(()=>n()),i=SL(()=>n()),a=null;if(typeof BroadcastChannel<`u`)try{a=new BroadcastChannel(ex),a.onmessage=()=>n()}catch{}return()=>{e=!0,r(),i(),a?.close()}},[]),e}function Qq(){return(0,G.jsx)(`svg`,{"data-slot":`icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,className:`[&>[data-slot=icon]]:size-5`,children:(0,G.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 $q(){return(0,G.jsx)(`svg`,{"data-slot":`icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,className:`[&>[data-slot=icon]]:size-5`,children:(0,G.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 eJ(){let{tree:e,navState:t,contextNav:n}=SR(),r=z(),i=Yz();return!e.find(e=>e.id===t.activeL1Id)?.applyFooter||n?.pathname===r.pathname?null:(0,G.jsx)(`div`,{className:`shrink-0 border-t border-border/50 bg-card p-3`,children:(0,G.jsx)(`button`,{type:`button`,onClick:i,"data-testid":$.DRAWER_APPLY_BTN,className:`h-11 w-full rounded-lg bg-primary text-sm font-medium text-primary-foreground`,children:`Apply`})})}function tJ({open:e,close:t,onSearch:n,children:r}){return(0,G.jsxs)(it,{open:e,onClose:t,className:`fixed inset-0 z-50 lg:hidden`,children:[(0,G.jsx)(_,{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,G.jsx)(S,{transition:!0,"data-testid":$.MOBILE_NAV_DRAWER,className:`fixed inset-y-0 left-0 w-full transition duration-300 ease-out data-closed:-translate-x-full`,children:(0,G.jsx)(Jz,{close:t,children:(0,G.jsxs)(`div`,{className:`flex h-full min-h-0 bg-card`,children:[(0,G.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,G.jsx)(QW,{onSearch:()=>{t(),n?.()}})}),(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,G.jsx)(`div`,{className:`flex items-center px-4 pt-3`,children:(0,G.jsxs)(Mn,{as:aW,"aria-label":`Close navigation`,title:`Close navigation`,"data-testid":$.MOBILE_NAV_CLOSE,children:[(0,G.jsx)($q,{}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Close navigation`})]})}),(0,G.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:r}),(0,G.jsx)(eJ,{})]})]})})})]})}function nJ({open:e,close:t,children:n}){return(0,W.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(e.stopPropagation(),t())};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),e?(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 2xl:hidden`,"data-testid":`l3-right-drawer`,children:[(0,G.jsx)(`div`,{"aria-hidden":`true`,onClick:t,className:`fixed inset-0 bg-black/25 dark:bg-black/40 transition-opacity`}),(0,G.jsx)(`div`,{role:`region`,"aria-label":`Page options panel`,className:`fixed inset-y-0 right-0 flex h-full min-h-0 w-full lg:w-80 flex-col bg-card lg:border-l lg:border-border/60 lg:shadow-2xl animate-in slide-in-from-right duration-200`,children:(0,G.jsxs)(Jz,{close:t,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/40 px-4 py-2.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Page options`}),(0,G.jsxs)(aW,{onClick:t,"aria-label":`Close page options`,title:`Close page options`,children:[(0,G.jsx)($q,{}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Close page options`})]})]}),(0,G.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:n}),(0,G.jsx)(`div`,{className:`shrink-0 border-t border-border/50 bg-card p-3 lg:hidden`,children:(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`h-11 w-full rounded-lg bg-primary text-sm font-medium text-primary-foreground`,children:`Apply`})})]})})]}):null}function rJ({navbar:e,sidebar:t,onSearch:n,secondary:r,pageAction:i,hideDesktopSidebar:a,children:o}){let[s,c]=(0,W.useState)(!1),{navState:l,dispatch:u,streamControls:d,analyticsControls:f,l3Items:p,l3Actions:m=[]}=SR(),h=!!l?.rightDrawerOpen,g=(0,W.useCallback)(e=>u({type:`SET_RIGHT_DRAWER`,open:e}),[u]),_=(0,W.useCallback)(()=>g(!0),[g]),v=(0,W.useCallback)(()=>g(!1),[g]),y=!!(r&&r.length>0||p&&p.length>0||m&&m.length>0||d||f||i),b=(0,W.useMemo)(()=>{let e=Y(d?.query??``);return!e.error&&Th(e)&&e.filters.length>0},[d?.query]),x=(0,W.useMemo)(()=>({railHasContent:y,hasAppliedFilters:b,openRightDrawer:_}),[y,b,_]);return(0,W.useEffect)(()=>{if(!s&&!h)return;let e=()=>{c(!1),g(!1)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[s,h,g]),(0,W.useEffect)(()=>{if(!y)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`.`&&!e.shiftKey&&!e.altKey){if(window.innerWidth>=1520)return;e.preventDefault(),g(!h)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y,h,g]),(0,G.jsx)(OG,{value:x,children:(0,G.jsx)(VG,{children:(0,G.jsx)(HK,{onSearch:n,children:(0,G.jsx)(`div`,{className:`relative isolate flex min-h-svh w-full bg-background max-lg:flex-col lg:flex-row`,children:(0,G.jsxs)(`div`,{className:`flex flex-1 w-full max-lg:flex-col lg:flex-row`,children:[(0,G.jsxs)(`nav`,{"aria-label":`Main`,className:`hidden lg:flex`,children:[(0,G.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,G.jsx)(QW,{onSearch:n??(()=>{})})}),(0,G.jsx)(`div`,{className:K(`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`,a&&`lg:hidden`),children:t})]}),(0,G.jsx)(tJ,{open:s,close:()=>c(!1),onSearch:n,children:t}),(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col min-w-0 xl:max-w-[984px] 2xl:max-w-none`,children:[(0,G.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,G.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,G.jsxs)(aW,{onClick:()=>c(!0),"aria-label":`Open navigation`,title:`Open navigation`,"data-testid":$.MOBILE_NAV_OPEN,children:[(0,G.jsx)(Qq,{}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Open navigation`})]})}),(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:e}),y&&(0,G.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,G.jsxs)(aW,{onClick:_,"aria-label":`Open page options`,title:`Open page options`,children:[(0,G.jsxs)(`span`,{className:`relative inline-flex`,children:[(0,G.jsx)(Nn,{className:`size-5`}),b&&(0,G.jsx)(`span`,{"data-testid":`drawer-filters-active`,className:`absolute -top-1 -right-1 size-2 rounded-full bg-amber-500`,"aria-hidden":`true`})]}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Open page options`})]})})]}),(0,G.jsxs)(iJ,{children:[(0,G.jsx)(`div`,{className:`grow w-full max-lg:pb-48 lg:overflow-visible`,children:o}),(0,G.jsx)(aJ,{})]})]}),(0,G.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,G.jsx)(SK,{spec:r,pageAction:i})}),(0,G.jsx)(nJ,{open:h,close:v,children:(0,G.jsx)(SK,{spec:r,pageAction:i})})]})})})})})}function iJ({children:e}){let t=z(),n=mq(),r=Wq(),i=Gq(),a=Kq(),o=n||r===`preparing`||i,s=i&&r!==`preparing`&&t.pathname!==`/`,c=s?gq(a):null;return(0,G.jsxs)(`main`,{"aria-busy":o,"data-agent-status":o?`loading`:`ready`,className:`flex flex-1 flex-col lg:min-w-0`,children:[e,s&&(0,G.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`boot-import-progress`,className:`pointer-events-none fixed bottom-4 right-4 z-30 flex items-center gap-2 rounded-lg border border-border bg-card/95 px-3 py-1.5 text-xs text-foreground shadow-sm`,children:[(0,G.jsx)(`span`,{children:a?hq(a):`Importing library…`}),c&&(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:c})]})]})}function aJ(){let e=(0,W.useRef)(null),[t,n]=(0,W.useState)(0);return(0,W.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,W.useEffect)(()=>(document.documentElement.style.setProperty(`--thumb-dock-lift`,`${t}px`),()=>document.documentElement.style.setProperty(`--thumb-dock-lift`,`0px`)),[t]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:K(`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,G.jsx)(`div`,{ref:e,className:`w-full min-w-0`,children:(0,G.jsx)(HG,{className:`flex w-full min-w-0`})})}),(0,G.jsx)(`div`,{className:`lg:hidden`,"aria-hidden":`true`,style:{height:t}})]})}function oJ(e){let t=e.indexOf(`markdown`);return t!==-1&&e.length>t+2?e[t+2]:`General`}function sJ(e){return String(Mo(Oo(e).meta,`search`)??``).toLowerCase()===`hidden`}function cJ(e){let t=Mo(Oo(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 lJ(e){return Object.entries(e).map(([e,t])=>{let n=e.split(`/`),r=n[n.length-1].replace(`.md`,``),i=t,a=Mo(Oo(i).meta,`title`);return{id:e,name:r,displayName:typeof a==`string`&&a.trim()?a.trim():NM(r),category:oJ(n),content:i,date:cJ(i),searchHidden:sJ(i)}})}function uJ(){let e=nN();return(0,W.useMemo)(()=>e?lJ(e):[],[e])}var dJ={};function fJ(e,t){let{canvasPage:n,workoutItems:r,selectWorkout:i}=t;if(e===`/`)return[];if(n){let t=/^\/notebook\//.test(e),a=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=DU(e).split(`
754
754
  `),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&&a&&(o.push({id:`notebook-workouts`,label:`Explore`,type:`heading`}),r.filter(e=>e.category===a&&e.name.toLowerCase()!==`readme`).forEach(e=>{o.push({id:`workout-${e.id}`,label:e.name,type:`time`,onRun:()=>i(e),runIcon:`link`})})),o}return[]}var pJ=/^[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 mJ(e){return pJ.test(e)}function hJ(e){try{return decodeURIComponent(e)}catch{return null}}function gJ(e){if(!zz(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 _J(e){let t=(e.length>1?e.replace(/\/+$/,``):e).match(/^\/day\/([^/]+)$/);if(!t)return{kind:`invalid`};let n=hJ(t[1]);return n!=null&&gJ(n)?{kind:`date`,date:n}:{kind:`invalid`}}var vJ=`# My Workout Notebook
755
755
 
756
756
  Welcome to the **WOD.WIKI** playground.
@@ -822,8 +822,8 @@ Timer 12:00
822
822
  bg-background/70 backdrop-blur-sm border-l border-b border-border/40 rounded-bl-md`,style:{top:o,height:D},children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[h.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-0.5 rounded-sm text-[10px] font-medium bg-primary/10 text-primary border border-primary/20 shadow-sm`,children:[(0,G.jsx)(hn,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:h.length})]}),(0,G.jsx)(`div`,{className:`h-3 w-[1px] bg-border/40 mx-0.5`})]}),(0,G.jsx)(Y0,{commands:d,section:m,view:n,compact:!0})]})}),x&&(0,G.jsxs)(`div`,{className:`absolute inset-x-0 flex flex-col bg-popover/95 backdrop-blur-md
823
823
  border border-border/80 shadow-xl rounded-lg overflow-hidden pointer-events-auto`,style:{top:O,maxHeight:200},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-muted/40 border-b border-border/50 shrink-0`,children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center min-w-0 gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground/60`,children:[`L`,E]}),(0,G.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}),(0,G.jsx)(`span`,{className:`text-xs font-mono text-foreground/90 truncate font-medium`,title:T,children:T||(0,G.jsx)(`span`,{className:`italic text-muted-foreground`,children:`—`})})]})]}),(0,G.jsx)(`div`,{className:`px-3 py-2.5 min-h-0 overflow-auto`,children:C.length>0?(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map((e,t)=>(0,G.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,G.jsx)(`span`,{className:`text-base leading-none`,children:e.icon}),(0,G.jsx)(`span`,{className:`font-mono tracking-tight`,children:e.value})]},t))}):(0,G.jsx)(`span`,{className:`text-xs italic text-muted-foreground`,children:`No metrics on this line`})}),w&&(0,G.jsx)(G0,{summary:w}),(0,G.jsx)(`div`,{className:`border-t border-border/40 shrink-0`,children:(0,G.jsx)(Y0,{commands:d,section:m,view:n})})]})]})},Z0=({sectionId:e,widgetName:t,view:n,registry:r,docVersion:i})=>{let{rawContent:a,config:o}=(0,W.useMemo)(()=>{let t=n.state.field(CO).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,G.jsx)(`div`,{className:`h-full w-full overflow-hidden rounded-l-md border-l border-border bg-background shadow-sm`,children:(0,G.jsx)(s,{config:o,rawContent:a,sectionId:e})}):(0,G.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,G.jsxs)(`span`,{className:`font-mono`,children:[`widget:`,t]}),(0,G.jsx)(`span`,{className:`ml-2 opacity-60`,children:`— not registered`})]})},Q0=({title:e,onClose:t,children:n,closeButtonClassName:r,floatingClose:i=!1,variant:a=`default`,actions:o,closeLabel:s})=>{(0,W.useEffect)(()=>(document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=``}),[]);let c=W.useRef(null);(0,W.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,G.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":$.FOCUSED_DIALOG_CLOSE,children:s??(0,G.jsx)(Bn,{className:`h-5 w-5`})});return cE.createPortal((0,G.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,G.jsxs)(`div`,{className:`absolute top-4 right-4 z-[110] flex items-center gap-2`,children:[o,d]}):e?(0,G.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,G.jsx)(`h2`,{className:`text-lg ${u?`font-black tracking-tight uppercase text-[11px] text-muted-foreground`:`font-semibold`}`,children:e}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o,d]})]}):null,(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden flex flex-col`,children:n})]}),document.body)},$0=(0,W.createContext)({updateFromSegments:()=>{},clear:()=>{}}),e2=({children:e,chromecastSubscription:t=null})=>(0,G.jsx)($0.Provider,{value:{updateFromSegments:(e,n,r)=>{t&&t.sendAnalyticsSummary([],n,r)},clear:()=>{}},children:e}),t2=new class{resolve(e){let t=this.resolveMode(e);return t===`active`?{type:`rpc-workbench-update`,mode:`active`}:t===`review`?p$(e.analyticsSegments):h$(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 n2(){if(!(`wakeLock`in navigator))return;let e=navigator.wakeLock;if(!(typeof e!=`object`||!e||!(`request`in e)))return e}function r2(e){let t=(0,W.useRef)(null);(0,W.useEffect)(()=>{let n=n2();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 i2(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 a2=``,o2=null,s2=()=>{let e=qZ(),[t,n]=(0,W.useState)(e.state),[r,i]=(0,W.useState)(!1);r2(r);let[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(null),d=(0,W.useRef)(null),f=iQ,p=(0,W.useRef)(f.getActiveHandle()),m=(0,W.useRef)(!1),h=(0,W.useCallback)(e=>{let t=p.current;p.current=null,t&&f.dispose(e),VF(null),u(null),c(null),i(!1)},[f]),g=(0,W.useCallback)(async e=>{if(!m.current){m.current=!0;try{let t=vF.getState().subscriptionManager,n=f.connect(e,t);p.current=n,u(n),c(n.subscription),i(!0),VF(n.transport),n.eventProvider.onEvent(e=>{if(e.name===`clock-command`){let t=r$(e.data);if(!t){console.warn(`[CastButtonRpc] Dropped malformed clock-command payload`);return}wQ(t.runId,t.command)||console.warn(`[CastButtonRpc] Clock command rejected by authority:`,t.command.kind);return}let t=SQ(),n=i$(e.name,t);n&&t&&!wQ(t.runId,n)&&console.warn(`[CastButtonRpc] Legacy receiver event rejected by authority:`,e.name)});let r=vF.getState(),a=t2.resolve({viewMode:r.runtime?`track`:`plan`,executionStatus:r.execution.status,runtime:r.runtime,analyticsSegments:[],selectedBlock:null,documentItems:[]});n.pushInitialWorkbench(a)}finally{m.current=!1}}},[f]),_=(0,W.useRef)(!1),v=(0,W.useCallback)(async()=>{if(f.isConnected&&f.getActiveHandle()){let e=f.getActiveHandle();p.current=e,u(e),c(e.subscription),i(!0);return}if(!(p.current||_.current)&&typeof e.resumeSession==`function`){_.current=!0;try{let t=await e.resumeSession();await g(t)}catch(t){console.warn(`[CastButtonRpc] Session resume failed:`,i2(t)),h(!1),e.endSession()}finally{_.current=!1}}},[e,g,h,f]);(0,W.useEffect)(()=>e.onStateChanged(e=>{n(e),e===`session-active`?(i(!0),v()):e===`ready`||e===`unavailable`?i(!1):e===`session-ended`&&h(!1)}),[e,h,v]),(0,W.useEffect)(()=>{if(f.isConnected&&f.getActiveHandle()){let e=f.getActiveHandle();p.current=e,u(e),c(e.subscription),i(!0)}else e.state===`session-active`&&v()},[e,f]),(0,W.useEffect)(()=>{let e=l?.transport;if(!e)return;let t=()=>{let t=SQ(),n=JSON.stringify(t);if(n!==a2||e!==o2){a2=n,o2=e;try{e.send({type:`rpc-clock-snapshot`,snapshot:t})}catch{}}};return t(),CQ(t)},[l]),(0,W.useEffect)(()=>{let e=()=>{f.sendDisposeSignal()};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[f]),(0,W.useEffect)(()=>{let t=d.current;if(!t)return;let n=async()=>{if(y.current===`session-active`){if(b.current)return;o(!0);try{h(!0),e.endSession()}finally{setTimeout(()=>o(!1),2e3)}return}try{let t=await e.startSession();i(!0),await g(t)}catch(e){let t=i2(e);t===`cancel`||t.includes(`cancel`)?console.log(`[CastButtonRpc] Cast request canceled or gesture expired`):console.error(`[CastButtonRpc] Cast failed:`,t),h(!1)}};return t.addEventListener(`click`,n),()=>t.removeEventListener(`click`,n)},[e,g,h]);let y=(0,W.useRef)(t);y.current=t;let b=(0,W.useRef)(a);b.current=a;let x=t===`unavailable`,S=t===`ready`,C=t===`session-active`,w=t===`connecting`,T=r&&C,E=w,D=E||a,O=S||C;return x?(0,G.jsxs)(q,{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,G.jsx)(sr,{className:`h-5 w-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Cast to TV (unavailable)`})]}):(0,G.jsx)(wae,{transport:l?.transport??null,children:(0,G.jsx)(e2,{chromecastSubscription:s,children:(0,G.jsxs)(q,{ref:d,variant:`ghost`,size:`icon`,disabled:D,onClick:()=>{},className:K(`transition-all`,T&&`text-signal-positive ring-2 ring-signal-positive/30`,E&&`animate-pulse text-signal-caution`,!O&&`opacity-50`),"aria-label":T?`Stop casting`:`Cast to TV`,title:T?`Stop casting`:E?`Connecting...`:`Cast to TV`,children:[T?(0,G.jsx)(Cn,{className:`h-5 w-5`}):(0,G.jsx)(sr,{className:`h-5 w-5`}),(0,G.jsx)(`span`,{className:`sr-only`,children:T?`Stop casting`:`Cast to TV`})]})})})};function c2(){let{isEnabled:e,toggleAudio:t}=JF();return(0,G.jsxs)(q,{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,G.jsx)(mn,{className:`h-[1.2rem] w-[1.2rem]`}):(0,G.jsx)(rn,{className:`h-[1.2rem] w-[1.2rem]`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Toggle audio`})]})}var l2=new Map,u2=({block:e,noteContent:t,prepareRun:n,view:r,onClose:i,onCompleteWorkout:a,resultId:o,noteId:s,autoStart:c,onRuntimeReady:l,onRunStarted:u,externalStop:d,adoptRuntime:f,parkOnUnmount:p,onPark:m,RuntimePanelSlot:h=g1,CastButtonSlot:g=s2,AudioToggleSlot:_=c2})=>{let[v,y]=(0,W.useState)(n?null:e),[b,x]=(0,W.useState)(null),S=(0,W.useRef)(!1),C=(0,W.useCallback)(async()=>{if(!(!n||S.current)){S.current=!0,x(null);try{y(await n())}catch(e){x(e instanceof Error?e.message:String(e))}finally{S.current=!1}}},[n]);(0,W.useEffect)(()=>{C()},[C]);let[w,T]=(0,W.useState)(null),[E,D]=(0,W.useState)(null),{isDebugMode:O}=VS(),k=(0,W.useMemo)(()=>d$(v??e,t),[v,e,t]).workoutTitle,A=(0,W.useRef)(Date.now()),j=(0,W.useRef)(typeof document<`u`?document.title:`Wod.Wiki`),M=(0,W.useRef)(null);(0,W.useEffect)(()=>{let t=k||e.label,n=w!==null,r=n?`Wod.Wiki - Workout Complete${t?`: `+t:``}`:`Wod.Wiki - Workout Timer${t?`: `+t:``}`,i=n?`/workout/review`:`/workout/timer`;document.title=r,M.current!==i&&(M.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:GP()}));let a=KP.consent;n?a&&window.gtag?.(`event`,`runtime_dialog_review`,{workout_label:t,block_type:e.blockType}):(KP.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,k,w]),(0,W.useEffect)(()=>{let t=j.current,n=A.current,r=k||e.label||e.id;return()=>{let e=Date.now()-n;e>=1e3&&window.gtag?.(`event`,`runtime_dialog_closed`,{workout_label:r,duration_seconds:Math.round(e/1e3),engagement_time_msec:e}),typeof document<`u`&&(document.title=t)}},[e.id,e.label,k]);let N=(0,W.useRef)(!1),P=(0,W.useRef)(!1),F=(0,W.useRef)(!1),[I,ee]=(0,W.useState)(!1),L=(0,W.useRef)(!1),te=(0,W.useRef)(!1),R=(0,W.useRef)(null),[ne,z]=(0,W.useState)(`idle`),[B,V]=(0,W.useState)(null),[re,ie]=(0,W.useState)(!1),{collectionItems:ae}=G$(w??[],l2,null),[oe,se]=(0,W.useState)(new Set),[ce,le]=(0,W.useState)(new Set),[H,ue]=(0,W.useState)(!1),U=(0,W.useMemo)(()=>ae.filter(e=>{let t=j$(e);return!oe.has(t)&&!ce.has(t)}),[ae,oe,ce]),de=w!==null&&!!o&&U.length>0&&!H,fe=(0,W.useCallback)(async e=>{let t=await X.getEventsByResult(e);D(t);let{segments:n}=xm(Hv(t).map(e=>dC(new Ba(e))));T(n)},[]),pe=(0,W.useCallback)(async(e,t)=>{if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid value`);if(e.kind!==`value`)throw Error(`Unsupported entry`);if(!o)throw Error(`The saved run is unavailable.`);if(await LF({resultId:o,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.`);await fe(o),se(t=>new Set(t).add(j$(e)))},[o,fe]),me=(0,W.useCallback)(async(e,t)=>{if(await LF({resultId:e,occurrence:t.occurrence,metric:{type:t.metric.type,value:t.metric.value,image:t.metric.image}})===`not-found`)throw Error(`This result entry could not be found.`);await fe(e)},[fe]),he=(0,W.useCallback)(async(e,t)=>{await RF(e,t),await fe(e)},[fe]),ge=(0,W.useCallback)(e=>{le(t=>new Set(t).add(j$(e)))},[]),_e=(0,W.useMemo)(()=>w===null||de?null:{runId:o?`result:${o}`:`review`,phase:`review`,status:`idle`,canNext:!1,canStop:!1,stopRequested:!1,reps:[],selectedOccurrenceId:null,entry:null,error:null,saving:!1},[w,de,o]),ve=async()=>{let e=R.current;if(!e||L.current)return;L.current=!0,te.current=!1,z(`saving`),V(null);let t;try{t=a?.(e.blockId,e.results),await t}catch(e){te.current=!0,V(e instanceof Error?e.message:String(e)),z(`error`),L.current=!1;return}L.current=!1,z(`idle`),ie(!0);let{results:n}=e;if(o)try{let e=await X.getEventsByResult(o);e.length>0&&D(e)}catch{}if(n.logs&&n.logs.length>0)try{let{segments:e}=xm(n.logs,n.startTime);T(e)}catch{T([])}else n.completed?T([]):F.current&&i()},ye=(0,W.useCallback)(()=>{N.current=!0,u?.()},[u]),be=()=>{if(L.current||te.current){F.current=!0;return}if(w!==null||P.current||!N.current){i();return}!I&&!d&&f$()||(F.current=!0,ee(!0))},xe=(0,W.useRef)(be);xe.current=be,sQ(_e,(0,W.useCallback)(e=>e.kind===`dismiss`&&(xe.current(),!0),[]),20,{keyboard:!0});let Se=(e,t)=>{P.current||(P.current=!0,R.current={blockId:e,results:t},ve())},Ce=(0,W.useMemo)(()=>{if(w===null)return null;let e=o??`standalone-review`,t=E&&E.length>0?E:w.map((t,n)=>{let r=t.context,i=t.absoluteStartTime??Date.now(),a=i+Math.max(0,(t.duration??0)*1e3);return{id:`${e}:${t.id??n}`,grain:`event`,outputType:String(r?.outputType??t.type??`segment`),sourceBlockKey:String(r?.sourceBlockKey??t.name??`segment-${n}`),...typeof r?.sourceStatementId==`number`?{sourceStatementId:r.sourceStatementId}:{},stackLevel:t.depth,completionReason:typeof r?.completionReason==`string`?r.completionReason:void 0,timestamp:i,timeSpan:{started:i,ended:a},metrics:t.metrics?Array.from(t.metrics):[]}}),n=t[0]?.timeSpan?.started??Date.now();return{parsed:{family:`find`,raw:`:session{result:${e}}`,target:`session`,filters:[{key:`result`,negate:!1,values:[{value:e,wildcard:!1}]}]},runs:[{resultId:e,noteId:``,timestamp:n,events:t}]}},[w,E,o]),we=ne===`idle`?null:(0,G.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:[ne===`saving`&&(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Saving…`}),ne===`error`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{role:`alert`,className:`text-destructive`,children:[`Save failed`,B?` — ${B}`:``]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>void ve(),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 v?w===null?(0,G.jsx)(Q0,{onClose:be,title:k??`Workout`,closeLabel:`Exit`,actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{type:`button`,onClick:be,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,G.jsx)(g,{}),(0,G.jsx)(_,{})]}),children:(0,G.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,"data-testid":$.TIMER_FULLSCREEN_OVERLAY,children:[we,b?(0,G.jsxs)(`div`,{className:`space-y-2 p-4`,children:[(0,G.jsxs)(`p`,{role:`alert`,children:[`Workout not started. `,b]}),(0,G.jsx)(`button`,{type:`button`,className:`rounded border px-3 py-2 hover:bg-accent focus-visible:ring-2`,onClick:()=>void C(),children:`Retry starting workout`})]}):v?null:(0,G.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`p-4`,children:`Saving workout before starting…`}),(0,G.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,G.jsx)(h,{block:v,resultId:o,noteId:s,noteContent:t,view:r,onClose:be,onComplete:Se,isExpanded:!0,autoStart:c,onRuntimeReady:l,onRunStarted:ye,externalStop:d||I,adoptRuntime:f,parkOnUnmount:p,onPark:m})})]})}):(0,G.jsx)(Q0,{title:`Workout Complete`,onClose:be,actions:(0,G.jsxs)(G.Fragment,{children:[re&&(0,G.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`Saved ✓`}),(0,G.jsx)(g,{}),(0,G.jsx)(_,{})]}),children:(0,G.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,"data-testid":$.TIMER_FULLSCREEN_OVERLAY,children:[we,(0,G.jsx)(`div`,{className:`min-h-0 flex-1`,children:de?(0,G.jsx)(X$,{mode:`post-run`,items:U,onSave:pe,onSkip:ge,onClose:()=>ue(!0),runId:o?`result:${o}`:void 0,className:`mx-auto max-w-md`}):Ce&&o?(0,G.jsx)(`div`,{className:`h-full overflow-auto p-4 sm:p-6`,children:(0,G.jsx)(aE,{resultId:o,sessionResult:Ce,executor:jW,onCaptureRpe:he,onEditMetric:me})}):Ce?(0,G.jsx)(`div`,{className:`h-full overflow-auto p-4 sm:p-6`,children:(0,G.jsx)(rE,{result:Ce,filter:O?``:void 0})}):null})]})}):(0,G.jsx)(Q0,{title:`Starting workout`,onClose:i,children:b?(0,G.jsxs)(`div`,{className:`space-y-3 p-6`,children:[(0,G.jsxs)(`p`,{role:`alert`,children:[`Workout not started. `,b,` Your draft is kept.`]}),(0,G.jsx)(`button`,{type:`button`,className:`rounded border px-3 py-2 focus-visible:ring-2`,onClick:()=>void C(),children:`Retry start`})]}):(0,G.jsx)(`p`,{role:`status`,className:`p-6`,children:`Saving workout before starting…`})})},d2={play:!0,"add-to-today":!0,schedule:!0},f2=`log`;function p2(e,t){return e.filter(e=>e.id===f2?t===`log`:!d2[e.id]||t===`run`)}function m2(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 h2(e){return function({className:t}){return W.isValidElement(e)?W.cloneElement(e,{className:K(e.props.className,t)}):(0,G.jsx)(`span`,{className:K(`flex items-center`,t),children:e})}}var g2=({cmd:e,block:t})=>{let[n,r]=(0,W.useState)(!1),[i,a]=(0,W.useState)(!1),o=(0,W.useCallback)(async()=>{!e.onSplitClick||n||(await e.onSplitClick(t),r(!0),setTimeout(()=>r(!1),1500))},[e,t,n]),s=(0,W.useCallback)(async()=>{i||(await e.onClick(t),e.successIcon&&(a(!0),setTimeout(()=>a(!1),1500)))},[e,t,i]),c=(0,W.useMemo)(()=>h2(i?e.successIcon??e.icon:e.icon),[e.icon,e.successIcon,i]),l=(0,W.useMemo)(()=>h2(n?e.splitSuccessIcon??e.splitIcon:e.splitIcon),[n,e.splitIcon,e.splitSuccessIcon]),u=(0,W.useMemo)(()=>({id:e.id,label:e.label,icon:c,action:{type:`call`,handler:()=>s()}}),[e.id,e.label,c,s]),d=(0,W.useMemo)(()=>({id:`${e.id}-split`,label:`Copy link`,icon:l,action:{type:`call`,handler:o}}),[e.id,l,o]),f=(0,W.useCallback)(e=>{e.preventDefault(),e.stopPropagation()},[]);if(!e.onSplitClick){let t=i?e.successIcon??e.icon:e.icon;return(0,G.jsxs)(q,{variant:e.primary?`default`:`secondary`,className:K(`pointer-events-auto scroll-mt-20`,e.iconOnly?`h-8 min-w-[34px] rounded-[5px] px-2 py-0.5 text-[11px] font-medium shadow-none`:`h-8 rounded-[5px] px-2.5 py-0.5 text-[11px] font-medium shadow-none gap-1.5`,e.primary?`bg-foreground text-background hover:bg-foreground/90 border border-foreground`:`bg-card text-foreground hover:bg-muted border border-border`,i&&`text-success bg-success/15 border-success/30`),title:e.label,"aria-label":e.label,"data-testid":e.id===`run`||e.id===`play`?$.EDITOR_START_WORKOUT:void 0,onClick:e=>{f(e),s()},onMouseDown:f,onPointerDown:f,children:[(0,G.jsx)(`span`,{className:`flex items-center justify-center size-3.5`,children:t}),!e.iconOnly&&(0,G.jsx)(`span`,{children:e.label})]})}return(0,G.jsx)(`div`,{className:`pointer-events-auto scroll-mt-20`,onClick:f,onMouseDown:f,onPointerDown:f,children:(0,G.jsx)(L0,{primary:u,secondary:d,size:`xs`,variant:e.primary?`primary`:`default`,className:`rounded-[5px] shadow-none`,labelClassName:`sr-only sm:not-sr-only sm:inline`})})},_2=({view:e,commands:t})=>{let[n,r]=(0,W.useState)(()=>e?.plugin($O)?.rects??[]),[i,a]=(0,W.useState)(0);(0,W.useEffect)(()=>{if(!e)return;let t=e.plugin($O);if(t)return r([...t.rects]),t.addListener(e=>r([...e]))},[e]),(0,W.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($O):null,s=(n.length>0?n:o?.rects??[]).filter(e=>e.type===`time`||e.type===`log`);if(s.length===0||!e)return null;let{sections:c}=e.state.field(CO),l=new Map(c.map(e=>[e.id,e])),u=(e.dom?.offsetTop??0)+(e.scrollDOM?.offsetTop??0)+(e.contentDOM?.offsetTop??0);return(0,G.jsx)(G.Fragment,{children:s.map(n=>{let r=l.get(n.sectionId);if(!r)return null;let a=m2(e,r),o=p2(t,Za(r.type));return o.length===0?null:(0,G.jsx)(`div`,{className:`absolute right-1.5 z-20 flex items-end gap-1 pb-0.5 pointer-events-none`,style:{top:u+n.top-i,height:n.firstLineHeight},children:o.map(e=>(0,G.jsx)(g2,{cmd:e,block:a},e.id))},n.sectionId)})})},v2=({sections:e,isRuntimeActive:t,editorState:n,onSelectBlock:r})=>{let i=GF(),a=(0,W.useRef)(``);return(0,W.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(`
824
824
  `).filter(e=>e.trim().length>0),i=r.slice(0,3).join(`
825
- `),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,W.useEffect)(()=>{i?.connected||(a.current=``)},[i]),(0,W.useEffect)(()=>{t||(a.current=``)},[t]),(0,W.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},y2={[J.Duration]:{label:`Timer`,Icon:mr,textClass:`text-metric-time`,bgClass:`bg-metric-time/10`,borderClass:`border-metric-time/30`},[J.Rep]:{label:`Reps`,Icon:Fr,textClass:`text-metric-rep`,bgClass:`bg-metric-rep/10`,borderClass:`border-metric-rep/30`},[J.Effort]:{label:`Exercise`,Icon:E,textClass:`text-metric-effort`,bgClass:`bg-metric-effort/10`,borderClass:`border-metric-effort/30`},[J.Rounds]:{label:`Rounds`,Icon:x,textClass:`text-metric-rounds`,bgClass:`bg-metric-rounds/10`,borderClass:`border-metric-rounds/30`},[J.Distance]:{label:`Distance`,Icon:tee,textClass:`text-metric-distance`,bgClass:`bg-metric-distance/10`,borderClass:`border-metric-distance/30`},[J.Resistance]:{label:`Weight`,Icon:xn,textClass:`text-metric-resistance`,bgClass:`bg-metric-resistance/10`,borderClass:`border-metric-resistance/30`},[J.Equipment]:{label:`Equipment`,Icon:Xn,textClass:`text-metric-equipment`,bgClass:`bg-metric-equipment/10`,borderClass:`border-metric-equipment/30`},[J.Action]:{label:`Action`,Icon:Br,textClass:`text-metric-action`,bgClass:`bg-metric-action/10`,borderClass:`border-metric-action/30`},[J.Label]:{label:`Label`,Icon:$n,textClass:`text-muted-foreground`,bgClass:`bg-muted/40`,borderClass:`border-border`}},b2={[J.Rep]:`reps`,[J.Effort]:`movement`,[J.Resistance]:`weight`},x2=({metric:e,tooltip:t,isFocused:n,onClick:r})=>{let i=y2[e.type],a=e.type===J.Hint,o=e.name??e.image??(e.value===void 0?``:String(e.value)),s=i?.label??String(e.type),c=i?.Icon;return(0,G.jsxs)(`span`,{title:t,onClick:r,className:K(`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full border text-[10px] leading-none font-medium whitespace-nowrap tabular-nums`,`pointer-events-auto transition-opacity hover:opacity-80`,i?.bgClass??`bg-muted/40`,i?.textClass??`text-muted-foreground`,i?.borderClass??`border-border`,r&&`cursor-pointer`,n&&`font-bold ring-1 ring-foreground/20`),children:[a?(0,G.jsx)(`span`,{children:e.icon}):c?(0,G.jsx)(c,{weight:`bold`,className:`h-2.5 w-2.5 shrink-0`}):null,!a&&(0,G.jsx)(`span`,{className:`sr-only`,children:s}),!a&&(0,G.jsx)(`span`,{className:`font-semibold`,children:o||s})]})};function S2(e){let t=Fa(e.metadata);return{refs:t?.refs??[],diagnostics:t?.diagnostics??[]}}function C2(e,t){try{let n=e.coordsAtPos(t.lineFrom);if(!n)return null;let r=typeof t.lineTo==`number`?e.coordsAtPos(t.lineTo)??n:n,i=e.dom?.getBoundingClientRect?.()??{top:0,left:0,width:600},a=e.contentDOM?.getBoundingClientRect?.()??{left:0,width:600},o=Math.max(0,a.left-i.left),s=o+Math.max(240,a.width),c=r.left-i.left+12,l=s-c;if(l>=180){let e=typeof r.top==`number`?r.top:r.bottom-20;return{top:Math.max(0,e-i.top-1),left:c,maxWidth:l-4,belowLine:!1}}return{top:r.bottom-i.top+3,left:o,maxWidth:Math.max(220,a.width),belowLine:!0}}catch{return null}}var w2=({view:e,cursorVersion:t,getCursorFocusState:n,hidden:r=!1})=>{let[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(null),u=(0,W.useRef)(null),d=(0,W.useCallback)(()=>{if(!e||r){s(null),a(null);return}let t=(n??h0)(e.state);s(t),a(t?C2(e,t):null)},[e,n,r]);(0,W.useEffect)(()=>{d()},[d,t]),(0,W.useEffect)(()=>{if(!e||r)return;let t=()=>d();return window.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,t,!0),()=>{window.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,t,!0)}},[e,d,r]);let f=e?.state&&typeof e.state.field==`function`?Fi(e.state)===`active`:!1;if(r||!i||!o?.section||f)return null;let p=o.allStatements?.filter(e=>e.meta?.line===o.cursorLine-o.section.startLine)??(o.statement?[o.statement]:[]),m=p.flatMap(e=>e.metrics.toArray()).filter(e=>{if(e.type===J.Sound||e.type===J.System||e.type===J.Hint&&!e.icon||e.type===J.Custom&&typeof e.value==`string`&&/^#[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(e.value.trim()))return!1;if(e.type===J.Effort||e.type===J.Equipment){let t=S2(e);if(t.refs.length>0||t.diagnostics.length>0)return!1}return!0}),h=KX(m,`runtime-badge`),g=p.flatMap(e=>e.metrics.toArray()),_=[],v=[],y=[];for(let e of g){let t=S2(e);for(let e of t.refs){let t=`${e.kind}:${e.slug}`;_.includes(t)||(_.push(t),v.push(e))}y.push(...t.diagnostics)}let b=[],x=[];for(let e of g){let t=Wa(e.metadata);if(t){b.some(e=>e.slug===t.slug)||b.push(t);continue}if(e.type===J.Custom&&typeof e.value==`string`&&/^#[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(e.value.trim())){let t=e.value.trim().slice(1);x.includes(t)||x.push(t)}}let S=typeof e?.state?.facet==`function`?e.state.facet(yk)?.()??null:null,C=typeof e?.state?.doc?.sliceString==`function`?t0(e.state.doc.sliceString(o.lineFrom,o.lineTo)):null,w=e=>e.reason===`conflict`||e.reason.endsWith(`equipment`)||e.reason===`invalid-explicit`&&e.token&&C?.equipment.includes(e.token)?`equipment`:`effort`,T=e=>typeof e==`string`&&e.trim()?e:null,D=async t=>{if(!e)return;let n=e.state.doc.sliceString(o.lineFrom,o.lineTo),r=FJ.getState();if(t===`effort`){let t=await r.open({placeholder:`Change effort...`,sources:[J1(`effort`)]});if(t.dismissed)return;let i=T(t.item.payload);if(!i)return;e.dispatch({changes:{from:o.lineFrom,to:o.lineTo,insert:n0(n,{effort:i})}});return}let i=[...C?.equipment??[]];for(;;){let e=await r.open({placeholder:i.length>0?`Add equipment (Esc to finish)...`:`Set equipment...`,sources:[J1(`equipment`)]});if(e.dismissed)break;let t=T(e.item.payload);t&&!i.includes(t)&&i.push(t)}((C?.jsonFrom??-1)>=0||i.length>0)&&e.dispatch({changes:{from:o.lineFrom,to:o.lineTo,insert:n0(n,{equipment:i})}})},O=async()=>{if(!e)return;let t=e.state.doc.sliceString(o.lineFrom,o.lineTo),n=FJ.getState(),r,i=await n.open({placeholder:`Add effort (Esc to skip)...`,sources:[J1(`effort`)]});i.dismissed||(r=T(i.item.payload)??void 0);let a=[];for(;;){let e=await n.open({placeholder:`Add equipment (Esc to finish)...`,sources:[J1(`equipment`)]});if(e.dismissed)break;let t=T(e.item.payload);t&&!a.includes(t)&&a.push(t)}!r&&a.length===0||e.dispatch({changes:{from:o.lineFrom,to:o.lineTo,insert:n0(t,{effort:r,equipment:a})}})},k=()=>{e&&typeof e.dispatch==`function`&&e.dispatch({effects:[s0.of(null)]}),d()},A=async t=>{if(!e||!t.token)return;let n=w(t),r=await FJ.getState().open({placeholder:`Replace "${t.token}"...`,sources:[J1(n,t.candidates)]});if(r.dismissed)return;let i=T(r.item.payload);if(!i)return;let a=e.state.doc.sliceString(o.lineFrom,o.lineTo).indexOf(t.token);a<0||e.dispatch({changes:{from:o.lineFrom+a,to:o.lineFrom+a+t.token.length,insert:i}})},j=async(e,t)=>{t.trim()&&(e===`effort`?await X1(t):await Q1(t),k())},M=async e=>{if(!e.trim())return;let t=await FJ.getState().open({placeholder:`Link "${e}" as alias to effort...`,sources:[J1(`effort`)]});if(t.dismissed)return;let n=T(t.item.payload);n&&(await Z1(n,e),k())},N=async e=>{e.trim()&&(await $1(e),k())},P=t=>{let n=b2[t.type];if(!n||!e)return;let r=t.type===J.Effort?`effort`:t.type===J.Equipment?`equipment`:null;if(r&&C?.jsonFrom!==void 0&&C.jsonFrom>=0){D(r);return}pe(async()=>{let{runStatementBuilderFlow:e}=await import(`./statementBuilderFlow-DVhmPVHz.js`);return{runStatementBuilderFlow:e}},__vite__mapDeps([0,1,2,3])).then(({runStatementBuilderFlow:t})=>{t(o,e,n)})};return(0,G.jsx)(`div`,{ref:u,className:K(`cm-metric-inline-panel`,`absolute z-[15]`,`inline-flex items-center gap-1 px-1.5 py-0.5 min-h-[22px]`,i.belowLine?`pointer-events-auto bg-card border border-border rounded-[6px]`:`pointer-events-none bg-transparent`,`transition-opacity duration-100 max-w-full`),style:{top:i.top,left:i.left,maxWidth:i.maxWidth},"aria-live":`polite`,"aria-label":`Metric inline panel`,children:m.length>0||v.length>0||b.length>0||y.length>0||x.length>0?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[m.map((e,t)=>(0,G.jsx)(x2,{metric:e,tooltip:e.type===J.Hint?String(e.value??``):h[t]?.tooltip,isFocused:o.focusedMetric===e,onClick:b2[e.type]?()=>P(e):void 0},`${e.type}-${t}`)),v.map(e=>{let t=e.kind===`effort`&&o.focusedMetric?.type===J.Effort||e.kind===`equipment`&&o.focusedMetric?.type===J.Equipment,n=e.kind===`effort`?E:Xn;return(0,G.jsxs)(`span`,{title:`${e.kind===`effort`?`Effort`:`Equipment`}: ${e.label} (${e.slug})${e.matchedAlias?` · matched alias "${e.matchedAlias}"`:``} · click to change`,onClick:()=>void D(e.kind),className:K(`pointer-events-auto inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full border text-[10px] leading-none font-medium cursor-pointer hover:opacity-80 whitespace-nowrap`,e.kind===`effort`?`bg-metric-effort/10 text-metric-effort border-metric-effort/30`:`bg-metric-equipment/10 text-metric-equipment border-metric-equipment/30`,t&&`font-bold ring-1 ring-foreground/20`),children:[(0,G.jsx)(n,{weight:`bold`,className:`h-2.5 w-2.5 shrink-0`}),(0,G.jsx)(`span`,{className:`sr-only`,children:e.kind===`effort`?`Exercise`:`Equipment`}),(0,G.jsx)(`span`,{className:`font-semibold`,children:e.label}),S&&(0,G.jsx)(`a`,{href:S.openHref(e.kind,e.slug),title:`Open ${e.label} page`,"aria-label":`Open ${e.label} page`,className:`opacity-70 hover:opacity-100 ml-0.5 inline-flex items-center`,onClick:e=>e.stopPropagation(),children:(0,G.jsx)(Me,{weight:`bold`,className:`h-2.5 w-2.5`})})]},`${e.kind}:${e.slug}`)}),b.map(e=>(0,G.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-0.5 px-1.5 py-0.5 rounded-full border text-[10px] leading-none font-medium bg-primary/10 text-primary border-primary/30 whitespace-nowrap`,children:[(0,G.jsx)(`span`,{children:`#`}),(0,G.jsx)(`span`,{className:`font-semibold font-mono`,children:e.label}),S&&(0,G.jsx)(`a`,{href:S.openHref(`tag`,e.slug),title:`Open the ${e.label} tag`,"aria-label":`Open the ${e.label} tag`,className:`opacity-70 hover:opacity-100 ml-0.5 inline-flex items-center`,onClick:e=>e.stopPropagation(),children:(0,G.jsx)(Me,{weight:`bold`,className:`h-2.5 w-2.5`})})]},`tag:${e.slug}`)),C?.malformed&&(0,G.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-[4px] border text-[11px] font-medium bg-destructive/10 text-destructive border-destructive/30`,children:[(0,G.jsx)(Ut,{weight:`bold`,className:`h-3 w-3 shrink-0`}),(0,G.jsx)(`span`,{children:`Malformed reference JSON`})]}),x.map(e=>(0,G.jsxs)(`span`,{"data-testid":`editor-tag-unknown`,title:`Unknown tag #${e} — click to create`,className:`pointer-events-auto inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full border border-dashed text-[10px] leading-none font-medium bg-warning/10 text-warning border-warning/40 whitespace-nowrap`,children:[(0,G.jsxs)(`span`,{className:`font-mono font-semibold`,children:[`#`,e]}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-create-tag-inline`,className:`underline cursor-pointer hover:text-foreground font-semibold ml-0.5`,onClick:()=>void N(e),children:`+ Tag`})]},`unresolved-tag:${e}`)),y.map((e,t)=>{let n=w(e),r=e.token?.trim()??``,i=e.reason===`unknown-effort`,a=`${e.reason}-${r||t}`,o=c===a||c===`all`;return(0,G.jsxs)(`span`,{"data-testid":`editor-ref-unknown`,title:e.message,onClick:()=>{o||l(a)},className:K(`pointer-events-auto inline-flex flex-wrap items-center gap-1.5 px-1.5 py-0.5 rounded-[6px] border border-dashed text-[10px] leading-tight font-medium bg-warning/10 text-warning border-warning/40 max-w-full`,!o&&`rounded-full whitespace-nowrap cursor-pointer hover:bg-warning/15`),children:[(0,G.jsx)(`span`,{children:`?`}),(0,G.jsx)(`span`,{className:`font-semibold`,children:e.token??e.reason}),o?(0,G.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1.5 pl-1 border-l border-warning/30`,children:[r&&(0,G.jsxs)(`button`,{type:`button`,"data-testid":`editor-create-${n}-inline`,className:`underline cursor-pointer hover:text-foreground font-semibold`,onClick:e=>{e.stopPropagation(),j(n,r)},children:[`+ `,n===`effort`?`Effort`:`Equipment`]}),r&&i&&(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-link-alias-inline`,className:`underline cursor-pointer hover:text-foreground font-semibold`,onClick:e=>{e.stopPropagation(),M(r)},children:`+ Alias`}),r&&i&&(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-create-equipment-from-token`,className:`underline cursor-pointer hover:text-foreground font-semibold`,onClick:e=>{e.stopPropagation(),j(`equipment`,r)},children:`+ Equipment`}),(0,G.jsx)(`button`,{type:`button`,className:`underline cursor-pointer hover:text-foreground`,onClick:t=>{t.stopPropagation(),A(e)},children:`Select existing`}),S&&(0,G.jsx)(`a`,{href:S.createHref(n),className:`underline hover:text-foreground`,onClick:e=>e.stopPropagation(),children:`Create page`})]}):(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-define-token`,className:`underline cursor-pointer hover:text-foreground font-semibold`,onClick:e=>{e.stopPropagation(),l(a)},children:`Define`})]},a)}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-add-metric-line`,title:`Add effort/equipment reference to this line`,onClick:()=>void O(),className:`pointer-events-auto inline-flex items-center px-1.5 py-0.5 rounded-full border border-dashed border-border text-[10px] leading-none text-muted-foreground hover:text-foreground hover:border-foreground cursor-pointer whitespace-nowrap`,children:`+ Metric`})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 italic select-none`,children:`No metrics on this line`})})},T2=Array.from({length:61},(e,t)=>({id:`min-${t}`,label:`${t}m`,value:String(t)})),E2=[`00`,`05`,`10`,`15`,`20`,`30`,`45`],D2=E2.map(e=>({id:`sec-${e}`,label:`${e}s`,value:e})),O2=[...[`21-15-9`,`15-12-9`,`12-9-6`,`10-8-6-4-2`,`5-5-5-5-5`].map(e=>({id:`scheme-${e}`,label:e,sublabel:`Scheme`,value:e})),...Array.from({length:50},(e,t)=>{let n=String(t+1);return{id:`rep-${n}`,label:n,value:n}}),...[`60`,`75`,`100`].map(e=>({id:`rep-${e}`,label:e,value:e}))],k2=Array.from({length:12},(e,t)=>{let n=t+1,r=`(${n})`;return{id:`rounds-${n}`,label:`${n} ${n===1?`round`:`rounds`}`,sublabel:r,value:r}}),A2=`5,7.5,10,12,15,16,20,22.5,24,25,30,32,35,40,42.5,45,50,52.5,60,65,70,75,80,85,90,95,100,105,115,120,135,140,155,160,185,205,225,245,275,315`.split(`,`),j2=`10,15,20,25,30,40,50,75,100,150,200,250,300,400,500,600,800,1000,1200,1600,2000,5000,1,1.5,2,3,5,10`.split(`,`),M2=[`kg`,`lb`,`pood`,`%`],N2=[`m`,`km`,`cal`,`ft`,`mi`,`yd`],P2=[{id:`act-rest`,label:`Rest`,sublabel:`:rest`,value:`:rest`},{id:`act-emom`,label:`EMOM`,sublabel:`1:00`,value:`1:00`},{id:`act-buyin`,label:`Buy-in`,sublabel:`Header`,value:`Buy-in:`},{id:`act-cashout`,label:`Cash-out`,sublabel:`Header`,value:`Cash-out:`}],F2=[`Air Squat`,`Back Squat`,`Front Squat`,`Deadlift`,`Kettlebell Swing`,`Pull-up`,`Push-up`,`Burpee`,`Thruster`,`Wall Ball`,`Box Jump`,`Row`,`Run`,`Double Under`],I2=[{id:`md-blocks`,label:`Blocks`,options:[{id:`blk-time`,label:`Timer Block`,sublabel:"```time",value:`block:time`},{id:`blk-log`,label:`Log Block`,sublabel:"```log",value:`block:log`},{id:`blk-query`,label:`Query Block`,sublabel:"```query",value:`block:query`},{id:`blk-table`,label:`Table (3x2)`,sublabel:`| Col |`,value:`block:table`},{id:`blk-divider`,label:`Divider`,sublabel:`---`,value:`block:divider`}]},{id:`md-format`,label:`Format`,options:[{id:`fmt-h1`,label:`Heading 1`,sublabel:`# Title`,value:`prefix:# `},{id:`fmt-h2`,label:`Heading 2`,sublabel:`## Section`,value:`prefix:## `},{id:`fmt-h3`,label:`Heading 3`,sublabel:`### Detail`,value:`prefix:### `},{id:`fmt-quote`,label:`Blockquote`,sublabel:`> Quote`,value:`prefix:> `},{id:`fmt-bold`,label:`Bold`,sublabel:`**text**`,value:`wrap:**`},{id:`fmt-code`,label:`Inline Code`,sublabel:"`code`",value:"wrap:`"}]},{id:`md-lists`,label:`Lists & Links`,options:[{id:`lst-task`,label:`Task Checkbox`,sublabel:`- [ ]`,value:`prefix:- [ ] `},{id:`lst-bullet`,label:`Bullet Item`,sublabel:`- `,value:`prefix:- `},{id:`lst-number`,label:`Numbered Item`,sublabel:`1. `,value:`prefix:1. `},{id:`lst-link`,label:`External Link`,sublabel:`[Label](url)`,value:`insert:[Link](https://)`},{id:`lst-wiki`,label:`Note Link`,sublabel:`[[Note]]`,value:`insert:[[Note]]`}]}],L2=[{id:`wql-metric`,label:`Query`,options:[{id:`q-reps`,label:`Total Reps`,sublabel:`sum:reps{}`,value:`replace:sum:reps{}`},{id:`q-vol`,label:`Total Volume`,sublabel:`sum:totalVolume{}`,value:`replace:sum:totalVolume{}`},{id:`q-dur`,label:`Total Duration`,sublabel:`sum:duration{}`,value:`replace:sum:duration{}`},{id:`q-sessions`,label:`Find Sessions`,sublabel:`find session{}`,value:`replace:find session{}`},{id:`q-notes`,label:`Find Notes`,sublabel:`find note{}`,value:`replace:find note{}`}]},{id:`wql-scope`,label:`Scope`,options:[{id:`s-note`,label:`This Note`,sublabel:`:note`,value:`append: :note`},{id:`s-all`,label:`All History`,sublabel:`Global`,value:`noop:`}]},{id:`wql-window`,label:`Window`,options:[{id:`w-week`,label:`Every Week`,sublabel:`every week`,value:`append: every week`},{id:`w-month`,label:`Every Month`,sublabel:`every month`,value:`append: every month`},{id:`w-4w`,label:`Last 4 Weeks`,sublabel:`last 4w`,value:`append: last 4w`},{id:`w-12w`,label:`Last 12 Weeks`,sublabel:`last 12w`,value:`append: last 12w`}]},{id:`wql-chart`,label:`Chart`,options:[{id:`c-bar`,label:`Bar Chart`,sublabel:`| :bar{}`,value:`append: | :bar{}`},{id:`c-line`,label:`Timeseries`,sublabel:`| :timeseries{}`,value:`append: | :timeseries{}`},{id:`c-table`,label:`Table`,sublabel:`| :table{}`,value:`append: | :table{}`}]}];function R2(e){return e.trim().toLowerCase()}function z2(e,t){let n=new Set,r=e=>{if(!e)return;let t=R2(e);if(t){n.add(t);for(let e of t.split(/[\s/_-]+/))e.length>=3&&n.add(e)}};r(e.notebookSlug);for(let t of e.tags)r(t);r(e.defaultEffort);for(let t of e.defaultEquipment)r(t);let i=E$(t);for(let e of i.activeTags)r(e);if(t.trimStart().startsWith(`---`)){let{meta:e}=Oo(t);for(let t of[`tags`,`domain`,`discipline`,`category`,`equipment`,`format`,`intent`]){let n=e[t];if(typeof n==`string`)r(n);else if(Array.isArray(n))for(let e of n)typeof e==`string`&&r(e)}}return n}async function B2(e,t){let n=q1(t),r=E$(t,{noteId:e}),i=new Set(r.activeTags),a,o,s=n.effort,c=[...n.equipment??[]],l,u,d=[];if(e)try{let t=await X.getNote(e);if(t){if(a=t.notebookId,a){o=a.replace(/^notebook\//,``);let e=await X.getNote(a).catch(()=>null);if(e?.rawContent){let t=q1(e.rawContent);!s&&t.effort&&(s=t.effort);for(let e of t.equipment??[])c.includes(e)||c.push(e);let n=E$(e.rawContent);for(let e of n.activeTags)i.add(e)}if(e?.tags)for(let t of e.tags)i.add(t)}if(t.tags)for(let e of t.tags)i.add(e)}}catch{}let f=oF(),p=new Set,m=new Set([`duration`,`time`,`rep`,`reps`,`effort`,`rounds`,`distance`,`resistance`,`weight`,`action`,`equipment`,`sound`,`system`,`label`]),h=e=>{let t=f.resolve(e);if(t)for(let e of t.contributions){if(e.kind!==`metric`)continue;let t=e.type.toLowerCase();if(t===`resistance`&&e.unit&&!l)l=e.unit;else if(t===`distance`&&e.unit&&!u)u=e.unit;else if(!m.has(t)&&!p.has(t)){p.add(t);let n=e.value===void 0?`1`:String(e.value);d.push({type:e.type,starterValue:n})}}};for(let e of i)h(e);for(let e of r.propertySources)for(let[t,n]of Object.entries(e.metrics??{})){let e=t.toLowerCase();if(!m.has(e)&&!p.has(e)){p.add(e);let r=typeof n==`object`&&n&&`value`in n?String(n.value??`1`):`1`;d.push({type:t,starterValue:r})}}return{notebookId:a,notebookSlug:o,tags:[...i],defaultEffort:s,defaultEquipment:c,preferredMassUnit:l,preferredDistanceUnit:u,customMetricTypes:d}}function V2(e,t,n){let r=0;if(t.defaultEffort&&e.slug===t.defaultEffort&&(r+=100),e.equipment?.some(e=>t.defaultEquipment.includes(e))&&(r+=40),e.baseAttributes?.discipline&&n.has(e.baseAttributes.discipline.toLowerCase())&&(r+=30),e.sourcePath){let t=e.sourcePath.toLowerCase();for(let e of n)if(e.length>=3&&t.includes(e)){r+=20;break}}let i=e.slug.toLowerCase();for(let e of n)if(e.length>=4&&i.includes(e)){r+=10;break}return r}function H2(e,t,n){let r=OM(),i=r.isInitialized()?[...r.list()]:[],a=z2(t,n);if(i.length===0){let t=F2.map(e=>({id:`eff-${e.toLowerCase().replace(/\s+/g,`-`)}`,label:e,value:e}));return e&&!t.some(t=>t.value.toLowerCase()===e.toLowerCase())?[{id:`eff-current`,label:e,value:e},...t]:t}let o=i.map(e=>({effort:e,score:V2(e,t,a)})).sort((e,t)=>t.score===e.score?e.effort.label.localeCompare(t.effort.label):t.score-e.score).slice(0,80).map(({effort:e,score:t})=>({id:`eff-${e.slug}`,label:e.label,sublabel:t>0?`Scoped`:e.baseAttributes?.discipline,value:e.label})),s=e.trim();return s&&!o.some(e=>e.value.toLowerCase()===s.toLowerCase())&&o.unshift({id:`eff-current`,label:s,value:s}),o}function U2(e,t){let n=eF(),r=[...n.isInitialized()?n.list():[]].sort((e,n)=>{let r=+!!t.defaultEquipment.includes(e.slug),i=+!!t.defaultEquipment.includes(n.slug);return i===r?e.label.localeCompare(n.label):i-r}),i=r.length>0?r.map(e=>({id:`eq-${e.slug}`,label:e.label,value:e.label})):[{id:`eq-kb`,label:`Kettlebell`,value:`KB`},{id:`eq-db`,label:`Dumbbell`,value:`DB`},{id:`eq-bb`,label:`Barbell`,value:`Barbell`},{id:`eq-rig`,label:`Pull-up Bar`,value:`Pull-up Bar`}],a=e.trim();return a&&!i.some(e=>e.value.toLowerCase()===a.toLowerCase())&&i.unshift({id:`eq-current`,label:a,value:a}),i}function W2(e,t){let n=oF().list(),r=new Set(t.tags.map(e=>e.toLowerCase())),i=[...n].filter(e=>!e.isCategory).sort((e,t)=>{let n=+!!r.has(e.slug.toLowerCase()),i=+!!r.has(t.slug.toLowerCase());return i===n?e.slug.localeCompare(t.slug):i-n}).map(e=>({id:`tag-${e.slug}`,label:`#${e.slug}`,value:`#${e.slug}`}));i.length===0&&i.push({id:`tag-emom`,label:`#emom`,value:`#emom`},{id:`tag-amrap`,label:`#amrap`,value:`#amrap`},{id:`tag-for-time`,label:`#for-time`,value:`#for-time`});let a=e.trim();return a&&!i.some(e=>e.value.toLowerCase()===a.toLowerCase())&&i.unshift({id:`tag-current`,label:a,value:a}),i}function G2(e){let t=e.trim().match(/^(\d+):(\d{2})(?::(\d{2}))?$/);if(t){if(t[3]!==void 0){let e=parseInt(t[1],10)*60+parseInt(t[2],10);return{minutes:String(Math.min(60,e)),seconds:t[3]}}return{minutes:String(Math.min(60,parseInt(t[1],10))),seconds:E2.includes(t[2])?t[2]:`00`}}return{minutes:`1`,seconds:`00`}}function K2(e,t,n){let r=e.trim().match(/^(@?\d+(?:\.\d+)?)\s*([a-zA-Z%]+)?$/);return r?{amount:r[1].replace(/^@/,``),unit:r[2]||n}:{amount:t,unit:n}}function q2(e,t,n){let r=e.metricType??``;if(r===J.Duration){let{minutes:t,seconds:n}=G2(e.rawText);return[{id:`duration-min`,label:`Minutes`,options:T2,selectedValue:t},{id:`duration-sec`,label:`Seconds`,options:D2,selectedValue:n}]}if(r===J.Rep){let t=e.rawText.trim();return[{id:`rep-value`,label:`Reps / Scheme`,options:O2.some(e=>e.value===t)?O2:[{id:`rep-cur`,label:t,value:t},...O2],selectedValue:t||`10`}]}if(r===J.Rounds){let t=e.rawText.trim();return[{id:`rounds-value`,label:`Rounds`,options:k2.some(e=>e.value===t)?k2:[{id:`rounds-cur`,label:t,value:t},...k2],selectedValue:t||`(3)`}]}if(r===J.Resistance){let n=t.preferredMassUnit??`kg`,{amount:r,unit:i}=K2(e.rawText,`20`,n),a=t.preferredMassUnit&&!M2.includes(t.preferredMassUnit)?[t.preferredMassUnit,...M2]:[n,...M2.filter(e=>e!==n)],o=(A2.includes(r)?A2:[r,...A2]).map(e=>({id:`wt-${e}`,label:e,value:e})),s=(a.includes(i)?a:[i,...a]).map(e=>({id:`wt-u-${e}`,label:e,value:e}));return[{id:`unit-amount`,label:`Load`,options:o,selectedValue:r},{id:`unit-suffix`,label:`Unit`,options:s,selectedValue:i}]}if(r===J.Distance){let n=t.preferredDistanceUnit??`m`,{amount:r,unit:i}=K2(e.rawText,`400`,n),a=t.preferredDistanceUnit&&!N2.includes(t.preferredDistanceUnit)?[t.preferredDistanceUnit,...N2]:[n,...N2.filter(e=>e!==n)],o=(j2.includes(r)?j2:[r,...j2]).map(e=>({id:`dist-${e}`,label:e,value:e})),s=(a.includes(i)?a:[i,...a]).map(e=>({id:`dist-u-${e}`,label:e,value:e}));return[{id:`unit-amount`,label:`Distance`,options:o,selectedValue:r},{id:`unit-suffix`,label:`Unit`,options:s,selectedValue:i}]}if(r===J.Equipment){let n=U2(e.rawText,t);return[{id:`equipment-value`,label:`Equipment`,options:n,selectedValue:n[0]?.value??e.rawText}]}if(r===`tag`){let n=W2(e.rawText,t);return[{id:`tag-value`,label:`Tag`,options:n,selectedValue:n.find(t=>t.value.toLowerCase()===e.rawText.trim().toLowerCase())?.value??n[0]?.value??e.rawText}]}if(r===J.Action){let t=e.rawText.trim();return[{id:`action-value`,label:`Action`,options:P2.some(e=>e.value===t)?P2:[{id:`act-cur`,label:t,value:t},...P2],selectedValue:t}]}let i=H2(e.rawText,t,n);return[{id:`effort-value`,label:`Movement / Effort`,options:i,selectedValue:i.find(t=>t.value.toLowerCase()===e.rawText.trim().toLowerCase())?.value??e.rawText.trim()}]}function J2(e,t){let n=H2(``,e,t)[0]?.value??`Air Squat`,r=e.preferredMassUnit??`kg`,i=e.preferredDistanceUnit??`m`,a=W2(``,e)[0]?.value??`#emom`,o=[{id:`add-duration`,label:`Duration / Timer`,sublabel:`1:00`,value:`1:00`},{id:`add-rep`,label:`Reps / Scheme`,sublabel:`10`,value:`10`},{id:`add-effort`,label:`Movement / Effort`,sublabel:n,value:n},{id:`add-weight`,label:`Weight / Load`,sublabel:`20${r}`,value:`20${r}`},{id:`add-distance`,label:`Distance`,sublabel:`400${i}`,value:`400${i}`},{id:`add-rounds`,label:`Rounds`,sublabel:`(3)`,value:`(3)`},{id:`add-rest`,label:`Rest / Action`,sublabel:`:rest`,value:`:rest`},{id:`add-tag`,label:`Tag (#)`,sublabel:a,value:a},...e.customMetricTypes.map(e=>({id:`add-custom-${e.type}`,label:e.type,sublabel:e.starterValue,value:e.starterValue}))];return{id:`add-metric-type`,label:`Select Metric Type to Insert`,options:o,selectedValue:o[0].value}}function Y2(e){let t=h0(e),n=e.selection.main.head,r=e.doc.lineAt(n),i=[];if(t?.statement&&t.section.contentFrom!==void 0){let n=t.section.contentFrom,a=t.statement,o=[];for(let e of a.metrics){if(e.type!==J.Equipment)continue;let t=Fa(e.metadata);if(t?.matched===`whole`||t?.matched==="default")continue;let r=a.metricMeta?.get(e);r&&o.push({from:n+r.startOffset,to:n+r.endOffset})}let s=new Set;Array.from(a.metrics).forEach((t,c)=>{if(t.type===J.Sound||t.type===J.System)return;let l=Wa(t.metadata),u=typeof t.type==`string`&&t.type.startsWith(`tag.`);if(l&&!u)return;if(t.type===J.Equipment){let e=Fa(t.metadata);if(e?.matched===`whole`||e?.matched==="default")return}let d=a.metricMeta?.get(t);if(!d)return;let f=n+d.startOffset,p=n+d.endOffset;if(t.type===J.Effort){for(let t of o)if(t.from===f&&t.to<p)for(f=t.to;f<p&&/\s/.test(e.doc.sliceString(f,f+1));)f++}if(f<r.from||p>r.to||f>=p)return;let m=`${f}:${p}`;if(s.has(m))return;s.add(m);let h=e.doc.sliceString(f,p),g=u||/^#[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(h.trim())?`tag`:t.type===J.Choice?String(t.alternatives[0]?.type??J.Effort):String(t.type);i.push({id:`metric-${c}-${f}`,kind:`metric`,label:h.trim(),metricType:g,from:f,to:p,rawText:h})}),i.sort((e,t)=>e.from-t.from)}return i.push({id:`add-metric`,kind:`add-metric`,label:`+ Add`,from:r.to,to:r.to,rawText:``}),i}function X2(e,t,n){let r=e.selection.main.head,i=e.doc.lineAt(r),a=e.doc.toString(),o=e.field(CO,!1)?.sections.find(e=>(e.type===`time`||e.type===`log`||e.type===`query`)&&i.number>=e.startLine&&i.number<=e.endLine)??null;if(!o)try{o=EO(e)}catch{o=e.field(CO,!1)?.sections.find(e=>i.number>=e.startLine&&i.number<=e.endLine)??null}if((o?.type===`time`||o?.type===`log`)&&i.number>o.startLine&&i.number<o.endLine){let o=Y2(e),s=o.findIndex(e=>e.kind===`metric`&&r>=e.from&&r<=e.to);n!=null&&n>=0&&n<o.length?s=n:s<0&&(s=o.length-1);let c=o[s]??o[o.length-1],l=c.kind===`add-metric`?[J2(t,a)]:q2(c,t,a);return{context:`workout`,lineNumber:i.number,lineFrom:i.from,lineTo:i.to,slots:o,activeSlotIndex:s,drums:l}}if(o?.type===`query`&&i.number>o.startLine&&i.number<o.endLine){let e=L2.map(e=>({id:e.id,kind:`query-stage`,label:e.label,from:i.from,to:i.to,rawText:i.text})),t=n!=null&&n>=0&&n<e.length?n:0,r=L2[t];return{context:`query`,lineNumber:i.number,lineFrom:i.from,lineTo:i.to,slots:e,activeSlotIndex:t,drums:[{id:r.id,label:r.label,options:r.options,selectedValue:r.options[0].value}]}}let s=I2.map(e=>({id:e.id,kind:`markdown-group`,label:e.label,from:i.from,to:i.to,rawText:i.text})),c=n!=null&&n>=0&&n<s.length?n:0,l=I2[c];return{context:`markdown`,lineNumber:i.number,lineFrom:i.from,lineTo:i.to,slots:s,activeSlotIndex:c,drums:[{id:l.id,label:l.label,options:l.options,selectedValue:l.options[0].value}]}}var Z2={tags:[],defaultEquipment:[],customMetricTypes:[]},Q2=36,$2=({drum:e,autoCommitOnScroll:t,onSelect:n})=>{let r=(0,W.useRef)(null),i=(0,W.useRef)(!1),a=(0,W.useRef)(null),o=(0,W.useMemo)(()=>{let t=e.options.findIndex(t=>t.value===e.selectedValue);return t>=0?t:0},[e.options,e.selectedValue]);(0,W.useEffect)(()=>{let e=r.current;if(!e)return;let t=o*Q2;Math.abs(e.scrollTop-t)>4&&(i.current=!0,e.scrollTop=t,window.setTimeout(()=>{i.current=!1},80))},[e.id,o]),(0,W.useEffect)(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]);let s=(0,W.useCallback)(()=>{!t||i.current||(a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{let t=r.current;if(!t)return;let i=Math.max(0,Math.min(e.options.length-1,Math.round(t.scrollTop/Q2))),a=e.options[i];a&&a.value!==e.selectedValue&&n(a)},130))},[t,e.options,e.selectedValue,n]);return(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-0 h-full flex flex-col overflow-hidden`,"data-testid":`wheel-drum-${e.id}`,children:[(0,G.jsx)(`div`,{className:`px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.06em] text-muted-foreground border-b border-border/70 truncate`,children:e.label}),(0,G.jsxs)(`div`,{className:`relative flex-1 min-h-0 overflow-hidden`,children:[(0,G.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-2 top-1/2 -translate-y-1/2 h-9 border-y border-border bg-background/55 rounded-[4px]`}),(0,G.jsx)(`div`,{ref:r,onScroll:s,className:`relative z-10 h-full overflow-y-auto snap-y snap-mandatory overscroll-contain scrollbar-none`,style:{paddingTop:`calc(50% - 18px)`,paddingBottom:`calc(50% - 18px)`},children:e.options.map((e,t)=>{let a=t===o;return(0,G.jsxs)(`button`,{type:`button`,"data-testid":`wheel-option-${e.id}`,onMouseDown:e=>e.preventDefault(),onClick:()=>{let a=r.current;a&&(i.current=!0,typeof a.scrollTo==`function`?a.scrollTo({top:t*Q2,behavior:`smooth`}):a.scrollTop=t*Q2,window.setTimeout(()=>{i.current=!1},160)),n(e)},className:K(`w-full h-9 snap-center px-3 flex items-center justify-between gap-2 text-left transition-colors`,a?`text-foreground font-semibold`:`text-muted-foreground hover:text-foreground`),children:[(0,G.jsx)(`span`,{className:`truncate text-[13px] font-mono tabular-nums`,children:e.label}),e.sublabel&&(0,G.jsx)(`span`,{className:`shrink-0 text-[11px] font-mono tabular-nums text-muted-foreground`,children:e.sublabel})]},e.id)})})]})]})},e4=({view:e,noteId:t,cursorVersion:n,isOpen:r,isTypingMode:i,onSwitchToTyping:a,onClose:o})=>{let[s,c]=(0,W.useState)(Z2),[l,u]=(0,W.useState)(null),d=(0,W.useRef)(-1),f=(0,W.useRef)(null),[p,m]=(0,W.useState)(0),h=e?.state.doc.toString()??``;(0,W.useEffect)(()=>{if(!r||!e)return;let n=!1;return B2(t,h).then(e=>{n||c(e)}),()=>{n=!0}},[r,t,h,e]),(0,W.useEffect)(()=>{if(!r||!i||typeof window>`u`){m(0);return}let e=window.visualViewport;if(!e)return;let t=()=>{let t=Math.max(0,window.innerHeight-(e.height+e.offsetTop));m(t)};return t(),e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[r,i]),(0,W.useEffect)(()=>{if(!e)return;let t=e.state.doc.lineAt(e.state.selection.main.head).number;t!==d.current&&(d.current=t,u(null))},[e,n]);let _=(0,W.useMemo)(()=>!e||!r?null:X2(e.state,s,l),[e,r,s,l,n]),v=(0,W.useCallback)((e,t)=>{e.dispatch({effects:si.scrollIntoView(t,{y:`center`,yMargin:32})})},[]),y=(0,W.useCallback)(t=>{if(!e||!_||_.slots.length===0)return;let n=Math.max(0,Math.min(_.slots.length-1,t)),r=_.slots[n];u(n),r.kind===`metric`?(e.dispatch({selection:{anchor:r.from,head:r.to}}),v(e,r.from)):r.kind===`add-metric`&&(e.dispatch({selection:{anchor:r.from,head:r.from}}),v(e,r.from))},[e,_,v]),b=(0,W.useCallback)(e=>{_&&y(_.activeSlotIndex+e)},[_,y]),x=(0,W.useCallback)((t,n)=>{if(!e||!_)return;let r=_.slots[_.activeSlotIndex];if(r){if(_.context===`workout`){if(r.kind===`add-metric`){let t=e.state.doc.lineAt(e.state.selection.main.head),r=t.text.length>0&&!/\s$/.test(t.text),i=`${r?` `:``}${n.value}`,a=t.to+ +!!r,o=t.to+i.length;u(null),e.dispatch({changes:{from:t.to,to:t.to,insert:i},selection:{anchor:a,head:o},userEvent:`input.wheel`}),v(e,a);return}let i=n.value;if(t.id===`duration-min`||t.id===`duration-sec`){let e=_.drums.find(e=>e.id===`duration-min`),r=_.drums.find(e=>e.id===`duration-sec`);i=`${t.id===`duration-min`?n.value:e?.selectedValue??`1`}:${t.id===`duration-sec`?n.value:r?.selectedValue??`00`}`}else if(t.id===`unit-amount`||t.id===`unit-suffix`){let e=_.drums.find(e=>e.id===`unit-amount`),r=_.drums.find(e=>e.id===`unit-suffix`);i=`${t.id===`unit-amount`?n.value:e?.selectedValue??`20`}${t.id===`unit-suffix`?n.value:r?.selectedValue??`kg`}`}let a=r.from+i.length;e.dispatch({changes:{from:r.from,to:r.to,insert:i},selection:{anchor:r.from,head:a},userEvent:`input.wheel`}),v(e,r.from);return}if(_.context===`markdown`){let t=e.state.doc.line(_.lineNumber),r=e.state.selection.main,i=n.value;if(i.startsWith(`block:`)){let n=i.slice(6),r=t.text.trim().length>0?`
826
- `:``;if(n===`time`||n===`log`){let i=`${r}\`\`\`${n}\n\n\`\`\``,a=t.to+r.length+4+n.length;u(null),e.dispatch({changes:{from:t.to,to:t.to,insert:i},selection:{anchor:a},userEvent:`input.wheel`}),v(e,a)}else if(n===`query`){let n=`${r}\`\`\`query\nsum:reps{} every week | :bar{}\n\`\`\``,i=t.to+r.length+9;u(null),e.dispatch({changes:{from:t.to,to:t.to,insert:n},selection:{anchor:i,head:i+30},userEvent:`input.wheel`}),v(e,i)}else if(n===`table`){let n=`${r}| Movement | Load | Notes |\n| --- | --- | --- |\n| Squat | 100kg | Smooth |\n`;e.dispatch({changes:{from:t.to,to:t.to,insert:n},selection:{anchor:t.to+n.length},userEvent:`input.wheel`})}else if(n===`divider`){let n=`${r}---\n`;e.dispatch({changes:{from:t.to,to:t.to,insert:n},selection:{anchor:t.to+n.length},userEvent:`input.wheel`})}return}if(i.startsWith(`prefix:`)){let n=`${i.slice(7)}${t.text.replace(/^(#{1,6}\s+|>\s+|-\s+\[[ xX]\]\s+|[-*+]\s+|\d+\.\s+)/,``)}`;e.dispatch({changes:{from:t.from,to:t.to,insert:n},selection:{anchor:t.from+n.length},userEvent:`input.wheel`}),v(e,t.from);return}if(i.startsWith(`wrap:`)){let t=i.slice(5),n=r.empty?`text`:e.state.doc.sliceString(r.from,r.to),a=`${t}${n}${t}`;e.dispatch({changes:{from:r.from,to:r.to,insert:a},selection:{anchor:r.from+t.length,head:r.from+t.length+n.length},userEvent:`input.wheel`});return}if(i.startsWith(`insert:`)){let t=i.slice(7);e.dispatch({changes:{from:r.to,to:r.to,insert:t},selection:{anchor:r.to+t.length},userEvent:`input.wheel`});return}}if(_.context===`query`){let t=e.state.doc.line(_.lineNumber),r=n.value;if(r.startsWith(`replace:`)){let n=r.slice(8);e.dispatch({changes:{from:t.from,to:t.to,insert:n},selection:{anchor:t.from+n.length},userEvent:`input.wheel`})}else if(r.startsWith(`append:`)){let n=r.slice(7);t.text.includes(n.trim())||e.dispatch({changes:{from:t.to,to:t.to,insert:n},selection:{anchor:t.to+n.length},userEvent:`input.wheel`})}}}},[e,_,v]),S=(0,W.useCallback)(()=>{if(!e)return;let t=e.state.selection.main.head,n=e.state.doc.lineAt(t),r=n.text.match(/^(\s*)/),i=`\n${r?r[1]:``}`,a=n.to+i.length;u(null),e.dispatch({changes:{from:n.to,to:n.to,insert:i},selection:{anchor:a},userEvent:`input.wheel`}),v(e,a)},[e,v]),C=(0,W.useCallback)(()=>{e&&(e.contentDOM.setAttribute(`inputmode`,`text`),a(!0),e.focus())},[e,a]),w=(0,W.useCallback)(()=>{e&&(e.contentDOM.setAttribute(`inputmode`,`none`),a(!1),e.focus())},[e,a]),T=(0,W.useCallback)(()=>{e?.contentDOM.blur(),o()},[e,o]),E=(0,W.useCallback)((e,t)=>{f.current={x:e,y:t}},[]),D=(0,W.useCallback)((e,t)=>{let n=f.current;if(f.current=null,!n)return;let r=e-n.x,i=t-n.y;Math.abs(r)>=28&&Math.abs(r)>Math.abs(i)*1.2&&b(r<0?1:-1)},[b]);if(!r||!e||!_)return null;if(i)return(0,G.jsxs)(`div`,{"data-testid":`mobile-typing-bar`,style:{bottom:`${p}px`},className:`fixed inset-x-0 z-40 h-10 flex items-center justify-between gap-1.5 px-2.5 bg-[#F7F6F3] dark:bg-card border-t border-border select-none`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-return-wheel-btn`,onMouseDown:e=>e.preventDefault(),onClick:w,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-[4px] border border-border bg-background text-foreground text-xs font-medium hover:bg-muted transition-colors`,children:[(0,G.jsx)(oee,{weight:`bold`,className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:`Wheel`})]}),(0,G.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Ci(e),"aria-label":`Indent line`,className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground hover:bg-muted transition-colors`,children:(0,G.jsx)(tn,{weight:`bold`,className:`h-3.5 w-3.5`})}),(0,G.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:S,className:`inline-flex items-center gap-1 h-7 px-2 rounded-[4px] border border-border bg-background text-foreground text-xs font-medium hover:bg-muted transition-colors`,children:[(0,G.jsx)(Rt,{weight:`bold`,className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Line`})]})]}),(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-wheel-done-btn`,onMouseDown:e=>e.preventDefault(),onClick:T,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-[4px] bg-foreground text-background text-xs font-medium`,children:[(0,G.jsx)(g,{weight:`bold`,className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:`Done`})]})]});let O=_.slots[_.activeSlotIndex],k=_.context===`workout`&&O?.kind===`metric`;return(0,G.jsxs)(`section`,{"aria-label":`Mobile workout and note wheel composer`,"data-testid":`mobile-wheel-composer`,onMouseDown:e=>{e.target.tagName!==`INPUT`&&e.preventDefault()},onTouchStart:e=>{let t=e.touches[0];t&&E(t.clientX,t.clientY)},onTouchEnd:e=>{let t=e.changedTouches[0];t&&D(t.clientX,t.clientY)},className:`fixed inset-x-0 bottom-0 z-40 h-[40dvh] max-h-[300px] min-h-[216px] flex flex-col bg-[#F7F6F3] dark:bg-card border-t border-border select-none`,children:[(0,G.jsxs)(`div`,{className:`h-10 px-2.5 flex items-center justify-between gap-1.5 border-b border-border bg-background/70`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,"data-testid":`mobile-wheel-prev-slot`,"aria-label":`Previous slot`,disabled:_.activeSlotIndex<=0,onClick:()=>b(-1),className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground disabled:opacity-35 hover:bg-muted transition-colors`,children:(0,G.jsx)(rt,{weight:`bold`,className:`h-3.5 w-3.5`})}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`mobile-wheel-next-slot`,"aria-label":`Next slot`,disabled:_.activeSlotIndex>=_.slots.length-1,onClick:()=>b(1),className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground disabled:opacity-35 hover:bg-muted transition-colors`,children:(0,G.jsx)(Ar,{weight:`bold`,className:`h-3.5 w-3.5`})}),(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-wheel-newline-btn`,onClick:S,className:`inline-flex items-center gap-1 h-7 px-2 rounded-[4px] border border-border bg-background text-foreground text-xs font-medium hover:bg-muted transition-colors`,children:[(0,G.jsx)(Rt,{weight:`bold`,className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Line`})]}),(0,G.jsx)(`button`,{type:`button`,"aria-label":`Outdent line`,onClick:()=>hee(e),className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground hover:bg-muted transition-colors`,children:(0,G.jsx)(ree,{weight:`bold`,className:`h-3.5 w-3.5`})}),(0,G.jsx)(`button`,{type:`button`,"aria-label":`Indent line`,onClick:()=>Ci(e),className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground hover:bg-muted transition-colors`,children:(0,G.jsx)(tn,{weight:`bold`,className:`h-3.5 w-3.5`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-wheel-type-btn`,onClick:C,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-[4px] border border-border bg-background text-foreground text-xs font-medium hover:bg-muted transition-colors`,children:[(0,G.jsx)(Kt,{weight:`bold`,className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:`Type`})]}),(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-wheel-done-btn`,onClick:T,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-[4px] bg-foreground text-background text-xs font-medium`,children:[(0,G.jsx)(g,{weight:`bold`,className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:`Done`})]})]})]}),(0,G.jsxs)(`div`,{"data-testid":`mobile-wheel-slot-rail`,onPointerDown:e=>E(e.clientX,e.clientY),onPointerUp:e=>D(e.clientX,e.clientY),className:`h-9 px-2.5 flex items-center gap-1.5 overflow-x-auto border-b border-border scrollbar-none`,children:[(0,G.jsxs)(`span`,{className:`shrink-0 text-[10px] font-mono tabular-nums uppercase tracking-[0.05em] text-muted-foreground pr-1`,children:[`L`,_.lineNumber]}),_.slots.map((e,t)=>{let n=t===_.activeSlotIndex,r=e.kind===`add-metric`;return(0,G.jsx)(`button`,{type:`button`,"data-testid":`mobile-wheel-slot-${e.kind===`add-metric`?`add`:t}`,onClick:()=>y(t),className:K(`shrink-0 h-6 px-2.5 rounded-[4px] text-xs font-mono tabular-nums border transition-colors`,n?`bg-foreground text-background border-foreground font-semibold`:r?`bg-background text-foreground border-dashed border-border hover:bg-muted`:`bg-background text-muted-foreground border-border hover:text-foreground`),children:e.label},e.id)})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 flex divide-x divide-border`,children:_.drums.map(e=>(0,G.jsx)($2,{drum:e,autoCommitOnScroll:k,onSelect:t=>x(e,t)},e.id))})]})},t4=({view:e,cursorVersion:t,disabled:n=!1})=>{let[r,i]=(0,W.useState)(null);if((0,W.useEffect)(()=>{if(!e||n||e.state.readOnly){i(null);return}let t=e.state.selection.main;if(t.empty||!e.hasFocus){i(null);return}let r=EO(e.state);if(!r||r.type!==`markdown`){i(null);return}let a=e.coordsAtPos(t.from),o=e.coordsAtPos(t.to),s=e.dom.getBoundingClientRect();if(!a||!o){i(null);return}let c=(a.left+o.right)/2-s.left,l=Math.max(96,Math.min(s.width-96,c)),u=a.top-s.top-38,d=u<4?o.bottom-s.top+6:u;i({top:d,left:l})},[e,t,n]),!r||!e)return null;let a=[{id:`bold`,label:`Bold (Ctrl+B)`,Icon:fn,run:()=>{PO(e,`**`),e.focus()}},{id:`italic`,label:`Italic (Ctrl+I)`,Icon:wr,run:()=>{PO(e,`*`),e.focus()}},{id:`strike`,label:`Strikethrough`,Icon:Zt,run:()=>{PO(e,`~~`),e.focus()}},{id:`code`,label:`Inline code (Ctrl+E)`,Icon:Qe,run:()=>{PO(e,"`"),e.focus()}},{id:`link`,label:`Insert link (Ctrl+K)`,Icon:dee,run:()=>{FO(e),e.focus()}},{id:`timer`,label:`Wrap in timer block`,Icon:mr,run:()=>{let t=e.state.selection.main;if(t.empty)return;let n=e.state.doc.sliceString(t.from,t.to),r=`\n\`\`\`time\n${n}\n\`\`\`\n`;e.dispatch({changes:{from:t.from,to:t.to,insert:r},selection:{anchor:t.from+9,head:t.from+9+n.length},userEvent:`input.format`}),e.focus()}}];return(0,G.jsx)(`div`,{role:`toolbar`,"aria-label":`Text formatting`,"data-testid":`selection-format-bar`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},style:{position:`absolute`,top:`${r.top}px`,left:`${r.left}px`,transform:`translateX(-50%)`,boxShadow:`0 2px 8px rgba(0, 0, 0, 0.04)`},className:`z-30 hidden lg:inline-flex items-center gap-0.5 px-1 py-0.5 rounded-[6px] bg-card border border-border text-foreground`,children:a.map(({id:e,label:t,Icon:n,run:r})=>(0,G.jsx)(`button`,{type:`button`,title:t,"aria-label":t,"data-testid":`format-bar-${e}`,onClick:r,className:`inline-flex items-center justify-center h-6 w-6 rounded-[4px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:(0,G.jsx)(n,{weight:`bold`,className:`h-3.5 w-3.5`})},e))})},n4=new zi,r4=new zi,i4=new zi,a4=new zi;async function o4(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 s4(e){let t=await o4(`\`\`\`time\n${e.trimEnd()}\n\`\`\`\n`);return`${window.location.origin}/load?zip=${t}`}async function c4(e){let t=await o4(`\`\`\`time\n${e.trimEnd()}\n\`\`\`\n`),n=`shared by ${iw()}`;return`${window.location.origin}/?z=${t}&by=${encodeURIComponent(n)}`}var l4=({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=``,ariaLabel:g=`Note editor`,onStartWorkout:_,onCompleteWorkout:v,onBlocksChange:y,onAddToPlan:b,notePersistence:x,onViewCreated:S,mode:C=`edit`,lineWrapping:w=!0,showLineNumbers:T=!0,enablePreview:E=!0,showFrontmatter:D=!0,enableLinting:O=!0,enableOverlay:k=!1,commands:A,hideDefaultCommands:j=!1,enableInlineRuntime:M=!0,extensions:N,widgetComponents:P,activeSectionId:F,scrollToSectionId:I,results:ee,placeholder:L})=>{let te=(0,W.useRef)(null),R=(0,W.useRef)(null),ne=(0,W.useRef)(null),z=(0,W.useRef)(``),B=p===`dark`||p===`vs-dark`,{isDebugMode:V}=VS(),re=r0(ne,x),[ie,ae]=(0,W.useState)(null),[oe,se]=(0,W.useState)([]),[ce,le]=(0,W.useState)(1),[H,ue]=(0,W.useState)(0),U=F??ie,de=E0(oe,U),[fe,me]=(0,W.useState)(null),[he,ge]=(0,W.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches),[_e,ve]=(0,W.useState)(!1),[ye,be]=(0,W.useState)(!1);(0,W.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(max-width: 1023px)`),t=e=>{ge(e.matches),e.matches||(ve(!1),be(!1))};return ge(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[xe,Se]=(0,W.useState)(null),[Ce,we]=(0,W.useState)(null),[Te,Ee]=(0,W.useState)(!1),De=(0,W.useRef)(null),Oe=(0,W.useRef)(!1),ke=(0,W.useRef)(n??0);(0,W.useEffect)(()=>{ke.current=n??0},[n]);let[Ae,je]=(0,W.useState)(null),Me=(0,W.useRef)(null),Ne=(0,W.useCallback)(async(t,n=!1)=>{let r=R.current;if(!(!r||Oe.current)){Oe.current=!0,je(null);try{let o=await a?.();typeof o==`number`&&(ke.current=o);let s=r.state.field(CO),c=await TF({noteId:e??xr(),rawContent:s.rawContent,blocks:s.noteBlocks,expectedSourceRevision:ke.current,...e?{}:{metadata:{title:`Playground workout`},noteType:`playground`}},t,xr(),e?void 0:`playground`,re);De.current=c,Me.current=null,ke.current=c.note.sourceRevision,r.dispatch({effects:hO.of({blocks:c.note.blocks,sourceRevision:c.note.sourceRevision})}),i?.({rawContent:c.note.rawContent,blocks:c.note.blocks,sourceRevision:c.note.sourceRevision}),Ee(n),Se(c.block),we(c.session.id)}catch(e){je(e instanceof Error?e.message:String(e))}finally{Oe.current=!1}}},[e,re,i,a]),Pe=(0,W.useCallback)(()=>{Se(null),we(null),Ee(!1)},[]),Ie=(0,W.useCallback)(e=>{M&&Ne(e,!0)},[M,Ne]);(0,W.useEffect)(()=>qK({noteId:e,readonly:!!m,sourceRevision:n,getValue:()=>R.current?.state.doc.toString()??c,getView:()=>R.current,getBlocks:()=>{let e=R.current;return e?e.state.field(CO).sections.filter(e=>e.type===`time`||e.type===`log`).map(t=>m4(t,e.state)).filter(e=>e!==null):[]},applyEdit:async(e,t=!1)=>{if(m)throw Error(`Editor is in read-only mode. Clone this Note before editing.`);let n=R.current;if(!n){l(e),t&&await(o??s)?.();return}let r=n.state.doc.length;n.dispatch({changes:{from:0,to:r,insert:e}}),l(e),t&&await(o??s)?.()},undoEdit:()=>{let e=R.current;if(!e||m)return!1;let t=Qi(e);return t&&l(e.state.doc.toString()),t},startLiveWorkout:async(e,t=!0)=>{let n=R.current;if(!n)return{started:!1,error:`Editor view is not mounted.`};let r=n.state.field(CO).sections.filter(e=>e.type===`time`||e.type===`log`).map(e=>m4(e,n.state)).filter(e=>e!==null),i=e?r.find(t=>t.id===e):r[0];return i?(await Ne(i,t),{started:!0,blockId:i.id}):{started:!1,error:e?`Workout block '${e}' not found in editor.`:"No runnable ```time workout block found in editor."}}}),[e,m,n,c,l,o,s,Ne]);let Le=(0,W.useRef)(null),Re=(0,W.useCallback)((e,t)=>{let n=Le.current,r=n!==null&&n.results===t,i=De.current;if(!i||!t)return Promise.reject(Error(`The saved run pin is unavailable.`));let a=i.session.id;if(Me.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=kj(t.state,e,a);if(n){let e=n.from+n.insert.indexOf("```");t.dispatch({changes:n,effects:[si.scrollIntoView(e,{y:`start`,yMargin:96})]}),l?.(t.state.doc.toString())}}r||(Le.current={results:t,resultId:a,runBlock:o});let s;try{s=KN(re).record({resultId:a,noteId:i.session.noteId,blockId:i.session.blockId,data:t,createdAt:t.endTime}).then(()=>v?.(e,t,a,o))}catch(e){return Promise.reject(e instanceof Error?e:Error(String(e)))}return Promise.resolve(s).then(()=>{Le.current?.results===t&&(Le.current=null),Me.current=a},()=>{}),s},[l,v,re]),ze=(0,W.useMemo)(()=>{if(j)return[];if(A&&A.length>0)return A;let e=[];return M?e.push({id:`run`,label:`Run`,icon:(0,G.jsx)(bt,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:Ne}):_&&e.push({id:`run`,label:`Run`,icon:(0,G.jsx)(bt,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:_}),e.push({id:`playground`,label:`Playground`,icon:(0,G.jsx)(Nr,{className:`h-3 w-3`}),splitIcon:(0,G.jsx)(Fe,{className:`h-3 w-3`}),splitSuccessIcon:(0,G.jsx)(xt,{className:`h-3 w-3`}),onClick:e=>{s4(e.content).then(e=>{let t=window.open(e,`wodwiki-playground`);t&&t.focus()})},onSplitClick:async e=>{let t=await c4(e.content);await navigator.clipboard.writeText(t)}}),b&&e.push({id:`plan`,label:`Plan`,icon:(0,G.jsx)(ut,{className:`h-3 w-3`}),onClick:b}),e},[A,_,b,M,j,Ne]),Be=(0,W.useMemo)(()=>Hi({codeLanguages:yM}),[]),Ve=(0,W.useMemo)(()=>{let e=Math.max(1,n),r=P?[...P.keys()]:co;if(t&&Object.keys(t).length>0)try{return ho(c,t,e,{registeredWidgets:r}),t}catch{return mo(c,{sourceRevision:e,blocks:t,registeredWidgets:r})}return mo(c,{sourceRevision:e,registeredWidgets:r})},[c,t,n,P]),He=(0,W.useMemo)(()=>[...T?[Ni(),pee()]:[],qi(),Li(),bi(),Si(),...w?[si.lineWrapping]:[],Oi.allowMultipleSelections.of(!0),Qr(),gi(),Xr(),Ki(),Yi.highest(Ui.of([{key:`Tab`,run:e=>Fi(e.state)!==null&&($r(e),!0)},{key:`Enter`,run:e=>{let t=e.state.selection.main,n=p4(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:(ei(e),$i(e))}}])),Ui.of([...ti,...gee,...Bi,...vee,...Mi,...di,...Wi,Xi,{key:`Mod-s`,run:()=>(o?.(),!0)},{key:`Ctrl-.`,run:e=>{let t=h0(e.state);if(!t?.focusedMetric)return!1;let n=t.focusedMetric.type;return!new Set([`duration`,`rep`,`rounds`,`distance`,`resistance`]).has(n)&&(pe(()=>Promise.resolve().then(()=>PJ).then(()=>{pe(async()=>{let{runStatementBuilderFlow:e}=await import(`./statementBuilderFlow-DVhmPVHz.js`);return{runStatementBuilderFlow:e}},__vite__mapDeps([0,1,2,3])).then(({runStatementBuilderFlow:n})=>{n(t,e)}).catch(()=>{FJ.getState().open({placeholder:`Modify metric…`,sources:[]})})}),void 0),!0)}}]),Fj,CO,fO.of({blocks:Ve,sourceRevision:Math.max(1,n),rawContent:c}),pO.of(P?[...P.keys()]:co),wO,xk.of(D),Sk.of(V),...E||!D?[dA]:[],...E?[nO,ok,mk,a0(e),F1(),W1(),XA,HA(),mj]:[],...O?[kO]:[],ZO,cD,zO,RO,BO.of(u4),VO.of(d4),...k?[Ij]:[],$O,iO.of(null),cO.of(e=>{if(/^(https?:|mailto:|tel:)/i.test(e)){window.open(e,`_blank`,`noopener,noreferrer`);return}if(e.startsWith(`/`)&&typeof window<`u`){window.history.pushState({},``,e),window.dispatchEvent(new PopStateEvent(`popstate`));return}typeof window<`u`&&window.location.assign(e)}),dO,v0,...bj,rO,...P&&P.size>0?[vM(P)]:[],Jj({executor:jW,onResultSaved:GN,readOnly:m,onCaptureRpe:m?void 0:async(e,t)=>{await RF(e,t)},onEditMetric:m?void 0:async(e,t)=>{if(await LF({resultId:e,occurrence:t.occurrence,metric:{type:t.metric.type,value:t.metric.value,image:t.metric.image}})===`not-found`)throw Error(`Result segment not found in storage.`)},noteHref:e=>eH(`blockContentId`in e||`dataType`in e?IV(e):AV(e))}),o0(e,re),si.domEventHandlers({focus:()=>(typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches&&!m&&ve(!0),!1),blur:e=>{let t=e.relatedTarget;return(!t||!te.current?.contains(t))&&(ve(!1),be(!1)),f?.(),!1}}),si.updateListener.of(e=>{if(e.docChanged){let t=e.state.field(CO);r?.({rawContent:t.rawContent,blocks:t.noteBlocks,sourceRevision:t.sourceRevision}),l(t.rawContent),u?.(e),h4(e.state,y,z),e.transactions.some(e=>e.isUserEvent(`input`)&&!e.isUserEvent(`input.wheel`)&&!e.isUserEvent(`input.format`)||e.isUserEvent(`delete`)||e.isUserEvent(`paste`)||e.isUserEvent(`drop`))||s?.()}if(e.selectionSet||e.docChanged){ue(e=>e+1),e.transactions.some(e=>e.isUserEvent(`delete.backward`))&&Fi(e.startState)!==null&&Fi(e.state)===null&&p4(e.state,e.state.selection.main.head)?.value===``&&queueMicrotask(()=>{e.view.state===e.state&&ni(e.view)});let{head:t}=e.state.selection.main,n=e.state.doc.lineAt(t);d?.(n.number,t-n.from+1);let r=EO(e.state);ae(r?.id??null),le(n.number);let{sections:i}=e.state.field(CO);se(i)}}),Oi.readOnly.of(m),si.editable.of(!m),...L?[Ti(L)]:[],si.contentAttributes.of({"aria-label":g})],[l,d,f,u,y,r,m,o,s,T,w,E,D,V,O,k,e,re,P,L,g]);(0,W.useEffect)(()=>{let e=te.current;if(!e)return;let t;try{t=Oi.create({doc:c,extensions:[...He,n4.of(QD(B)),r4.of(Be),i4.of([]),a4.of(si.contentAttributes.of({inputmode:he&&!ye?`none`:`text`})),...N??[]]})}catch(e){console.error(`NoteEditor: Failed to initialize EditorState, recovering with safe fallback`,e),t=Oi.create({doc:c,extensions:[n4.of(QD(B)),r4.of(Be)]})}let n=new si({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:si.scrollIntoView(n.state.selection.main.head,{y:`nearest`,yMargin:24})})})};i?.addEventListener(`resize`,o),n.contentDOM.addEventListener(`focus`,o),R.current=n,me(n),e.__codemirrorView=n,S?.(n);let{sections:s}=n.state.field(CO);se(s);let l=n.state.doc.lineAt(n.state.selection.main.head).number;le(l);let u=EO(n.state);ae(u?.id??null);let d=n.state.field(CO);return r?.({rawContent:d.rawContent,blocks:d.noteBlocks,sourceRevision:d.sourceRevision}),h4(n.state,y,z),()=>{cancelAnimationFrame(a),i?.removeEventListener(`resize`,o),n.contentDOM.removeEventListener(`focus`,o),delete e.__codemirrorView,me(null),n.destroy()}},[]),(0,W.useEffect)(()=>{let e=R.current;if(!e)return;let r=e.state.field(CO);if(c!==r.rawContent){let r=Math.max(1,n),i=t?mo(c,{sourceRevision:r,blocks:t,registeredWidgets:P?[...P.keys()]:co}):void 0,a=i&&t&&Object.keys(i).length===Object.keys(t).length&&Object.entries(t).every(([e,t])=>{let n=i[e];return n&&n.from===t.from&&n.to===t.to&&n.kind===t.kind&&n.dialect===t.dialect&&n.sport===t.sport});e.dispatch({changes:{from:0,to:e.state.doc.length,insert:c},...a?{effects:gO.of({rawContent:c,blocks:t,sourceRevision:r})}:{}})}else t&&n!==r.sourceRevision&&e.dispatch({effects:hO.of({blocks:t,sourceRevision:Math.max(1,n)})})},[c,t,n]),(0,W.useEffect)(()=>{R.current&&R.current.dispatch({effects:n4.reconfigure(QD(B))})},[B]);let Ue=(0,W.useRef)(he);Ue.current=he;let We=(0,W.useRef)(ye);return We.current=ye,(0,W.useEffect)(()=>{if(R.current){let e=[];R.current.dispatch({effects:[ji.reconfigure.of([...He,n4.of(QD(B)),r4.of(Be),i4.of(e),a4.of(si.contentAttributes.of({inputmode:Ue.current&&!We.current?`none`:`text`})),...N??[]])]})}},[He,N,C,B,Be]),(0,W.useEffect)(()=>{R.current&&R.current.dispatch({effects:a4.reconfigure(si.contentAttributes.of({inputmode:he&&!ye?`none`:`text`}))})},[he,ye]),(0,W.useEffect)(()=>{let e=typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches;!m&&!e&&R.current?.focus()},[m]),(0,W.useEffect)(()=>{if(I&&R.current){let e=R.current,t=e.state.doc.toString().split(`
825
+ `),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,W.useEffect)(()=>{i?.connected||(a.current=``)},[i]),(0,W.useEffect)(()=>{t||(a.current=``)},[t]),(0,W.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},y2={[J.Duration]:{label:`Timer`,Icon:mr,textClass:`text-metric-time`,bgClass:`bg-metric-time/10`,borderClass:`border-metric-time/30`},[J.Rep]:{label:`Reps`,Icon:Fr,textClass:`text-metric-rep`,bgClass:`bg-metric-rep/10`,borderClass:`border-metric-rep/30`},[J.Effort]:{label:`Exercise`,Icon:E,textClass:`text-metric-effort`,bgClass:`bg-metric-effort/10`,borderClass:`border-metric-effort/30`},[J.Rounds]:{label:`Rounds`,Icon:x,textClass:`text-metric-rounds`,bgClass:`bg-metric-rounds/10`,borderClass:`border-metric-rounds/30`},[J.Distance]:{label:`Distance`,Icon:tee,textClass:`text-metric-distance`,bgClass:`bg-metric-distance/10`,borderClass:`border-metric-distance/30`},[J.Resistance]:{label:`Weight`,Icon:xn,textClass:`text-metric-resistance`,bgClass:`bg-metric-resistance/10`,borderClass:`border-metric-resistance/30`},[J.Equipment]:{label:`Equipment`,Icon:Xn,textClass:`text-metric-equipment`,bgClass:`bg-metric-equipment/10`,borderClass:`border-metric-equipment/30`},[J.Action]:{label:`Action`,Icon:Br,textClass:`text-metric-action`,bgClass:`bg-metric-action/10`,borderClass:`border-metric-action/30`},[J.Label]:{label:`Label`,Icon:$n,textClass:`text-muted-foreground`,bgClass:`bg-muted/40`,borderClass:`border-border`}},b2={[J.Rep]:`reps`,[J.Effort]:`movement`,[J.Resistance]:`weight`},x2=({metric:e,tooltip:t,isFocused:n,onClick:r})=>{let i=y2[e.type],a=e.type===J.Hint,o=e.name??e.image??(e.value===void 0?``:String(e.value)),s=i?.label??String(e.type),c=i?.Icon;return(0,G.jsxs)(`span`,{title:t,onClick:r,className:K(`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full border text-[10px] leading-none font-medium whitespace-nowrap tabular-nums`,`pointer-events-auto transition-opacity hover:opacity-80`,i?.bgClass??`bg-muted/40`,i?.textClass??`text-muted-foreground`,i?.borderClass??`border-border`,r&&`cursor-pointer`,n&&`font-bold ring-1 ring-foreground/20`),children:[a?(0,G.jsx)(`span`,{children:e.icon}):c?(0,G.jsx)(c,{weight:`bold`,className:`h-2.5 w-2.5 shrink-0`}):null,!a&&(0,G.jsx)(`span`,{className:`sr-only`,children:s}),!a&&(0,G.jsx)(`span`,{className:`font-semibold`,children:o||s})]})};function S2(e){let t=Fa(e.metadata);return{refs:t?.refs??[],diagnostics:t?.diagnostics??[]}}function C2(e,t){try{let n=e.coordsAtPos(t.lineFrom);if(!n)return null;let r=typeof t.lineTo==`number`?e.coordsAtPos(t.lineTo)??n:n,i=e.dom?.getBoundingClientRect?.()??{top:0,left:0,width:600},a=e.contentDOM?.getBoundingClientRect?.()??{left:0,width:600},o=Math.max(0,a.left-i.left),s=o+Math.max(240,a.width),c=r.left-i.left+12,l=s-c;if(l>=180){let e=typeof r.top==`number`?r.top:r.bottom-20;return{top:Math.max(0,e-i.top-1),left:c,maxWidth:l-4,belowLine:!1}}return{top:r.bottom-i.top+3,left:o,maxWidth:Math.max(220,a.width),belowLine:!0}}catch{return null}}var w2=({view:e,cursorVersion:t,getCursorFocusState:n,hidden:r=!1})=>{let[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(null),u=(0,W.useRef)(null),d=(0,W.useCallback)(()=>{if(!e||r){s(null),a(null);return}let t=(n??h0)(e.state);s(t),a(t?C2(e,t):null)},[e,n,r]);(0,W.useEffect)(()=>{d()},[d,t]),(0,W.useEffect)(()=>{if(!e||r)return;let t=()=>d();return window.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,t,!0),()=>{window.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,t,!0)}},[e,d,r]);let f=e?.state&&typeof e.state.field==`function`?Fi(e.state)===`active`:!1;if(r||!i||!o?.section||f)return null;let p=o.allStatements?.filter(e=>e.meta?.line===o.cursorLine-o.section.startLine)??(o.statement?[o.statement]:[]),m=p.flatMap(e=>e.metrics.toArray()).filter(e=>{if(e.type===J.Sound||e.type===J.System||e.type===J.Hint&&!e.icon||e.type===J.Custom&&typeof e.value==`string`&&/^#[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(e.value.trim()))return!1;if(e.type===J.Effort||e.type===J.Equipment){let t=S2(e);if(t.refs.length>0||t.diagnostics.length>0)return!1}return!0}),h=KX(m,`runtime-badge`),g=p.flatMap(e=>e.metrics.toArray()),_=[],v=[],y=[];for(let e of g){let t=S2(e);for(let e of t.refs){let t=`${e.kind}:${e.slug}`;_.includes(t)||(_.push(t),v.push(e))}y.push(...t.diagnostics)}let b=[],x=[];for(let e of g){let t=Wa(e.metadata);if(t){b.some(e=>e.slug===t.slug)||b.push(t);continue}if(e.type===J.Custom&&typeof e.value==`string`&&/^#[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(e.value.trim())){let t=e.value.trim().slice(1);x.includes(t)||x.push(t)}}let S=typeof e?.state?.facet==`function`?e.state.facet(yk)?.()??null:null,C=typeof e?.state?.doc?.sliceString==`function`?t0(e.state.doc.sliceString(o.lineFrom,o.lineTo)):null,w=e=>e.reason===`conflict`||e.reason.endsWith(`equipment`)||e.reason===`invalid-explicit`&&e.token&&C?.equipment.includes(e.token)?`equipment`:`effort`,T=e=>typeof e==`string`&&e.trim()?e:null,D=async t=>{if(!e)return;let n=e.state.doc.sliceString(o.lineFrom,o.lineTo),r=FJ.getState();if(t===`effort`){let t=await r.open({placeholder:`Change effort...`,sources:[J1(`effort`)]});if(t.dismissed)return;let i=T(t.item.payload);if(!i)return;e.dispatch({changes:{from:o.lineFrom,to:o.lineTo,insert:n0(n,{effort:i})}});return}let i=[...C?.equipment??[]];for(;;){let e=await r.open({placeholder:i.length>0?`Add equipment (Esc to finish)...`:`Set equipment...`,sources:[J1(`equipment`)]});if(e.dismissed)break;let t=T(e.item.payload);t&&!i.includes(t)&&i.push(t)}((C?.jsonFrom??-1)>=0||i.length>0)&&e.dispatch({changes:{from:o.lineFrom,to:o.lineTo,insert:n0(n,{equipment:i})}})},O=async()=>{if(!e)return;let t=e.state.doc.sliceString(o.lineFrom,o.lineTo),n=FJ.getState(),r,i=await n.open({placeholder:`Add effort (Esc to skip)...`,sources:[J1(`effort`)]});i.dismissed||(r=T(i.item.payload)??void 0);let a=[];for(;;){let e=await n.open({placeholder:`Add equipment (Esc to finish)...`,sources:[J1(`equipment`)]});if(e.dismissed)break;let t=T(e.item.payload);t&&!a.includes(t)&&a.push(t)}!r&&a.length===0||e.dispatch({changes:{from:o.lineFrom,to:o.lineTo,insert:n0(t,{effort:r,equipment:a})}})},k=()=>{e&&typeof e.dispatch==`function`&&e.dispatch({effects:[s0.of(null)]}),d()},A=async t=>{if(!e||!t.token)return;let n=w(t),r=await FJ.getState().open({placeholder:`Replace "${t.token}"...`,sources:[J1(n,t.candidates)]});if(r.dismissed)return;let i=T(r.item.payload);if(!i)return;let a=e.state.doc.sliceString(o.lineFrom,o.lineTo).indexOf(t.token);a<0||e.dispatch({changes:{from:o.lineFrom+a,to:o.lineFrom+a+t.token.length,insert:i}})},j=async(e,t)=>{t.trim()&&(e===`effort`?await X1(t):await Q1(t),k())},M=async e=>{if(!e.trim())return;let t=await FJ.getState().open({placeholder:`Link "${e}" as alias to effort...`,sources:[J1(`effort`)]});if(t.dismissed)return;let n=T(t.item.payload);n&&(await Z1(n,e),k())},N=async e=>{e.trim()&&(await $1(e),k())},P=t=>{let n=b2[t.type];if(!n||!e)return;let r=t.type===J.Effort?`effort`:t.type===J.Equipment?`equipment`:null;if(r&&C?.jsonFrom!==void 0&&C.jsonFrom>=0){D(r);return}pe(async()=>{let{runStatementBuilderFlow:e}=await import(`./statementBuilderFlow-CILJ_dtU.js`);return{runStatementBuilderFlow:e}},__vite__mapDeps([0,1,2,3])).then(({runStatementBuilderFlow:t})=>{t(o,e,n)})};return(0,G.jsx)(`div`,{ref:u,className:K(`cm-metric-inline-panel`,`absolute z-[15]`,`inline-flex items-center gap-1 px-1.5 py-0.5 min-h-[22px]`,i.belowLine?`pointer-events-auto bg-card border border-border rounded-[6px]`:`pointer-events-none bg-transparent`,`transition-opacity duration-100 max-w-full`),style:{top:i.top,left:i.left,maxWidth:i.maxWidth},"aria-live":`polite`,"aria-label":`Metric inline panel`,children:m.length>0||v.length>0||b.length>0||y.length>0||x.length>0?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[m.map((e,t)=>(0,G.jsx)(x2,{metric:e,tooltip:e.type===J.Hint?String(e.value??``):h[t]?.tooltip,isFocused:o.focusedMetric===e,onClick:b2[e.type]?()=>P(e):void 0},`${e.type}-${t}`)),v.map(e=>{let t=e.kind===`effort`&&o.focusedMetric?.type===J.Effort||e.kind===`equipment`&&o.focusedMetric?.type===J.Equipment,n=e.kind===`effort`?E:Xn;return(0,G.jsxs)(`span`,{title:`${e.kind===`effort`?`Effort`:`Equipment`}: ${e.label} (${e.slug})${e.matchedAlias?` · matched alias "${e.matchedAlias}"`:``} · click to change`,onClick:()=>void D(e.kind),className:K(`pointer-events-auto inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full border text-[10px] leading-none font-medium cursor-pointer hover:opacity-80 whitespace-nowrap`,e.kind===`effort`?`bg-metric-effort/10 text-metric-effort border-metric-effort/30`:`bg-metric-equipment/10 text-metric-equipment border-metric-equipment/30`,t&&`font-bold ring-1 ring-foreground/20`),children:[(0,G.jsx)(n,{weight:`bold`,className:`h-2.5 w-2.5 shrink-0`}),(0,G.jsx)(`span`,{className:`sr-only`,children:e.kind===`effort`?`Exercise`:`Equipment`}),(0,G.jsx)(`span`,{className:`font-semibold`,children:e.label}),S&&(0,G.jsx)(`a`,{href:S.openHref(e.kind,e.slug),title:`Open ${e.label} page`,"aria-label":`Open ${e.label} page`,className:`opacity-70 hover:opacity-100 ml-0.5 inline-flex items-center`,onClick:e=>e.stopPropagation(),children:(0,G.jsx)(Me,{weight:`bold`,className:`h-2.5 w-2.5`})})]},`${e.kind}:${e.slug}`)}),b.map(e=>(0,G.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-0.5 px-1.5 py-0.5 rounded-full border text-[10px] leading-none font-medium bg-primary/10 text-primary border-primary/30 whitespace-nowrap`,children:[(0,G.jsx)(`span`,{children:`#`}),(0,G.jsx)(`span`,{className:`font-semibold font-mono`,children:e.label}),S&&(0,G.jsx)(`a`,{href:S.openHref(`tag`,e.slug),title:`Open the ${e.label} tag`,"aria-label":`Open the ${e.label} tag`,className:`opacity-70 hover:opacity-100 ml-0.5 inline-flex items-center`,onClick:e=>e.stopPropagation(),children:(0,G.jsx)(Me,{weight:`bold`,className:`h-2.5 w-2.5`})})]},`tag:${e.slug}`)),C?.malformed&&(0,G.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-[4px] border text-[11px] font-medium bg-destructive/10 text-destructive border-destructive/30`,children:[(0,G.jsx)(Ut,{weight:`bold`,className:`h-3 w-3 shrink-0`}),(0,G.jsx)(`span`,{children:`Malformed reference JSON`})]}),x.map(e=>(0,G.jsxs)(`span`,{"data-testid":`editor-tag-unknown`,title:`Unknown tag #${e} — click to create`,className:`pointer-events-auto inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full border border-dashed text-[10px] leading-none font-medium bg-warning/10 text-warning border-warning/40 whitespace-nowrap`,children:[(0,G.jsxs)(`span`,{className:`font-mono font-semibold`,children:[`#`,e]}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-create-tag-inline`,className:`underline cursor-pointer hover:text-foreground font-semibold ml-0.5`,onClick:()=>void N(e),children:`+ Tag`})]},`unresolved-tag:${e}`)),y.map((e,t)=>{let n=w(e),r=e.token?.trim()??``,i=e.reason===`unknown-effort`,a=`${e.reason}-${r||t}`,o=c===a||c===`all`;return(0,G.jsxs)(`span`,{"data-testid":`editor-ref-unknown`,title:e.message,onClick:()=>{o||l(a)},className:K(`pointer-events-auto inline-flex flex-wrap items-center gap-1.5 px-1.5 py-0.5 rounded-[6px] border border-dashed text-[10px] leading-tight font-medium bg-warning/10 text-warning border-warning/40 max-w-full`,!o&&`rounded-full whitespace-nowrap cursor-pointer hover:bg-warning/15`),children:[(0,G.jsx)(`span`,{children:`?`}),(0,G.jsx)(`span`,{className:`font-semibold`,children:e.token??e.reason}),o?(0,G.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1.5 pl-1 border-l border-warning/30`,children:[r&&(0,G.jsxs)(`button`,{type:`button`,"data-testid":`editor-create-${n}-inline`,className:`underline cursor-pointer hover:text-foreground font-semibold`,onClick:e=>{e.stopPropagation(),j(n,r)},children:[`+ `,n===`effort`?`Effort`:`Equipment`]}),r&&i&&(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-link-alias-inline`,className:`underline cursor-pointer hover:text-foreground font-semibold`,onClick:e=>{e.stopPropagation(),M(r)},children:`+ Alias`}),r&&i&&(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-create-equipment-from-token`,className:`underline cursor-pointer hover:text-foreground font-semibold`,onClick:e=>{e.stopPropagation(),j(`equipment`,r)},children:`+ Equipment`}),(0,G.jsx)(`button`,{type:`button`,className:`underline cursor-pointer hover:text-foreground`,onClick:t=>{t.stopPropagation(),A(e)},children:`Select existing`}),S&&(0,G.jsx)(`a`,{href:S.createHref(n),className:`underline hover:text-foreground`,onClick:e=>e.stopPropagation(),children:`Create page`})]}):(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-define-token`,className:`underline cursor-pointer hover:text-foreground font-semibold`,onClick:e=>{e.stopPropagation(),l(a)},children:`Define`})]},a)}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`editor-add-metric-line`,title:`Add effort/equipment reference to this line`,onClick:()=>void O(),className:`pointer-events-auto inline-flex items-center px-1.5 py-0.5 rounded-full border border-dashed border-border text-[10px] leading-none text-muted-foreground hover:text-foreground hover:border-foreground cursor-pointer whitespace-nowrap`,children:`+ Metric`})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 italic select-none`,children:`No metrics on this line`})})},T2=Array.from({length:61},(e,t)=>({id:`min-${t}`,label:`${t}m`,value:String(t)})),E2=[`00`,`05`,`10`,`15`,`20`,`30`,`45`],D2=E2.map(e=>({id:`sec-${e}`,label:`${e}s`,value:e})),O2=[...[`21-15-9`,`15-12-9`,`12-9-6`,`10-8-6-4-2`,`5-5-5-5-5`].map(e=>({id:`scheme-${e}`,label:e,sublabel:`Scheme`,value:e})),...Array.from({length:50},(e,t)=>{let n=String(t+1);return{id:`rep-${n}`,label:n,value:n}}),...[`60`,`75`,`100`].map(e=>({id:`rep-${e}`,label:e,value:e}))],k2=Array.from({length:12},(e,t)=>{let n=t+1,r=`(${n})`;return{id:`rounds-${n}`,label:`${n} ${n===1?`round`:`rounds`}`,sublabel:r,value:r}}),A2=`5,7.5,10,12,15,16,20,22.5,24,25,30,32,35,40,42.5,45,50,52.5,60,65,70,75,80,85,90,95,100,105,115,120,135,140,155,160,185,205,225,245,275,315`.split(`,`),j2=`10,15,20,25,30,40,50,75,100,150,200,250,300,400,500,600,800,1000,1200,1600,2000,5000,1,1.5,2,3,5,10`.split(`,`),M2=[`kg`,`lb`,`pood`,`%`],N2=[`m`,`km`,`cal`,`ft`,`mi`,`yd`],P2=[{id:`act-rest`,label:`Rest`,sublabel:`:rest`,value:`:rest`},{id:`act-emom`,label:`EMOM`,sublabel:`1:00`,value:`1:00`},{id:`act-buyin`,label:`Buy-in`,sublabel:`Header`,value:`Buy-in:`},{id:`act-cashout`,label:`Cash-out`,sublabel:`Header`,value:`Cash-out:`}],F2=[`Air Squat`,`Back Squat`,`Front Squat`,`Deadlift`,`Kettlebell Swing`,`Pull-up`,`Push-up`,`Burpee`,`Thruster`,`Wall Ball`,`Box Jump`,`Row`,`Run`,`Double Under`],I2=[{id:`md-blocks`,label:`Blocks`,options:[{id:`blk-time`,label:`Timer Block`,sublabel:"```time",value:`block:time`},{id:`blk-log`,label:`Log Block`,sublabel:"```log",value:`block:log`},{id:`blk-query`,label:`Query Block`,sublabel:"```query",value:`block:query`},{id:`blk-table`,label:`Table (3x2)`,sublabel:`| Col |`,value:`block:table`},{id:`blk-divider`,label:`Divider`,sublabel:`---`,value:`block:divider`}]},{id:`md-format`,label:`Format`,options:[{id:`fmt-h1`,label:`Heading 1`,sublabel:`# Title`,value:`prefix:# `},{id:`fmt-h2`,label:`Heading 2`,sublabel:`## Section`,value:`prefix:## `},{id:`fmt-h3`,label:`Heading 3`,sublabel:`### Detail`,value:`prefix:### `},{id:`fmt-quote`,label:`Blockquote`,sublabel:`> Quote`,value:`prefix:> `},{id:`fmt-bold`,label:`Bold`,sublabel:`**text**`,value:`wrap:**`},{id:`fmt-code`,label:`Inline Code`,sublabel:"`code`",value:"wrap:`"}]},{id:`md-lists`,label:`Lists & Links`,options:[{id:`lst-task`,label:`Task Checkbox`,sublabel:`- [ ]`,value:`prefix:- [ ] `},{id:`lst-bullet`,label:`Bullet Item`,sublabel:`- `,value:`prefix:- `},{id:`lst-number`,label:`Numbered Item`,sublabel:`1. `,value:`prefix:1. `},{id:`lst-link`,label:`External Link`,sublabel:`[Label](url)`,value:`insert:[Link](https://)`},{id:`lst-wiki`,label:`Note Link`,sublabel:`[[Note]]`,value:`insert:[[Note]]`}]}],L2=[{id:`wql-metric`,label:`Query`,options:[{id:`q-reps`,label:`Total Reps`,sublabel:`sum:reps{}`,value:`replace:sum:reps{}`},{id:`q-vol`,label:`Total Volume`,sublabel:`sum:totalVolume{}`,value:`replace:sum:totalVolume{}`},{id:`q-dur`,label:`Total Duration`,sublabel:`sum:duration{}`,value:`replace:sum:duration{}`},{id:`q-sessions`,label:`Find Sessions`,sublabel:`find session{}`,value:`replace:find session{}`},{id:`q-notes`,label:`Find Notes`,sublabel:`find note{}`,value:`replace:find note{}`}]},{id:`wql-scope`,label:`Scope`,options:[{id:`s-note`,label:`This Note`,sublabel:`:note`,value:`append: :note`},{id:`s-all`,label:`All History`,sublabel:`Global`,value:`noop:`}]},{id:`wql-window`,label:`Window`,options:[{id:`w-week`,label:`Every Week`,sublabel:`every week`,value:`append: every week`},{id:`w-month`,label:`Every Month`,sublabel:`every month`,value:`append: every month`},{id:`w-4w`,label:`Last 4 Weeks`,sublabel:`last 4w`,value:`append: last 4w`},{id:`w-12w`,label:`Last 12 Weeks`,sublabel:`last 12w`,value:`append: last 12w`}]},{id:`wql-chart`,label:`Chart`,options:[{id:`c-bar`,label:`Bar Chart`,sublabel:`| :bar{}`,value:`append: | :bar{}`},{id:`c-line`,label:`Timeseries`,sublabel:`| :timeseries{}`,value:`append: | :timeseries{}`},{id:`c-table`,label:`Table`,sublabel:`| :table{}`,value:`append: | :table{}`}]}];function R2(e){return e.trim().toLowerCase()}function z2(e,t){let n=new Set,r=e=>{if(!e)return;let t=R2(e);if(t){n.add(t);for(let e of t.split(/[\s/_-]+/))e.length>=3&&n.add(e)}};r(e.notebookSlug);for(let t of e.tags)r(t);r(e.defaultEffort);for(let t of e.defaultEquipment)r(t);let i=E$(t);for(let e of i.activeTags)r(e);if(t.trimStart().startsWith(`---`)){let{meta:e}=Oo(t);for(let t of[`tags`,`domain`,`discipline`,`category`,`equipment`,`format`,`intent`]){let n=e[t];if(typeof n==`string`)r(n);else if(Array.isArray(n))for(let e of n)typeof e==`string`&&r(e)}}return n}async function B2(e,t){let n=q1(t),r=E$(t,{noteId:e}),i=new Set(r.activeTags),a,o,s=n.effort,c=[...n.equipment??[]],l,u,d=[];if(e)try{let t=await X.getNote(e);if(t){if(a=t.notebookId,a){o=a.replace(/^notebook\//,``);let e=await X.getNote(a).catch(()=>null);if(e?.rawContent){let t=q1(e.rawContent);!s&&t.effort&&(s=t.effort);for(let e of t.equipment??[])c.includes(e)||c.push(e);let n=E$(e.rawContent);for(let e of n.activeTags)i.add(e)}if(e?.tags)for(let t of e.tags)i.add(t)}if(t.tags)for(let e of t.tags)i.add(e)}}catch{}let f=oF(),p=new Set,m=new Set([`duration`,`time`,`rep`,`reps`,`effort`,`rounds`,`distance`,`resistance`,`weight`,`action`,`equipment`,`sound`,`system`,`label`]),h=e=>{let t=f.resolve(e);if(t)for(let e of t.contributions){if(e.kind!==`metric`)continue;let t=e.type.toLowerCase();if(t===`resistance`&&e.unit&&!l)l=e.unit;else if(t===`distance`&&e.unit&&!u)u=e.unit;else if(!m.has(t)&&!p.has(t)){p.add(t);let n=e.value===void 0?`1`:String(e.value);d.push({type:e.type,starterValue:n})}}};for(let e of i)h(e);for(let e of r.propertySources)for(let[t,n]of Object.entries(e.metrics??{})){let e=t.toLowerCase();if(!m.has(e)&&!p.has(e)){p.add(e);let r=typeof n==`object`&&n&&`value`in n?String(n.value??`1`):`1`;d.push({type:t,starterValue:r})}}return{notebookId:a,notebookSlug:o,tags:[...i],defaultEffort:s,defaultEquipment:c,preferredMassUnit:l,preferredDistanceUnit:u,customMetricTypes:d}}function V2(e,t,n){let r=0;if(t.defaultEffort&&e.slug===t.defaultEffort&&(r+=100),e.equipment?.some(e=>t.defaultEquipment.includes(e))&&(r+=40),e.baseAttributes?.discipline&&n.has(e.baseAttributes.discipline.toLowerCase())&&(r+=30),e.sourcePath){let t=e.sourcePath.toLowerCase();for(let e of n)if(e.length>=3&&t.includes(e)){r+=20;break}}let i=e.slug.toLowerCase();for(let e of n)if(e.length>=4&&i.includes(e)){r+=10;break}return r}function H2(e,t,n){let r=OM(),i=r.isInitialized()?[...r.list()]:[],a=z2(t,n);if(i.length===0){let t=F2.map(e=>({id:`eff-${e.toLowerCase().replace(/\s+/g,`-`)}`,label:e,value:e}));return e&&!t.some(t=>t.value.toLowerCase()===e.toLowerCase())?[{id:`eff-current`,label:e,value:e},...t]:t}let o=i.map(e=>({effort:e,score:V2(e,t,a)})).sort((e,t)=>t.score===e.score?e.effort.label.localeCompare(t.effort.label):t.score-e.score).slice(0,80).map(({effort:e,score:t})=>({id:`eff-${e.slug}`,label:e.label,sublabel:t>0?`Scoped`:e.baseAttributes?.discipline,value:e.label})),s=e.trim();return s&&!o.some(e=>e.value.toLowerCase()===s.toLowerCase())&&o.unshift({id:`eff-current`,label:s,value:s}),o}function U2(e,t){let n=eF(),r=[...n.isInitialized()?n.list():[]].sort((e,n)=>{let r=+!!t.defaultEquipment.includes(e.slug),i=+!!t.defaultEquipment.includes(n.slug);return i===r?e.label.localeCompare(n.label):i-r}),i=r.length>0?r.map(e=>({id:`eq-${e.slug}`,label:e.label,value:e.label})):[{id:`eq-kb`,label:`Kettlebell`,value:`KB`},{id:`eq-db`,label:`Dumbbell`,value:`DB`},{id:`eq-bb`,label:`Barbell`,value:`Barbell`},{id:`eq-rig`,label:`Pull-up Bar`,value:`Pull-up Bar`}],a=e.trim();return a&&!i.some(e=>e.value.toLowerCase()===a.toLowerCase())&&i.unshift({id:`eq-current`,label:a,value:a}),i}function W2(e,t){let n=oF().list(),r=new Set(t.tags.map(e=>e.toLowerCase())),i=[...n].filter(e=>!e.isCategory).sort((e,t)=>{let n=+!!r.has(e.slug.toLowerCase()),i=+!!r.has(t.slug.toLowerCase());return i===n?e.slug.localeCompare(t.slug):i-n}).map(e=>({id:`tag-${e.slug}`,label:`#${e.slug}`,value:`#${e.slug}`}));i.length===0&&i.push({id:`tag-emom`,label:`#emom`,value:`#emom`},{id:`tag-amrap`,label:`#amrap`,value:`#amrap`},{id:`tag-for-time`,label:`#for-time`,value:`#for-time`});let a=e.trim();return a&&!i.some(e=>e.value.toLowerCase()===a.toLowerCase())&&i.unshift({id:`tag-current`,label:a,value:a}),i}function G2(e){let t=e.trim().match(/^(\d+):(\d{2})(?::(\d{2}))?$/);if(t){if(t[3]!==void 0){let e=parseInt(t[1],10)*60+parseInt(t[2],10);return{minutes:String(Math.min(60,e)),seconds:t[3]}}return{minutes:String(Math.min(60,parseInt(t[1],10))),seconds:E2.includes(t[2])?t[2]:`00`}}return{minutes:`1`,seconds:`00`}}function K2(e,t,n){let r=e.trim().match(/^(@?\d+(?:\.\d+)?)\s*([a-zA-Z%]+)?$/);return r?{amount:r[1].replace(/^@/,``),unit:r[2]||n}:{amount:t,unit:n}}function q2(e,t,n){let r=e.metricType??``;if(r===J.Duration){let{minutes:t,seconds:n}=G2(e.rawText);return[{id:`duration-min`,label:`Minutes`,options:T2,selectedValue:t},{id:`duration-sec`,label:`Seconds`,options:D2,selectedValue:n}]}if(r===J.Rep){let t=e.rawText.trim();return[{id:`rep-value`,label:`Reps / Scheme`,options:O2.some(e=>e.value===t)?O2:[{id:`rep-cur`,label:t,value:t},...O2],selectedValue:t||`10`}]}if(r===J.Rounds){let t=e.rawText.trim();return[{id:`rounds-value`,label:`Rounds`,options:k2.some(e=>e.value===t)?k2:[{id:`rounds-cur`,label:t,value:t},...k2],selectedValue:t||`(3)`}]}if(r===J.Resistance){let n=t.preferredMassUnit??`kg`,{amount:r,unit:i}=K2(e.rawText,`20`,n),a=t.preferredMassUnit&&!M2.includes(t.preferredMassUnit)?[t.preferredMassUnit,...M2]:[n,...M2.filter(e=>e!==n)],o=(A2.includes(r)?A2:[r,...A2]).map(e=>({id:`wt-${e}`,label:e,value:e})),s=(a.includes(i)?a:[i,...a]).map(e=>({id:`wt-u-${e}`,label:e,value:e}));return[{id:`unit-amount`,label:`Load`,options:o,selectedValue:r},{id:`unit-suffix`,label:`Unit`,options:s,selectedValue:i}]}if(r===J.Distance){let n=t.preferredDistanceUnit??`m`,{amount:r,unit:i}=K2(e.rawText,`400`,n),a=t.preferredDistanceUnit&&!N2.includes(t.preferredDistanceUnit)?[t.preferredDistanceUnit,...N2]:[n,...N2.filter(e=>e!==n)],o=(j2.includes(r)?j2:[r,...j2]).map(e=>({id:`dist-${e}`,label:e,value:e})),s=(a.includes(i)?a:[i,...a]).map(e=>({id:`dist-u-${e}`,label:e,value:e}));return[{id:`unit-amount`,label:`Distance`,options:o,selectedValue:r},{id:`unit-suffix`,label:`Unit`,options:s,selectedValue:i}]}if(r===J.Equipment){let n=U2(e.rawText,t);return[{id:`equipment-value`,label:`Equipment`,options:n,selectedValue:n[0]?.value??e.rawText}]}if(r===`tag`){let n=W2(e.rawText,t);return[{id:`tag-value`,label:`Tag`,options:n,selectedValue:n.find(t=>t.value.toLowerCase()===e.rawText.trim().toLowerCase())?.value??n[0]?.value??e.rawText}]}if(r===J.Action){let t=e.rawText.trim();return[{id:`action-value`,label:`Action`,options:P2.some(e=>e.value===t)?P2:[{id:`act-cur`,label:t,value:t},...P2],selectedValue:t}]}let i=H2(e.rawText,t,n);return[{id:`effort-value`,label:`Movement / Effort`,options:i,selectedValue:i.find(t=>t.value.toLowerCase()===e.rawText.trim().toLowerCase())?.value??e.rawText.trim()}]}function J2(e,t){let n=H2(``,e,t)[0]?.value??`Air Squat`,r=e.preferredMassUnit??`kg`,i=e.preferredDistanceUnit??`m`,a=W2(``,e)[0]?.value??`#emom`,o=[{id:`add-duration`,label:`Duration / Timer`,sublabel:`1:00`,value:`1:00`},{id:`add-rep`,label:`Reps / Scheme`,sublabel:`10`,value:`10`},{id:`add-effort`,label:`Movement / Effort`,sublabel:n,value:n},{id:`add-weight`,label:`Weight / Load`,sublabel:`20${r}`,value:`20${r}`},{id:`add-distance`,label:`Distance`,sublabel:`400${i}`,value:`400${i}`},{id:`add-rounds`,label:`Rounds`,sublabel:`(3)`,value:`(3)`},{id:`add-rest`,label:`Rest / Action`,sublabel:`:rest`,value:`:rest`},{id:`add-tag`,label:`Tag (#)`,sublabel:a,value:a},...e.customMetricTypes.map(e=>({id:`add-custom-${e.type}`,label:e.type,sublabel:e.starterValue,value:e.starterValue}))];return{id:`add-metric-type`,label:`Select Metric Type to Insert`,options:o,selectedValue:o[0].value}}function Y2(e){let t=h0(e),n=e.selection.main.head,r=e.doc.lineAt(n),i=[];if(t?.statement&&t.section.contentFrom!==void 0){let n=t.section.contentFrom,a=t.statement,o=[];for(let e of a.metrics){if(e.type!==J.Equipment)continue;let t=Fa(e.metadata);if(t?.matched===`whole`||t?.matched==="default")continue;let r=a.metricMeta?.get(e);r&&o.push({from:n+r.startOffset,to:n+r.endOffset})}let s=new Set;Array.from(a.metrics).forEach((t,c)=>{if(t.type===J.Sound||t.type===J.System)return;let l=Wa(t.metadata),u=typeof t.type==`string`&&t.type.startsWith(`tag.`);if(l&&!u)return;if(t.type===J.Equipment){let e=Fa(t.metadata);if(e?.matched===`whole`||e?.matched==="default")return}let d=a.metricMeta?.get(t);if(!d)return;let f=n+d.startOffset,p=n+d.endOffset;if(t.type===J.Effort){for(let t of o)if(t.from===f&&t.to<p)for(f=t.to;f<p&&/\s/.test(e.doc.sliceString(f,f+1));)f++}if(f<r.from||p>r.to||f>=p)return;let m=`${f}:${p}`;if(s.has(m))return;s.add(m);let h=e.doc.sliceString(f,p),g=u||/^#[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(h.trim())?`tag`:t.type===J.Choice?String(t.alternatives[0]?.type??J.Effort):String(t.type);i.push({id:`metric-${c}-${f}`,kind:`metric`,label:h.trim(),metricType:g,from:f,to:p,rawText:h})}),i.sort((e,t)=>e.from-t.from)}return i.push({id:`add-metric`,kind:`add-metric`,label:`+ Add`,from:r.to,to:r.to,rawText:``}),i}function X2(e,t,n){let r=e.selection.main.head,i=e.doc.lineAt(r),a=e.doc.toString(),o=e.field(CO,!1)?.sections.find(e=>(e.type===`time`||e.type===`log`||e.type===`query`)&&i.number>=e.startLine&&i.number<=e.endLine)??null;if(!o)try{o=EO(e)}catch{o=e.field(CO,!1)?.sections.find(e=>i.number>=e.startLine&&i.number<=e.endLine)??null}if((o?.type===`time`||o?.type===`log`)&&i.number>o.startLine&&i.number<o.endLine){let o=Y2(e),s=o.findIndex(e=>e.kind===`metric`&&r>=e.from&&r<=e.to);n!=null&&n>=0&&n<o.length?s=n:s<0&&(s=o.length-1);let c=o[s]??o[o.length-1],l=c.kind===`add-metric`?[J2(t,a)]:q2(c,t,a);return{context:`workout`,lineNumber:i.number,lineFrom:i.from,lineTo:i.to,slots:o,activeSlotIndex:s,drums:l}}if(o?.type===`query`&&i.number>o.startLine&&i.number<o.endLine){let e=L2.map(e=>({id:e.id,kind:`query-stage`,label:e.label,from:i.from,to:i.to,rawText:i.text})),t=n!=null&&n>=0&&n<e.length?n:0,r=L2[t];return{context:`query`,lineNumber:i.number,lineFrom:i.from,lineTo:i.to,slots:e,activeSlotIndex:t,drums:[{id:r.id,label:r.label,options:r.options,selectedValue:r.options[0].value}]}}let s=I2.map(e=>({id:e.id,kind:`markdown-group`,label:e.label,from:i.from,to:i.to,rawText:i.text})),c=n!=null&&n>=0&&n<s.length?n:0,l=I2[c];return{context:`markdown`,lineNumber:i.number,lineFrom:i.from,lineTo:i.to,slots:s,activeSlotIndex:c,drums:[{id:l.id,label:l.label,options:l.options,selectedValue:l.options[0].value}]}}var Z2={tags:[],defaultEquipment:[],customMetricTypes:[]},Q2=36,$2=({drum:e,autoCommitOnScroll:t,onSelect:n})=>{let r=(0,W.useRef)(null),i=(0,W.useRef)(!1),a=(0,W.useRef)(null),o=(0,W.useMemo)(()=>{let t=e.options.findIndex(t=>t.value===e.selectedValue);return t>=0?t:0},[e.options,e.selectedValue]);(0,W.useEffect)(()=>{let e=r.current;if(!e)return;let t=o*Q2;Math.abs(e.scrollTop-t)>4&&(i.current=!0,e.scrollTop=t,window.setTimeout(()=>{i.current=!1},80))},[e.id,o]),(0,W.useEffect)(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]);let s=(0,W.useCallback)(()=>{!t||i.current||(a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{let t=r.current;if(!t)return;let i=Math.max(0,Math.min(e.options.length-1,Math.round(t.scrollTop/Q2))),a=e.options[i];a&&a.value!==e.selectedValue&&n(a)},130))},[t,e.options,e.selectedValue,n]);return(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-0 h-full flex flex-col overflow-hidden`,"data-testid":`wheel-drum-${e.id}`,children:[(0,G.jsx)(`div`,{className:`px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.06em] text-muted-foreground border-b border-border/70 truncate`,children:e.label}),(0,G.jsxs)(`div`,{className:`relative flex-1 min-h-0 overflow-hidden`,children:[(0,G.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-2 top-1/2 -translate-y-1/2 h-9 border-y border-border bg-background/55 rounded-[4px]`}),(0,G.jsx)(`div`,{ref:r,onScroll:s,className:`relative z-10 h-full overflow-y-auto snap-y snap-mandatory overscroll-contain scrollbar-none`,style:{paddingTop:`calc(50% - 18px)`,paddingBottom:`calc(50% - 18px)`},children:e.options.map((e,t)=>{let a=t===o;return(0,G.jsxs)(`button`,{type:`button`,"data-testid":`wheel-option-${e.id}`,onMouseDown:e=>e.preventDefault(),onClick:()=>{let a=r.current;a&&(i.current=!0,typeof a.scrollTo==`function`?a.scrollTo({top:t*Q2,behavior:`smooth`}):a.scrollTop=t*Q2,window.setTimeout(()=>{i.current=!1},160)),n(e)},className:K(`w-full h-9 snap-center px-3 flex items-center justify-between gap-2 text-left transition-colors`,a?`text-foreground font-semibold`:`text-muted-foreground hover:text-foreground`),children:[(0,G.jsx)(`span`,{className:`truncate text-[13px] font-mono tabular-nums`,children:e.label}),e.sublabel&&(0,G.jsx)(`span`,{className:`shrink-0 text-[11px] font-mono tabular-nums text-muted-foreground`,children:e.sublabel})]},e.id)})})]})]})},e4=({view:e,noteId:t,cursorVersion:n,isOpen:r,isTypingMode:i,onSwitchToTyping:a,onClose:o})=>{let[s,c]=(0,W.useState)(Z2),[l,u]=(0,W.useState)(null),d=(0,W.useRef)(-1),f=(0,W.useRef)(null),[p,m]=(0,W.useState)(0),h=e?.state.doc.toString()??``;(0,W.useEffect)(()=>{if(!r||!e)return;let n=!1;return B2(t,h).then(e=>{n||c(e)}),()=>{n=!0}},[r,t,h,e]),(0,W.useEffect)(()=>{if(!r||!i||typeof window>`u`){m(0);return}let e=window.visualViewport;if(!e)return;let t=()=>{let t=Math.max(0,window.innerHeight-(e.height+e.offsetTop));m(t)};return t(),e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[r,i]),(0,W.useEffect)(()=>{if(!e)return;let t=e.state.doc.lineAt(e.state.selection.main.head).number;t!==d.current&&(d.current=t,u(null))},[e,n]);let _=(0,W.useMemo)(()=>!e||!r?null:X2(e.state,s,l),[e,r,s,l,n]),v=(0,W.useCallback)((e,t)=>{e.dispatch({effects:si.scrollIntoView(t,{y:`center`,yMargin:32})})},[]),y=(0,W.useCallback)(t=>{if(!e||!_||_.slots.length===0)return;let n=Math.max(0,Math.min(_.slots.length-1,t)),r=_.slots[n];u(n),r.kind===`metric`?(e.dispatch({selection:{anchor:r.from,head:r.to}}),v(e,r.from)):r.kind===`add-metric`&&(e.dispatch({selection:{anchor:r.from,head:r.from}}),v(e,r.from))},[e,_,v]),b=(0,W.useCallback)(e=>{_&&y(_.activeSlotIndex+e)},[_,y]),x=(0,W.useCallback)((t,n)=>{if(!e||!_)return;let r=_.slots[_.activeSlotIndex];if(r){if(_.context===`workout`){if(r.kind===`add-metric`){let t=e.state.doc.lineAt(e.state.selection.main.head),r=t.text.length>0&&!/\s$/.test(t.text),i=`${r?` `:``}${n.value}`,a=t.to+ +!!r,o=t.to+i.length;u(null),e.dispatch({changes:{from:t.to,to:t.to,insert:i},selection:{anchor:a,head:o},userEvent:`input.wheel`}),v(e,a);return}let i=n.value;if(t.id===`duration-min`||t.id===`duration-sec`){let e=_.drums.find(e=>e.id===`duration-min`),r=_.drums.find(e=>e.id===`duration-sec`);i=`${t.id===`duration-min`?n.value:e?.selectedValue??`1`}:${t.id===`duration-sec`?n.value:r?.selectedValue??`00`}`}else if(t.id===`unit-amount`||t.id===`unit-suffix`){let e=_.drums.find(e=>e.id===`unit-amount`),r=_.drums.find(e=>e.id===`unit-suffix`);i=`${t.id===`unit-amount`?n.value:e?.selectedValue??`20`}${t.id===`unit-suffix`?n.value:r?.selectedValue??`kg`}`}let a=r.from+i.length;e.dispatch({changes:{from:r.from,to:r.to,insert:i},selection:{anchor:r.from,head:a},userEvent:`input.wheel`}),v(e,r.from);return}if(_.context===`markdown`){let t=e.state.doc.line(_.lineNumber),r=e.state.selection.main,i=n.value;if(i.startsWith(`block:`)){let n=i.slice(6),r=t.text.trim().length>0?`
826
+ `:``;if(n===`time`||n===`log`){let i=`${r}\`\`\`${n}\n\n\`\`\``,a=t.to+r.length+4+n.length;u(null),e.dispatch({changes:{from:t.to,to:t.to,insert:i},selection:{anchor:a},userEvent:`input.wheel`}),v(e,a)}else if(n===`query`){let n=`${r}\`\`\`query\nsum:reps{} every week | :bar{}\n\`\`\``,i=t.to+r.length+9;u(null),e.dispatch({changes:{from:t.to,to:t.to,insert:n},selection:{anchor:i,head:i+30},userEvent:`input.wheel`}),v(e,i)}else if(n===`table`){let n=`${r}| Movement | Load | Notes |\n| --- | --- | --- |\n| Squat | 100kg | Smooth |\n`;e.dispatch({changes:{from:t.to,to:t.to,insert:n},selection:{anchor:t.to+n.length},userEvent:`input.wheel`})}else if(n===`divider`){let n=`${r}---\n`;e.dispatch({changes:{from:t.to,to:t.to,insert:n},selection:{anchor:t.to+n.length},userEvent:`input.wheel`})}return}if(i.startsWith(`prefix:`)){let n=`${i.slice(7)}${t.text.replace(/^(#{1,6}\s+|>\s+|-\s+\[[ xX]\]\s+|[-*+]\s+|\d+\.\s+)/,``)}`;e.dispatch({changes:{from:t.from,to:t.to,insert:n},selection:{anchor:t.from+n.length},userEvent:`input.wheel`}),v(e,t.from);return}if(i.startsWith(`wrap:`)){let t=i.slice(5),n=r.empty?`text`:e.state.doc.sliceString(r.from,r.to),a=`${t}${n}${t}`;e.dispatch({changes:{from:r.from,to:r.to,insert:a},selection:{anchor:r.from+t.length,head:r.from+t.length+n.length},userEvent:`input.wheel`});return}if(i.startsWith(`insert:`)){let t=i.slice(7);e.dispatch({changes:{from:r.to,to:r.to,insert:t},selection:{anchor:r.to+t.length},userEvent:`input.wheel`});return}}if(_.context===`query`){let t=e.state.doc.line(_.lineNumber),r=n.value;if(r.startsWith(`replace:`)){let n=r.slice(8);e.dispatch({changes:{from:t.from,to:t.to,insert:n},selection:{anchor:t.from+n.length},userEvent:`input.wheel`})}else if(r.startsWith(`append:`)){let n=r.slice(7);t.text.includes(n.trim())||e.dispatch({changes:{from:t.to,to:t.to,insert:n},selection:{anchor:t.to+n.length},userEvent:`input.wheel`})}}}},[e,_,v]),S=(0,W.useCallback)(()=>{if(!e)return;let t=e.state.selection.main.head,n=e.state.doc.lineAt(t),r=n.text.match(/^(\s*)/),i=`\n${r?r[1]:``}`,a=n.to+i.length;u(null),e.dispatch({changes:{from:n.to,to:n.to,insert:i},selection:{anchor:a},userEvent:`input.wheel`}),v(e,a)},[e,v]),C=(0,W.useCallback)(()=>{e&&(e.contentDOM.setAttribute(`inputmode`,`text`),a(!0),e.focus())},[e,a]),w=(0,W.useCallback)(()=>{e&&(e.contentDOM.setAttribute(`inputmode`,`none`),a(!1),e.focus())},[e,a]),T=(0,W.useCallback)(()=>{e?.contentDOM.blur(),o()},[e,o]),E=(0,W.useCallback)((e,t)=>{f.current={x:e,y:t}},[]),D=(0,W.useCallback)((e,t)=>{let n=f.current;if(f.current=null,!n)return;let r=e-n.x,i=t-n.y;Math.abs(r)>=28&&Math.abs(r)>Math.abs(i)*1.2&&b(r<0?1:-1)},[b]);if(!r||!e||!_)return null;if(i)return(0,G.jsxs)(`div`,{"data-testid":`mobile-typing-bar`,style:{bottom:`${p}px`},className:`fixed inset-x-0 z-40 h-10 flex items-center justify-between gap-1.5 px-2.5 bg-[#F7F6F3] dark:bg-card border-t border-border select-none`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-return-wheel-btn`,onMouseDown:e=>e.preventDefault(),onClick:w,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-[4px] border border-border bg-background text-foreground text-xs font-medium hover:bg-muted transition-colors`,children:[(0,G.jsx)(oee,{weight:`bold`,className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:`Wheel`})]}),(0,G.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Ci(e),"aria-label":`Indent line`,className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground hover:bg-muted transition-colors`,children:(0,G.jsx)(tn,{weight:`bold`,className:`h-3.5 w-3.5`})}),(0,G.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:S,className:`inline-flex items-center gap-1 h-7 px-2 rounded-[4px] border border-border bg-background text-foreground text-xs font-medium hover:bg-muted transition-colors`,children:[(0,G.jsx)(Rt,{weight:`bold`,className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Line`})]})]}),(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-wheel-done-btn`,onMouseDown:e=>e.preventDefault(),onClick:T,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-[4px] bg-foreground text-background text-xs font-medium`,children:[(0,G.jsx)(g,{weight:`bold`,className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:`Done`})]})]});let O=_.slots[_.activeSlotIndex],k=_.context===`workout`&&O?.kind===`metric`;return(0,G.jsxs)(`section`,{"aria-label":`Mobile workout and note wheel composer`,"data-testid":`mobile-wheel-composer`,onMouseDown:e=>{e.target.tagName!==`INPUT`&&e.preventDefault()},onTouchStart:e=>{let t=e.touches[0];t&&E(t.clientX,t.clientY)},onTouchEnd:e=>{let t=e.changedTouches[0];t&&D(t.clientX,t.clientY)},className:`fixed inset-x-0 bottom-0 z-40 h-[40dvh] max-h-[300px] min-h-[216px] flex flex-col bg-[#F7F6F3] dark:bg-card border-t border-border select-none`,children:[(0,G.jsxs)(`div`,{className:`h-10 px-2.5 flex items-center justify-between gap-1.5 border-b border-border bg-background/70`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,"data-testid":`mobile-wheel-prev-slot`,"aria-label":`Previous slot`,disabled:_.activeSlotIndex<=0,onClick:()=>b(-1),className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground disabled:opacity-35 hover:bg-muted transition-colors`,children:(0,G.jsx)(rt,{weight:`bold`,className:`h-3.5 w-3.5`})}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`mobile-wheel-next-slot`,"aria-label":`Next slot`,disabled:_.activeSlotIndex>=_.slots.length-1,onClick:()=>b(1),className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground disabled:opacity-35 hover:bg-muted transition-colors`,children:(0,G.jsx)(Ar,{weight:`bold`,className:`h-3.5 w-3.5`})}),(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-wheel-newline-btn`,onClick:S,className:`inline-flex items-center gap-1 h-7 px-2 rounded-[4px] border border-border bg-background text-foreground text-xs font-medium hover:bg-muted transition-colors`,children:[(0,G.jsx)(Rt,{weight:`bold`,className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Line`})]}),(0,G.jsx)(`button`,{type:`button`,"aria-label":`Outdent line`,onClick:()=>hee(e),className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground hover:bg-muted transition-colors`,children:(0,G.jsx)(ree,{weight:`bold`,className:`h-3.5 w-3.5`})}),(0,G.jsx)(`button`,{type:`button`,"aria-label":`Indent line`,onClick:()=>Ci(e),className:`inline-flex items-center justify-center h-7 w-7 rounded-[4px] border border-border bg-background text-foreground hover:bg-muted transition-colors`,children:(0,G.jsx)(tn,{weight:`bold`,className:`h-3.5 w-3.5`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-wheel-type-btn`,onClick:C,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-[4px] border border-border bg-background text-foreground text-xs font-medium hover:bg-muted transition-colors`,children:[(0,G.jsx)(Kt,{weight:`bold`,className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:`Type`})]}),(0,G.jsxs)(`button`,{type:`button`,"data-testid":`mobile-wheel-done-btn`,onClick:T,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-[4px] bg-foreground text-background text-xs font-medium`,children:[(0,G.jsx)(g,{weight:`bold`,className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:`Done`})]})]})]}),(0,G.jsxs)(`div`,{"data-testid":`mobile-wheel-slot-rail`,onPointerDown:e=>E(e.clientX,e.clientY),onPointerUp:e=>D(e.clientX,e.clientY),className:`h-9 px-2.5 flex items-center gap-1.5 overflow-x-auto border-b border-border scrollbar-none`,children:[(0,G.jsxs)(`span`,{className:`shrink-0 text-[10px] font-mono tabular-nums uppercase tracking-[0.05em] text-muted-foreground pr-1`,children:[`L`,_.lineNumber]}),_.slots.map((e,t)=>{let n=t===_.activeSlotIndex,r=e.kind===`add-metric`;return(0,G.jsx)(`button`,{type:`button`,"data-testid":`mobile-wheel-slot-${e.kind===`add-metric`?`add`:t}`,onClick:()=>y(t),className:K(`shrink-0 h-6 px-2.5 rounded-[4px] text-xs font-mono tabular-nums border transition-colors`,n?`bg-foreground text-background border-foreground font-semibold`:r?`bg-background text-foreground border-dashed border-border hover:bg-muted`:`bg-background text-muted-foreground border-border hover:text-foreground`),children:e.label},e.id)})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 flex divide-x divide-border`,children:_.drums.map(e=>(0,G.jsx)($2,{drum:e,autoCommitOnScroll:k,onSelect:t=>x(e,t)},e.id))})]})},t4=({view:e,cursorVersion:t,disabled:n=!1})=>{let[r,i]=(0,W.useState)(null);if((0,W.useEffect)(()=>{if(!e||n||e.state.readOnly){i(null);return}let t=e.state.selection.main;if(t.empty||!e.hasFocus){i(null);return}let r=EO(e.state);if(!r||r.type!==`markdown`){i(null);return}let a=e.coordsAtPos(t.from),o=e.coordsAtPos(t.to),s=e.dom.getBoundingClientRect();if(!a||!o){i(null);return}let c=(a.left+o.right)/2-s.left,l=Math.max(96,Math.min(s.width-96,c)),u=a.top-s.top-38,d=u<4?o.bottom-s.top+6:u;i({top:d,left:l})},[e,t,n]),!r||!e)return null;let a=[{id:`bold`,label:`Bold (Ctrl+B)`,Icon:fn,run:()=>{PO(e,`**`),e.focus()}},{id:`italic`,label:`Italic (Ctrl+I)`,Icon:wr,run:()=>{PO(e,`*`),e.focus()}},{id:`strike`,label:`Strikethrough`,Icon:Zt,run:()=>{PO(e,`~~`),e.focus()}},{id:`code`,label:`Inline code (Ctrl+E)`,Icon:Qe,run:()=>{PO(e,"`"),e.focus()}},{id:`link`,label:`Insert link (Ctrl+K)`,Icon:dee,run:()=>{FO(e),e.focus()}},{id:`timer`,label:`Wrap in timer block`,Icon:mr,run:()=>{let t=e.state.selection.main;if(t.empty)return;let n=e.state.doc.sliceString(t.from,t.to),r=`\n\`\`\`time\n${n}\n\`\`\`\n`;e.dispatch({changes:{from:t.from,to:t.to,insert:r},selection:{anchor:t.from+9,head:t.from+9+n.length},userEvent:`input.format`}),e.focus()}}];return(0,G.jsx)(`div`,{role:`toolbar`,"aria-label":`Text formatting`,"data-testid":`selection-format-bar`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},style:{position:`absolute`,top:`${r.top}px`,left:`${r.left}px`,transform:`translateX(-50%)`,boxShadow:`0 2px 8px rgba(0, 0, 0, 0.04)`},className:`z-30 hidden lg:inline-flex items-center gap-0.5 px-1 py-0.5 rounded-[6px] bg-card border border-border text-foreground`,children:a.map(({id:e,label:t,Icon:n,run:r})=>(0,G.jsx)(`button`,{type:`button`,title:t,"aria-label":t,"data-testid":`format-bar-${e}`,onClick:r,className:`inline-flex items-center justify-center h-6 w-6 rounded-[4px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:(0,G.jsx)(n,{weight:`bold`,className:`h-3.5 w-3.5`})},e))})},n4=new zi,r4=new zi,i4=new zi,a4=new zi;async function o4(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 s4(e){let t=await o4(`\`\`\`time\n${e.trimEnd()}\n\`\`\`\n`);return`${window.location.origin}/load?zip=${t}`}async function c4(e){let t=await o4(`\`\`\`time\n${e.trimEnd()}\n\`\`\`\n`),n=`shared by ${iw()}`;return`${window.location.origin}/?z=${t}&by=${encodeURIComponent(n)}`}var l4=({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=``,ariaLabel:g=`Note editor`,onStartWorkout:_,onCompleteWorkout:v,onBlocksChange:y,onAddToPlan:b,notePersistence:x,onViewCreated:S,mode:C=`edit`,lineWrapping:w=!0,showLineNumbers:T=!0,enablePreview:E=!0,showFrontmatter:D=!0,enableLinting:O=!0,enableOverlay:k=!1,commands:A,hideDefaultCommands:j=!1,enableInlineRuntime:M=!0,extensions:N,widgetComponents:P,activeSectionId:F,scrollToSectionId:I,results:ee,placeholder:L})=>{let te=(0,W.useRef)(null),R=(0,W.useRef)(null),ne=(0,W.useRef)(null),z=(0,W.useRef)(``),B=p===`dark`||p===`vs-dark`,{isDebugMode:V}=VS(),re=r0(ne,x),[ie,ae]=(0,W.useState)(null),[oe,se]=(0,W.useState)([]),[ce,le]=(0,W.useState)(1),[H,ue]=(0,W.useState)(0),U=F??ie,de=E0(oe,U),[fe,me]=(0,W.useState)(null),[he,ge]=(0,W.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches),[_e,ve]=(0,W.useState)(!1),[ye,be]=(0,W.useState)(!1);(0,W.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(max-width: 1023px)`),t=e=>{ge(e.matches),e.matches||(ve(!1),be(!1))};return ge(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[xe,Se]=(0,W.useState)(null),[Ce,we]=(0,W.useState)(null),[Te,Ee]=(0,W.useState)(!1),De=(0,W.useRef)(null),Oe=(0,W.useRef)(!1),ke=(0,W.useRef)(n??0);(0,W.useEffect)(()=>{ke.current=n??0},[n]);let[Ae,je]=(0,W.useState)(null),Me=(0,W.useRef)(null),Ne=(0,W.useCallback)(async(t,n=!1)=>{let r=R.current;if(!(!r||Oe.current)){Oe.current=!0,je(null);try{let o=await a?.();typeof o==`number`&&(ke.current=o);let s=r.state.field(CO),c=await TF({noteId:e??xr(),rawContent:s.rawContent,blocks:s.noteBlocks,expectedSourceRevision:ke.current,...e?{}:{metadata:{title:`Playground workout`},noteType:`playground`}},t,xr(),e?void 0:`playground`,re);De.current=c,Me.current=null,ke.current=c.note.sourceRevision,r.dispatch({effects:hO.of({blocks:c.note.blocks,sourceRevision:c.note.sourceRevision})}),i?.({rawContent:c.note.rawContent,blocks:c.note.blocks,sourceRevision:c.note.sourceRevision}),Ee(n),Se(c.block),we(c.session.id)}catch(e){je(e instanceof Error?e.message:String(e))}finally{Oe.current=!1}}},[e,re,i,a]),Pe=(0,W.useCallback)(()=>{Se(null),we(null),Ee(!1)},[]),Ie=(0,W.useCallback)(e=>{M&&Ne(e,!0)},[M,Ne]);(0,W.useEffect)(()=>qK({noteId:e,readonly:!!m,sourceRevision:n,getValue:()=>R.current?.state.doc.toString()??c,getView:()=>R.current,getBlocks:()=>{let e=R.current;return e?e.state.field(CO).sections.filter(e=>e.type===`time`||e.type===`log`).map(t=>m4(t,e.state)).filter(e=>e!==null):[]},applyEdit:async(e,t=!1)=>{if(m)throw Error(`Editor is in read-only mode. Clone this Note before editing.`);let n=R.current;if(!n){l(e),t&&await(o??s)?.();return}let r=n.state.doc.length;n.dispatch({changes:{from:0,to:r,insert:e}}),l(e),t&&await(o??s)?.()},undoEdit:()=>{let e=R.current;if(!e||m)return!1;let t=Qi(e);return t&&l(e.state.doc.toString()),t},startLiveWorkout:async(e,t=!0)=>{let n=R.current;if(!n)return{started:!1,error:`Editor view is not mounted.`};let r=n.state.field(CO).sections.filter(e=>e.type===`time`||e.type===`log`).map(e=>m4(e,n.state)).filter(e=>e!==null),i=e?r.find(t=>t.id===e):r[0];return i?(await Ne(i,t),{started:!0,blockId:i.id}):{started:!1,error:e?`Workout block '${e}' not found in editor.`:"No runnable ```time workout block found in editor."}}}),[e,m,n,c,l,o,s,Ne]);let Le=(0,W.useRef)(null),Re=(0,W.useCallback)((e,t)=>{let n=Le.current,r=n!==null&&n.results===t,i=De.current;if(!i||!t)return Promise.reject(Error(`The saved run pin is unavailable.`));let a=i.session.id;if(Me.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=kj(t.state,e,a);if(n){let e=n.from+n.insert.indexOf("```");t.dispatch({changes:n,effects:[si.scrollIntoView(e,{y:`start`,yMargin:96})]}),l?.(t.state.doc.toString())}}r||(Le.current={results:t,resultId:a,runBlock:o});let s;try{s=KN(re).record({resultId:a,noteId:i.session.noteId,blockId:i.session.blockId,data:t,createdAt:t.endTime}).then(()=>v?.(e,t,a,o))}catch(e){return Promise.reject(e instanceof Error?e:Error(String(e)))}return Promise.resolve(s).then(()=>{Le.current?.results===t&&(Le.current=null),Me.current=a},()=>{}),s},[l,v,re]),ze=(0,W.useMemo)(()=>{if(j)return[];if(A&&A.length>0)return A;let e=[];return M?e.push({id:`run`,label:`Run`,icon:(0,G.jsx)(bt,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:Ne}):_&&e.push({id:`run`,label:`Run`,icon:(0,G.jsx)(bt,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:_}),e.push({id:`playground`,label:`Playground`,icon:(0,G.jsx)(Nr,{className:`h-3 w-3`}),splitIcon:(0,G.jsx)(Fe,{className:`h-3 w-3`}),splitSuccessIcon:(0,G.jsx)(xt,{className:`h-3 w-3`}),onClick:e=>{s4(e.content).then(e=>{let t=window.open(e,`wodwiki-playground`);t&&t.focus()})},onSplitClick:async e=>{let t=await c4(e.content);await navigator.clipboard.writeText(t)}}),b&&e.push({id:`plan`,label:`Plan`,icon:(0,G.jsx)(ut,{className:`h-3 w-3`}),onClick:b}),e},[A,_,b,M,j,Ne]),Be=(0,W.useMemo)(()=>Hi({codeLanguages:yM}),[]),Ve=(0,W.useMemo)(()=>{let e=Math.max(1,n),r=P?[...P.keys()]:co;if(t&&Object.keys(t).length>0)try{return ho(c,t,e,{registeredWidgets:r}),t}catch{return mo(c,{sourceRevision:e,blocks:t,registeredWidgets:r})}return mo(c,{sourceRevision:e,registeredWidgets:r})},[c,t,n,P]),He=(0,W.useMemo)(()=>[...T?[Ni(),pee()]:[],qi(),Li(),bi(),Si(),...w?[si.lineWrapping]:[],Oi.allowMultipleSelections.of(!0),Qr(),gi(),Xr(),Ki(),Yi.highest(Ui.of([{key:`Tab`,run:e=>Fi(e.state)!==null&&($r(e),!0)},{key:`Enter`,run:e=>{let t=e.state.selection.main,n=p4(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:(ei(e),$i(e))}}])),Ui.of([...ti,...gee,...Bi,...vee,...Mi,...di,...Wi,Xi,{key:`Mod-s`,run:()=>(o?.(),!0)},{key:`Ctrl-.`,run:e=>{let t=h0(e.state);if(!t?.focusedMetric)return!1;let n=t.focusedMetric.type;return!new Set([`duration`,`rep`,`rounds`,`distance`,`resistance`]).has(n)&&(pe(()=>Promise.resolve().then(()=>PJ).then(()=>{pe(async()=>{let{runStatementBuilderFlow:e}=await import(`./statementBuilderFlow-CILJ_dtU.js`);return{runStatementBuilderFlow:e}},__vite__mapDeps([0,1,2,3])).then(({runStatementBuilderFlow:n})=>{n(t,e)}).catch(()=>{FJ.getState().open({placeholder:`Modify metric…`,sources:[]})})}),void 0),!0)}}]),Fj,CO,fO.of({blocks:Ve,sourceRevision:Math.max(1,n),rawContent:c}),pO.of(P?[...P.keys()]:co),wO,xk.of(D),Sk.of(V),...E||!D?[dA]:[],...E?[nO,ok,mk,a0(e),F1(),W1(),XA,HA(),mj]:[],...O?[kO]:[],ZO,cD,zO,RO,BO.of(u4),VO.of(d4),...k?[Ij]:[],$O,iO.of(null),cO.of(e=>{if(/^(https?:|mailto:|tel:)/i.test(e)){window.open(e,`_blank`,`noopener,noreferrer`);return}if(e.startsWith(`/`)&&typeof window<`u`){window.history.pushState({},``,e),window.dispatchEvent(new PopStateEvent(`popstate`));return}typeof window<`u`&&window.location.assign(e)}),dO,v0,...bj,rO,...P&&P.size>0?[vM(P)]:[],Jj({executor:jW,onResultSaved:GN,readOnly:m,onCaptureRpe:m?void 0:async(e,t)=>{await RF(e,t)},onEditMetric:m?void 0:async(e,t)=>{if(await LF({resultId:e,occurrence:t.occurrence,metric:{type:t.metric.type,value:t.metric.value,image:t.metric.image}})===`not-found`)throw Error(`Result segment not found in storage.`)},noteHref:e=>eH(`blockContentId`in e||`dataType`in e?IV(e):AV(e))}),o0(e,re),si.domEventHandlers({focus:()=>(typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches&&!m&&ve(!0),!1),blur:e=>{let t=e.relatedTarget;return(!t||!te.current?.contains(t))&&(ve(!1),be(!1)),f?.(),!1}}),si.updateListener.of(e=>{if(e.docChanged){let t=e.state.field(CO);r?.({rawContent:t.rawContent,blocks:t.noteBlocks,sourceRevision:t.sourceRevision}),l(t.rawContent),u?.(e),h4(e.state,y,z),e.transactions.some(e=>e.isUserEvent(`input`)&&!e.isUserEvent(`input.wheel`)&&!e.isUserEvent(`input.format`)||e.isUserEvent(`delete`)||e.isUserEvent(`paste`)||e.isUserEvent(`drop`))||s?.()}if(e.selectionSet||e.docChanged){ue(e=>e+1),e.transactions.some(e=>e.isUserEvent(`delete.backward`))&&Fi(e.startState)!==null&&Fi(e.state)===null&&p4(e.state,e.state.selection.main.head)?.value===``&&queueMicrotask(()=>{e.view.state===e.state&&ni(e.view)});let{head:t}=e.state.selection.main,n=e.state.doc.lineAt(t);d?.(n.number,t-n.from+1);let r=EO(e.state);ae(r?.id??null),le(n.number);let{sections:i}=e.state.field(CO);se(i)}}),Oi.readOnly.of(m),si.editable.of(!m),...L?[Ti(L)]:[],si.contentAttributes.of({"aria-label":g})],[l,d,f,u,y,r,m,o,s,T,w,E,D,V,O,k,e,re,P,L,g]);(0,W.useEffect)(()=>{let e=te.current;if(!e)return;let t;try{t=Oi.create({doc:c,extensions:[...He,n4.of(QD(B)),r4.of(Be),i4.of([]),a4.of(si.contentAttributes.of({inputmode:he&&!ye?`none`:`text`})),...N??[]]})}catch(e){console.error(`NoteEditor: Failed to initialize EditorState, recovering with safe fallback`,e),t=Oi.create({doc:c,extensions:[n4.of(QD(B)),r4.of(Be)]})}let n=new si({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:si.scrollIntoView(n.state.selection.main.head,{y:`nearest`,yMargin:24})})})};i?.addEventListener(`resize`,o),n.contentDOM.addEventListener(`focus`,o),R.current=n,me(n),e.__codemirrorView=n,S?.(n);let{sections:s}=n.state.field(CO);se(s);let l=n.state.doc.lineAt(n.state.selection.main.head).number;le(l);let u=EO(n.state);ae(u?.id??null);let d=n.state.field(CO);return r?.({rawContent:d.rawContent,blocks:d.noteBlocks,sourceRevision:d.sourceRevision}),h4(n.state,y,z),()=>{cancelAnimationFrame(a),i?.removeEventListener(`resize`,o),n.contentDOM.removeEventListener(`focus`,o),delete e.__codemirrorView,me(null),n.destroy()}},[]),(0,W.useEffect)(()=>{let e=R.current;if(!e)return;let r=e.state.field(CO);if(c!==r.rawContent){let r=Math.max(1,n),i=t?mo(c,{sourceRevision:r,blocks:t,registeredWidgets:P?[...P.keys()]:co}):void 0,a=i&&t&&Object.keys(i).length===Object.keys(t).length&&Object.entries(t).every(([e,t])=>{let n=i[e];return n&&n.from===t.from&&n.to===t.to&&n.kind===t.kind&&n.dialect===t.dialect&&n.sport===t.sport});e.dispatch({changes:{from:0,to:e.state.doc.length,insert:c},...a?{effects:gO.of({rawContent:c,blocks:t,sourceRevision:r})}:{}})}else t&&n!==r.sourceRevision&&e.dispatch({effects:hO.of({blocks:t,sourceRevision:Math.max(1,n)})})},[c,t,n]),(0,W.useEffect)(()=>{R.current&&R.current.dispatch({effects:n4.reconfigure(QD(B))})},[B]);let Ue=(0,W.useRef)(he);Ue.current=he;let We=(0,W.useRef)(ye);return We.current=ye,(0,W.useEffect)(()=>{if(R.current){let e=[];R.current.dispatch({effects:[ji.reconfigure.of([...He,n4.of(QD(B)),r4.of(Be),i4.of(e),a4.of(si.contentAttributes.of({inputmode:Ue.current&&!We.current?`none`:`text`})),...N??[]])]})}},[He,N,C,B,Be]),(0,W.useEffect)(()=>{R.current&&R.current.dispatch({effects:a4.reconfigure(si.contentAttributes.of({inputmode:he&&!ye?`none`:`text`}))})},[he,ye]),(0,W.useEffect)(()=>{let e=typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches;!m&&!e&&R.current?.focus()},[m]),(0,W.useEffect)(()=>{if(I&&R.current){let e=R.current,t=e.state.doc.toString().split(`
827
827
  `),n=-1,r=I.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,`-`)===I}return!1}),n>=0&&n<t.length){let t=e.state.doc.line(n+1).from;e.dispatch({selection:{anchor:t,head:t},effects:[si.scrollIntoView(t,{y:`start`,yMargin:20})]})}}},[I]),(0,G.jsxs)(G.Fragment,{children:[e&&!xe?(0,G.jsx)(m1,{noteId:e}):null,(0,G.jsxs)(`div`,{ref:te,className:`cm-note-editor relative w-full min-w-0 ${he&&_e&&!ye&&!m?`pb-[42dvh]`:``} ${h}`,children:[k&&(0,G.jsx)(x0,{view:fe??R.current,widths:de.widths,activeSectionId:U,renderSlot:t=>{if(!D&&t.sectionType===`frontmatter`)return null;if(t.sectionType===`time`||t.sectionType===`log`)return(0,G.jsx)(X0,{noteId:e,sectionId:t.sectionId,view:t.view,isActive:t.isActive,widthPercent:t.widthPercent,cursorLine:ce,docVersion:t.docVersion,commands:ze,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(CO),n=e.find(e=>e.id===t.sectionId);return(0,G.jsx)(A0,{sectionId:t.sectionId,section:n,view:t.view,isActive:t.isActive,widthPercent:t.widthPercent,docVersion:t.docVersion})}return t.sectionType===`widget`&&t.widgetName?(0,G.jsx)(Z0,{sectionId:t.sectionId,widgetName:t.widgetName,view:t.view,registry:P??new Map,docVersion:t.docVersion}):(0,G.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,G.jsx)(`div`,{className:`font-medium text-foreground`,children:t.sectionType})})},cursorLine:ce}),Ae&&(0,G.jsxs)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:[`Workout not started. `,Ae,` Your draft is kept.`]}),!k&&ze.length>0&&(0,G.jsx)(_2,{view:fe??R.current,commands:ze}),!m&&!he&&(0,G.jsx)(t4,{view:fe??R.current,cursorVersion:H}),(0,G.jsx)(w2,{view:fe??R.current,cursorVersion:H,hidden:he&&_e}),he&&!m&&(0,G.jsx)(e4,{view:fe??R.current,noteId:e,cursorVersion:H,isOpen:_e,isTypingMode:ye,onSwitchToTyping:be,onClose:()=>{ve(!1),be(!1)}}),xe&&R.current&&(0,G.jsx)(u2,{block:xe,view:fe??R.current,onClose:Pe,onCompleteWorkout:Re,resultId:Ce??void 0,noteId:e,autoStart:Te}),(0,G.jsx)(v2,{sections:oe,isRuntimeActive:xe!==null,editorState:(fe??R.current)?.state??null,onSelectBlock:Ie})]})]})},u4=async e=>{if(!f4(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=p4(e.state,e.pos);if(!n&&!r)return null;let[i,a]=await Promise.all([X.getAllTagTypes().catch(()=>[]),X.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)&&f4(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 G1();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=p4(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=p4(r,n);return/^[\w-]*$/.test(e)&&i?.propertyKey===o&&i.from===t}}},d4=K1();function f4(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 p4(e,t){if(!f4(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 m4(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=pl({tags:oF()}).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(CO).noteBlocks[e.id]?.version??1,createdAt:Date.now(),widgetIds:{}}}function h4(e,t,n){if(!t)return;let r=e.field(CO).sections.filter(e=>e.type===`time`||e.type===`log`).map(t=>m4(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 g4({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,W.useRef)([]),E=(0,W.useCallback)(e=>{T.current=e,a?.(e)},[a]),D=(0,W.useCallback)(()=>{v?.onRun(n,T.current[0]??null)},[v,n]),O=(0,G.jsxs)(G.Fragment,{children:[y,v&&(0,G.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,G.jsx)(bt,{size:11,fill:`currentColor`}),v.label??`Run`]})]});return(0,G.jsx)(N1,{title:e,subtitle:t,onReset:_,headerActions:O,className:S,children:(0,G.jsxs)(`div`,{className:`flex h-full flex-col min-h-0`,children:[b,(0,G.jsxs)(`div`,{ref:w,className:K(`relative flex-1 min-h-0`,C),children:[(0,G.jsx)(l4,{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 _4({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,G.jsx)(`div`,{className:`h-full`,style:{opacity:t,transition:`opacity 180ms ease`},children:(0,G.jsx)(g4,{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,G.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,G.jsx)(`span`,{children:`Try editing this example ↓`}),e===n?null:(0,G.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 v4(e,t){return e>=t?`split`:`stack`}function y4(e,t){let n=(0,W.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:v4(t,n)}},[e]),[r,i]=(0,W.useState)(n);return(0,W.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:v4(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 b4=e=>Math.max(0,Math.min(1,e)),x4=(e,t,n)=>e+(t-e)*n,S4=e=>1-(1-e)**2;function C4(e,t){return e===``||t===e}var w4={id:``,range:[0,1]};function T4(e,t){if(!t||t.length===0)return{index:-1,stage:w4,t:0,ring:null};let n=b4(e),r=t.map(e=>({...e,start:b4(Math.min(e.range[0],e.range[1])),end:b4(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]??w4,o=(a.end??1)-(a.start??0),s=o>0?b4((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 E4(e,t,n){let r=t-n;return{progress:r>0?b4(-e/r):0,reached:e<=0,inView:e<n&&e+t>0}}function D4(e,t){let n=t/2;for(let t of e)if(t.top<=n&&t.bottom>n)return t.id;return null}var O4=(0,W.createContext)(null);function k4(){return(0,W.useContext)(O4)}function A4({children:e}){let t=(0,W.useRef)(new Map),n=(0,W.useRef)(new Map),r=(0,W.useRef)(null),i=(0,W.useRef)(0),[a,o]=(0,W.useState)(null),s=(0,W.useRef)(null),c=(0,W.useCallback)(e=>{r.current?.gateId===e&&(r.current=null,o(null))},[]),l=(0,W.useCallback)((e,t)=>{r.current={gateId:e,segmentId:t},o(e)},[]),u=(0,W.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=D4(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=E4(r.top,r.height,e);t.onMeasure({slice:T4(i.progress,t.getStages()),progress:i.progress,reached:i.reached})})},[]),d=(0,W.useCallback)(()=>{i.current||=requestAnimationFrame(u)},[u]);(0,W.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,W.useCallback)((e,n)=>(t.current.set(e,n),d(),()=>{t.current.delete(e)}),[d]),p=(0,W.useCallback)((e,t)=>(n.current.set(e,t),d(),()=>{n.current.delete(e)}),[d]),m=(0,W.useCallback)(()=>u(),[u]),h=(0,W.useMemo)(()=>({registerAnchor:f,registerDriver:p,resync:m,capturedGateId:a,captureGate:l,releaseGate:c}),[f,p,m,a,l,c]);return(0,G.jsx)(O4.Provider,{value:h,children:e})}function j4(e,t){let n=k4()?.registerAnchor;(0,W.useEffect)(()=>{if(n)return n(e,()=>t.current)},[n,e,t])}function M4({gateId:e,segmentId:t,className:n,children:r}){let i=k4(),a=(0,W.useRef)(null),[o,s]=(0,W.useState)(!1);if((0,W.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,G.jsx)(`div`,{className:n,children:r});let c=i.capturedGateId===e?`captured`:`yield`;return(0,G.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,G.jsx)(`div`,{ref:a,className:`relative min-h-0 flex-1`,children:r}),(o||c===`captured`)&&(0,G.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":`${c===`captured`?`Scroll page`:`Scroll panel`}: ${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 N4({trackRef:e,height:t,stages:n,activeIndex:r,pane:i,captions:a,status:o,segmentId:s,testId:c,className:l}){let[u,d]=(0,W.useState)(null),f=y4(104,u).mode===`split`,p={status:o,pips:(0,G.jsx)(`div`,{className:`flex items-center gap-1.5`,"aria-hidden":`true`,children:n.map((e,t)=>{let n=r===t;return(0,G.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,G.jsx)(`section`,{ref:e,"data-testid":c,className:l?`relative ${l}`:`relative`,style:{height:t},children:(0,G.jsx)(j1.Provider,{value:p,children:(0,G.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,G.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,G.jsx)(`div`,{className:`relative min-h-0 min-w-0 flex-[3_1_0%]`,children:i}),(0,G.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-[2_1_0%] flex-col`,children:s?(0,G.jsx)(M4,{gateId:`${s}-captions`,segmentId:s,className:`relative min-h-0 flex-1`,children:a}):(0,G.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:a})})]})})})})}function P4(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 F4(e,t,n=`smooth`){let r=P4(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 I4(e,t,n,r){let[i,a]=(0,W.useState)(()=>T4(0,n)),[o,s]=(0,W.useState)(!1),c=(0,W.useRef)(0),l=(0,W.useRef)(i),u=(0,W.useRef)(new Set),d=(0,W.useRef)(0),f=(0,W.useRef)(t);f.current=t;let p=k4(),m=p?.registerDriver,h=(0,W.useRef)(p);h.current=p;let g=(0,W.useId)(),_=r??g,v=(0,W.useRef)(n);v.current=n;let y=(0,W.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,W.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(T4(i,v.current),i)},[e,y]),x=(0,W.useCallback)(()=>{if(h.current){h.current.resync();return}b()},[b]),S=(0,W.useCallback)(()=>{d.current||=requestAnimationFrame(x)},[x]);(0,W.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,W.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,W.useCallback)(e=>(u.current.add(e),e(l.current,c.current),()=>{u.current.delete(e)}),[]),w=(0,W.useCallback)(()=>{x()},[x]);return{slice:i,progress:c.current,runwayReached:o,subscribe:C,resync:w}}var L4={reference:!0},R4={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`]],"metrics-summaries":[[`frontmatter-metrics`,`tag-summaries`,`stacking-overrides`],[`querying-summaries`,`dependency-diagnostics`,`try-it`]]};function z4(e,t){let n=e.filter(e=>!L4[e.id]),r=e.filter(e=>L4[e.id]);if(n.length===0)return{groups:[],tail:r};let i=t?R4[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 B4(e){let t=Math.max(1,e.length);return e.map((e,n)=>({id:e.id,range:[n/t,(n+1)/t]}))}var V4=[{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 H4({slides:e=V4,className:t}){let n=(0,W.useRef)(null),[r,i]=(0,W.useState)(0);(0,W.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,G.jsxs)(`div`,{className:K(`relative w-full`,t),children:[(0,G.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,G.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,G.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,G.jsx)(`img`,{src:t.src,alt:t.alt,loading:n===0?`eager`:`lazy`,className:`h-full w-full object-cover`})}),(0,G.jsxs)(`div`,{className:`flex w-full flex-col gap-2 sm:w-1/2 sm:gap-3`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-black uppercase tracking-[0.24em] text-primary/80`,children:t.eyebrow}),(0,G.jsx)(`h3`,{className:`text-2xl font-black tracking-[-0.04em] text-foreground sm:text-3xl`,children:t.title}),(0,G.jsx)(`p`,{className:`text-sm leading-7 text-muted-foreground sm:text-base`,children:t.caption}),(0,G.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-2 text-[10px] font-black uppercase tracking-[0.2em] text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`text-primary`,children:[`Step `,n+1]}),(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,G.jsx)(`span`,{children:e.length})]})]})]},t.src))}),(0,G.jsx)(`div`,{className:`mt-4 flex items-center justify-center gap-2`,children:e.map((e,t)=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>a(t),"aria-label":`Go to slide ${t+1}: ${e.title}`,"aria-current":t===r?`true`:`false`,className:K(`h-2 rounded-full transition-all`,t===r?`w-8 bg-primary`:`w-2 bg-border hover:bg-muted-foreground/40`)},e.src))})]})}var U4=`wodwiki:text-filter-navigation`,W4=({paramName:e=`q`,placeholder:t=`Search…`,autoFocus:n=!1,className:r,navigationScope:i,inputTestId:a})=>{let[o,s]=ie(e,{defaultValue:``}),c=i??e,l=(0,W.useRef)(null);return(0,W.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,G.jsxs)(`div`,{className:K(`flex items-center gap-3 px-6 lg:px-10 pb-3`,r),children:[(0,G.jsx)(An,{className:`size-5 text-muted-foreground shrink-0`}),(0,G.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(U4,{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,G.jsx)(`button`,{onClick:()=>s(``),"aria-label":`Clear`,className:`text-muted-foreground hover:text-foreground transition-colors text-lg leading-none`,children:`×`})]})};function G4(e){let t=[],n=!1;for(let r of e){if(r.trim()===`---`){n=!n;continue}n||t.push(r)}return t}function K4(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 q4(e){return new Date(e).toISOString().slice(0,10)}function J4(e,t){let n=t.trim().toLowerCase();return!n||e.name.toLowerCase().includes(n)||e.content.toLowerCase().includes(n)||e.date!==void 0&&q4(e.date).includes(n)}function Y4(e){if(!e)return null;let t=G4(jo(e).split(`
828
828
  `)).map(e=>e.trim()).filter(e=>e.length>0&&!e.startsWith(`#`)&&!e.startsWith("```"))[0];return t?K4(t):null}var X4=({category:e,workoutItems:t,onSelect:n,showSearch:r=!0,variant:i=`card`,className:a,navigationScope:o=`q`,getItemActions:s})=>{let[c]=ie(`q`,{defaultValue:``}),[l,u]=(0,W.useState)(0),[d,f]=(0,W.useState)(0),p=(0,W.useRef)([]),m=(0,W.useMemo)(()=>t.filter(t=>t.category===e&&t.name.toLowerCase()!==`readme`).filter(e=>J4(e,c)),[t,e,c]),h=(0,W.useMemo)(()=>m.map(e=>({item:e,preview:Y4(e.content),actions:s?.(e)??[{id:`open`,label:`Open`,onSelect:n}]})),[m,s,n]);return(0,W.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,W.useEffect)(()=>{p.current=[]},[h]),(0,W.useEffect)(()=>{u(0),f(0)},[c]),(0,W.useEffect)(()=>{(p.current[l]?.[d])?.scrollIntoView({block:`nearest`,inline:`nearest`})},[d,l]),(0,W.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(U4,e),()=>{window.removeEventListener(U4,e)}},[h,o,d,l]),(0,G.jsxs)(`div`,{className:K(`flex flex-col`,i===`card`&&`rounded-3xl border border-border bg-card overflow-hidden shadow-2xl shadow-black/5`,a),children:[r?(0,G.jsx)(`div`,{className:`border-b border-border/60 bg-background/95 backdrop-blur-md`,children:(0,G.jsx)(W4,{placeholder:`Filter collection workouts…`,className:`pt-3`,navigationScope:o})}):null,h.length===0?(0,G.jsx)(`div`,{className:`px-6 py-10 text-sm font-medium text-muted-foreground`,children:`No workouts found.`}):(0,G.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,G.jsx)(`div`,{role:`option`,"aria-selected":n,className:K(`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,G.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:K(`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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex-shrink-0 size-10 rounded-xl bg-muted flex items-center justify-center transition-colors`,children:(0,G.jsx)(ot,{className:`size-4 text-primary`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-bold text-foreground truncate uppercase tracking-tight`,children:e.item.displayName??e.item.name}),e.preview?(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground font-medium truncate mt-1`,children:e.preview}):null]}),e.item.date===void 0?null:(0,G.jsx)(`span`,{className:`shrink-0 self-center text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:GS(new Date(e.item.date))}),(0,G.jsx)(gt,{className:`size-4 text-muted-foreground shrink-0 transition-opacity`})]}):r.label},r.id)})},e.item.id)})})]})};function Z4(){return(0,W.useEffect)(()=>{wW().catch(e=>console.warn(`[queryService] page source population failed`,e))},[]),(0,W.useSyncExternalStore)(DW,EW)}function Q4(e,t){let n=e.find(e=>e.key===t&&!e.negate);return n&&n.values.length===1?n.values[0].value:null}function $4(e){let t=e.trim();if(!t.startsWith(`:`))return null;let n=DB(t),r=Y(n);if(r.error||!Th(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=Q4(r.filters,`notebook`);if(e){let t=io(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=Q4(r.filters,`notebook`);if(e){let t=io(e);return t===`journal`?`/journal${i}`:t===`playground`?`/playgrounds${i}`:`/notebook/${encodeURIComponent(t)}${i}`}let t=Q4(r.filters,`source`);return t===`journal`?`/journal${i}`:t===`playground`?`/playgrounds${i}`:t===`feeds`||t===`notebooks`||t===`notebook`||t===`guides`?`/notes${i}`:Q4(r.filters,`type`)===`dashboard`?`/dashboards${i}`:`/notes${i}`}default:return null}}function e3(e,t,n){return t?{...t,title:n?.title??t.title,description:n?.question??t.description}:$g(e,{fenceTag:Xy({type:n?.type??``,spanCols:n?.spanCols,spanFull:n?.spanFull,attributes:n?.attributes}).slice(3),adjacentTitle:n?.title?.trim()||void 0,adjacentDescription:n?.question?.trim()||void 0})}function t3(e){if(e.error)return!1;let t=i_(e).trim();if(!t)return!1;let n=Mg(t);return!n.doc.degenerate&&n.doc.assignments.length>0?n.diagnostics.length===0:!Y(t).error}function n3({open:e,...t}){return e?(0,G.jsx)(r3,{...t}):null}function r3({onClose:e,mode:t,initialWql:n,initialObject:r,initial:i,subsetQuery:a,destination:o,executor:s,rangeStart:c,rangeEnd:l,preferredUnit:u,tokenValues:d,onApply:f,footerExtra:p,applyLabel:m=t===`edit`?`Apply changes`:`Add widget`}){let h=t===`inspect`,[g,_]=(0,W.useState)(()=>e3(n,r,i)),[v,y]=(0,W.useState)(()=>{let e=e3(n,r,i);return{valid:t3(e),error:e.error}}),[b,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(null),w=async()=>{if(!v.valid||!f||b)return;let t=i_(g).trim();if(!(!t||!t3(g))){x(!0),C(null);try{let n=a_(g).attributes;await f({title:g.title?.trim()||void 0,question:g.description?.trim()||void 0,type:g.view===`table`&&!g.rawViewType?``:g.rawViewType??g.view,spanCols:typeof g.span==`number`?g.span:void 0,spanFull:g.span===`full`||void 0,wql:t,queryObject:g,attributes:Object.keys(n).length>0?n:void 0}),e()}catch(e){C(e instanceof Error?e.message:String(e))}finally{x(!1)}}};return(0,G.jsx)(dE,{open:!0,onClose:e,presentation:`sheet`,title:t===`inspect`?`Inspect widget`:t===`edit`?`Edit widget`:`Add widget`,description:h?`Read-only — clone the dashboard to edit this widget.`:`Dataset, calculation, visualization, preview — then apply.`,footer:h&&!p?void 0:(0,G.jsxs)(G.Fragment,{children:[p,(0,G.jsx)(`div`,{className:`flex-1`}),!h&&(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(`button`,{type:`button`,"data-testid":`widget-composer-apply`,disabled:!v.valid||b,title:v.error,onClick:()=>void w(),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:b?`Applying…`:m})]})]}),children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,G.jsx)(GD,{density:`studio`,value:g,onChange:_,readOnly:h,subsetQuery:a,destination:o,executor:s,rangeStart:c,rangeEnd:l,preferredUnit:u,tokenValues:d,onValidationChange:y}),S&&(0,G.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:S})]})})}var i3=`__new__`;function a3(e){return e.open?(0,G.jsx)(o3,{...e},e.subsetQuery??`(whole-store)`):null}function o3({onOpenChange:e,initialQuery:t,subsetQuery:n,rangeStart:r,rangeEnd:i,preferredUnit:a}){let o=lt(),{items:s,loading:c}=Fz(),l=s.filter(e=>e.editable),[u,d]=(0,W.useState)(l[0]?.slug??i3),[f,p]=(0,W.useState)(``),[m,h]=(0,W.useState)(null),g=()=>e(!1);return(0,G.jsx)(n3,{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,queryObject:e.queryObject,attributes:e.attributes};try{if(u===i3){let e=f.trim()||`New Dashboard`,n=await Gz.createDashboard(e);await Uz.update(n,rb(n.rawContent,t)),Az();let{meta:r}=Oo(n.rawContent),i=typeof r.slug==`string`&&r.slug.trim()?Jy(r.slug):Jy(e);g(),o(yz(i))}else{let e=await Uz.resolve(u);await Uz.update(e,rb(e.rawContent,t)),Az(),g(),o(yz(u))}}catch(e){let t=e instanceof Error?e.message:String(e);throw h(t),e}},applyLabel:`Add to dashboard`,destination:(0,G.jsxs)(`section`,{children:[(0,G.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5`,children:`Destination`}),c?(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading dashboards…`}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[l.map(e=>(0,G.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,G.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-dest-new`,"aria-pressed":u===i3,onClick:()=>d(i3),className:`flex items-center gap-1 rounded-lg border px-3 py-1.5 text-xs font-medium transition-colors ${u===i3?`border-primary/60 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:[(0,G.jsx)(ut,{className:`size-3`}),` New dashboard`]})]}),u===i3&&(0,G.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,G.jsxs)(`p`,{role:`alert`,"data-testid":`dashboard-save-error`,className:`mt-2 text-xs text-destructive font-mono`,children:[`Could not save: `,m]})]})})}var s3=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 c3(e){let t=e.split(`.`).pop()?.split(`?`)[0]?.toLowerCase()??``;return s3.has(t)}function l3(e){return/^https?:\/\//.test(e)||e.startsWith(`//`)}function u3({queryText:e,widgetType:t,widgetError:n,attributes:r}){let i=Z4(),a=z(),[o,s]=(0,W.useState)(!1),c=/^\/dashboards?(?:\/|$)/.test(a.pathname),l=Y(e),u=!l.error&&Th(l)?e:null;return i?(0,G.jsxs)(`div`,{className:`my-5 not-prose`,children:[(0,G.jsx)(YD,{query:e,widgetType:t,widgetError:n,attributes:r,executor:jW,readOnly:!0,onAddToDashboard:c?void 0:()=>s(!0),noteHref:e=>eH(`blockContentId`in e||`dataType`in e?IV(e):AV(e))}),(0,G.jsx)(a3,{open:o,onOpenChange:s,initialQuery:e,subsetQuery:u})]}):(0,G.jsx)(`div`,{className:`my-5 not-prose text-xs text-muted-foreground py-2`,children:`Loading…`})}function d3(e){let{meta:t,body:n}=Oo(e);return Object.keys(t).length===0&&n===e?{fields:null,body:e}:{fields:t,body:n.trim()}}var f3={table({children:e}){return(0,G.jsx)(`div`,{className:`my-6 overflow-x-auto rounded-xl border border-border`,children:(0,G.jsx)(`table`,{className:`w-full text-sm border-collapse`,children:e})})},thead({children:e}){return(0,G.jsx)(`thead`,{className:`bg-muted/50 text-left`,children:e})},tbody({children:e}){return(0,G.jsx)(`tbody`,{className:`divide-y divide-border/50`,children:e})},tr({children:e}){return(0,G.jsx)(`tr`,{className:`hover:bg-muted/20 transition-colors`,children:e})},th({children:e}){return(0,G.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,G.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,G.jsxs)(`figure`,{className:`my-6`,children:[(0,G.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,G.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=$4(e);if(r)return(0,G.jsx)(ve,{to:r,className:`underline underline-offset-2 transition-colors text-primary hover:text-primary/70`,children:t})}let r=l3(n),i=c3(n),a=r?P1(n):n;return(0,G.jsxs)(`a`,{href:a,rel:r?`noopener noreferrer`:void 0,target:r||i?`_blank`:void 0,className:K(`underline underline-offset-2 transition-colors`,i?`text-primary font-medium`:`text-primary hover:text-primary/70`),children:[t,r&&(0,G.jsx)(`span`,{className:`ml-0.5 text-[10px] align-super opacity-60`,children:`↗`}),i&&!r&&(0,G.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(`
829
829
  `))return(0,G.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 `)||n.startsWith(`widget:`)){let t=(typeof e==`string`?e:Array.isArray(e)?e.join(``):String(e??``)).trim(),r=n.replace(/^(?:query|widget)[:\s]?/,``).trim(),i=r?Lg(r):void 0;return(0,G.jsx)(u3,{queryText:t,widgetType:i?.type,widgetError:i?.error,attributes:i?.attributes})}return(0,G.jsxs)(`div`,{className:`my-5 rounded-xl overflow-hidden border border-border`,children:[n&&(0,G.jsx)(`div`,{className:`flex items-center gap-2 px-4 py-2 bg-muted border-b border-border`,children:(0,G.jsx)(`span`,{className:`text-[10px] font-black tracking-widest uppercase text-muted-foreground`,children:n})}),(0,G.jsx)(`pre`,{className:`overflow-x-auto p-4 bg-muted/30`,children:(0,G.jsx)(`code`,{className:`font-mono text-sm text-foreground`,children:e})})]})},h1({children:e,id:t}){return(0,G.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,G.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,G.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,G.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,G.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,G.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,G.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,G.jsx)(`li`,{className:`leading-relaxed`,children:e})},blockquote({children:e}){return(0,G.jsx)(`blockquote`,{className:`my-5 pl-4 border-l-2 border-primary/40 text-muted-foreground italic text-sm`,children:e})},hr(){return(0,G.jsx)(`hr`,{className:`my-8 border-border/50`})},strong({children:e}){return(0,G.jsx)(`strong`,{className:`font-black text-foreground`,children:e})},em({children:e}){return(0,G.jsx)(`em`,{className:`italic text-foreground/80`,children:e})}},p3={...f3,p({children:e}){return(0,G.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=W.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,G.jsxs)(`span`,{className:`flex flex-col select-none mt-4 w-full gap-5 sm:gap-7`,children:[(0,G.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,G.jsx)(`span`,{className:`inline-block border-b-4 border-primary/70 pb-1 hover:scale-105 transition-transform duration-200`,children:`Markdown`}),`.`]}),(0,G.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,G.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,G.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,G.jsx)(`span`,{className:`inline-block border-b-4 border-primary/70 pb-1 hover:scale-105 transition-transform duration-200`,children:`Analytics`}),`.`]})]}):(0,G.jsx)(`strong`,{className:`font-black text-foreground`,children:e})}},m3={...f3,p({children:e}){return(0,G.jsx)(`p`,{className:`text-base lg:text-lg font-medium text-foreground/75 leading-relaxed my-4 first:mt-0`,children:e})}},h3=[Wn];function g3(e){return e.startsWith(`:`)?e:En(e)}function _3(e){return e.type===`text`&&typeof e.value==`string`?e.value:(e.children??[]).map(_3).join(``)}function v3(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N} _-]/gu,``).replace(/ /g,`-`).replace(/-+/g,`-`)||`heading`}var y3=()=>e=>{let t=new Map,n=e=>{if(e.tagName&&/^h[1-6]$/.test(e.tagName)){let n=v3(_3(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 b3({fields:e}){let t=Object.entries(e);return t.length===0?null:(0,G.jsxs)(`div`,{className:`my-6 rounded-xl border border-border bg-muted/30 overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`px-4 py-2 border-b border-border bg-muted/50`,children:(0,G.jsx)(`span`,{className:`text-[10px] font-black tracking-[0.2em] uppercase text-muted-foreground`,children:`Metadata`})}),(0,G.jsx)(`dl`,{className:`divide-y divide-border/50`,children:t.map(([e,t])=>(0,G.jsxs)(`div`,{className:`flex items-baseline gap-4 px-4 py-2`,children:[(0,G.jsx)(`dt`,{className:`text-[11px] font-semibold text-muted-foreground uppercase tracking-wide min-w-[100px] shrink-0`,children:e}),(0,G.jsx)(`dd`,{className:`text-sm text-foreground break-words`,children:Array.isArray(t)?t.join(`, `):String(t)})]},e))})]})}var x3={default:f3,heroLead:p3,heroBody:m3};function S3({prose:e,className:t,variant:n=`default`}){if(!e)return null;let{fields:r,body:i}=d3(e);return(0,G.jsxs)(`div`,{className:K(`prose-canvas`,t),children:[r&&(0,G.jsx)(b3,{fields:r}),i&&(0,G.jsx)(lr,{remarkPlugins:h3,rehypePlugins:[y3],urlTransform:g3,components:x3[n],children:i})]})}var C3=({activations:e,fullBleed:t,runState:n,deps:r})=>{if(e.length===0)return null;let i=e[0];if(cH(i)&&n){let a=e.slice(1),o=n.isReconnect?(0,G.jsxs)(`button`,{type:`button`,"aria-label":`View active workout timer`,onClick:n.onReconnect,className:K(`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,G.jsx)(y,{className:`size-3.5`,"aria-hidden":`true`}),`View`]}):(0,G.jsxs)(`button`,{type:`button`,"aria-label":i.label,onClick:n.onRun,className:K(`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||bt;return(0,G.jsx)(e,{className:`shrink-0 size-4 fill-current sm:size-3`,"aria-hidden":`true`})})(),(0,G.jsx)(`span`,{children:i.label})]});return(0,G.jsxs)(`div`,{className:K(`flex flex-wrap items-center gap-4 mt-8`,t&&`justify-center`),children:[o,a.map((e,t)=>(0,G.jsx)(`button`,{type:`button`,"aria-label":e.label,onClick:()=>aH(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,G.jsx)(`div`,{className:K(`flex flex-wrap gap-4 mt-8`,t&&`justify-center`),children:e.map((e,t)=>(0,G.jsx)(`button`,{type:`button`,"aria-label":e.label,onClick:()=>aH(e.action,r),className:K(`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))})},w3=({examples:e,activeIndex:t,onSelect:n})=>e.length===0?null:(0,G.jsx)(`div`,{className:`mt-6 rounded-2xl border border-border/70 bg-card/80 backdrop-blur-sm`,children:(0,G.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,G.jsxs)(`button`,{type:`button`,onClick:()=>n(r),"aria-current":i?`true`:void 0,className:K(`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,G.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}`)})})}),T3=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`struct-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E676`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#00F2FF`,stopOpacity:1}})]})}),(0,G.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,G.jsx)(`path`,{d:`M35 35 L65 35 L65 45 L45 45 L45 65 L35 65 Z`,fill:`url(#struct-grad)`}),(0,G.jsx)(`path`,{d:`M55 45 L65 45 L65 65 L45 65 L45 55 L55 55 Z`,fill:`url(#struct-grad)`,opacity:`0.7`})]}),E3=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`proto-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#FFD600`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#FFAB00`,stopOpacity:1}})]})}),(0,G.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,G.jsx)(`circle`,{cx:`50`,cy:`50`,r:`5`,fill:`url(#proto-grad)`}),(0,G.jsx)(`circle`,{cx:`50`,cy:`50`,r:`15`,fill:`none`,stroke:`url(#proto-grad)`,strokeWidth:`2`,strokeDasharray:`4 2`}),(0,G.jsx)(`circle`,{cx:`50`,cy:`50`,r:`25`,fill:`none`,stroke:`url(#proto-grad)`,strokeWidth:`1`,opacity:`0.5`}),(0,G.jsx)(`line`,{x1:`50`,y1:`50`,x2:`50`,y2:`25`,stroke:`url(#proto-grad)`,strokeWidth:`4`,strokeLinecap:`round`})]}),D3=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`complex-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#F50057`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#D500F9`,stopOpacity:1}})]})}),(0,G.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,G.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)`})]}),O3=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsxs)(`defs`,{children:[(0,G.jsxs)(`linearGradient`,{id:`basics-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00F2FF`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#6200EA`,stopOpacity:1}})]}),(0,G.jsxs)(`filter`,{id:`glow`,x:`-20%`,y:`-20%`,width:`140%`,height:`140%`,children:[(0,G.jsx)(`feGaussianBlur`,{stdDeviation:`3`,result:`blur`}),(0,G.jsx)(`feComposite`,{in:`SourceGraphic`,in2:`blur`,operator:`over`})]})]}),(0,G.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,G.jsx)(`path`,{d:`M55 20 L30 55 L45 55 L40 85 L70 45 L55 45 Z`,fill:`url(#basics-grad)`,filter:`url(#glow)`})]}),Dae=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`basics-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00F2FF`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#6200EA`,stopOpacity:1}})]})}),(0,G.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,G.jsx)(`text`,{x:`50`,y:`65`,fontFamily:`monospace`,fontSize:`40`,fontWeight:`bold`,fill:`url(#basics-grad)`,textAnchor:`middle`,children:`10`})]}),Oae=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`basics-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00F2FF`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#6200EA`,stopOpacity:1}})]})}),(0,G.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,G.jsx)(`rect`,{x:`30`,y:`30`,width:`40`,height:`8`,rx:`2`,fill:`url(#basics-grad)`}),(0,G.jsx)(`rect`,{x:`30`,y:`45`,width:`40`,height:`8`,rx:`2`,fill:`url(#basics-grad)`}),(0,G.jsx)(`rect`,{x:`30`,y:`60`,width:`40`,height:`8`,rx:`2`,fill:`url(#basics-grad)`})]}),kae=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`struct-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E676`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#00F2FF`,stopOpacity:1}})]})}),(0,G.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,G.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`})]}),Aae=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`struct-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E676`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#00F2FF`,stopOpacity:1}})]})}),(0,G.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,G.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,G.jsx)(`text`,{x:`50`,y:`30`,fontFamily:`monospace`,fontSize:`12`,fill:`url(#struct-grad)`,textAnchor:`middle`,children:`21-15-9`})]}),jae=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`proto-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#FFD600`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#FFAB00`,stopOpacity:1}})]})}),(0,G.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,G.jsx)(`path`,{d:`M35 35 H65 V55 L50 70 L35 55 Z`,fill:`url(#proto-grad)`}),(0,G.jsx)(`circle`,{cx:`50`,cy:`45`,r:`4`,fill:`#0b1326`})]}),k3=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`metric-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E5FF`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#1DE9B6`,stopOpacity:1}})]})}),(0,G.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,G.jsx)(`rect`,{x:`30`,y:`60`,width:`10`,height:`15`,fill:`url(#metric-grad)`}),(0,G.jsx)(`rect`,{x:`45`,y:`40`,width:`10`,height:`35`,fill:`url(#metric-grad)`}),(0,G.jsx)(`rect`,{x:`60`,y:`25`,width:`10`,height:`50`,fill:`url(#metric-grad)`})]}),Mae=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`metric-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E5FF`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#1DE9B6`,stopOpacity:1}})]})}),(0,G.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,G.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`})]}),A3=e=>(0,G.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`dialect-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,G.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#76FF03`,stopOpacity:1}}),(0,G.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#00E676`,stopOpacity:1}})]})}),(0,G.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,G.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 j3(e){switch(e){case`trophy`:return O3;case`dumbbell`:return ot;case`timer`:return E3;case`play`:return bt;case`blocks`:return T3;case`puzzle`:return D3;case`activity`:return k3;case`file-text`:return A3;default:return vn}}function Nae(e){switch(e){case`basics-movement`:return O3;case`basics-reps`:return Dae;case`basics-load`:return Oae;case`structure-rounds`:case`complex-rounds`:case`protocols-rounds`:return kae;case`structure-repscheme`:return Aae;case`protocols-timer`:case`complex-time`:return E3;case`protocols-tag`:return jae;case`metrics-custom`:return k3;case`metrics-calc`:return Mae;case`dialects-log`:case`dialects-climb`:return A3;default:return null}}function M3({quest:e,onClick:t,className:n,compact:r=!1,disabled:i=!1}){let a=Nae(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:K(`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,G.jsxs)(G.Fragment,{children:[a?(0,G.jsxs)(`span`,{className:K(`relative shrink-0 mt-0.5`,r?`size-5`:`size-6`),children:[(0,G.jsx)(a,{className:`w-full h-full`}),e.isCompleted&&(0,G.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,G.jsx)(xt,{className:`size-2`,strokeWidth:3})})]}):(0,G.jsx)(`span`,{className:K(`mt-0.5 shrink-0`,e.isCompleted?`text-primary`:`text-muted-foreground/50`),"aria-hidden":`true`,children:e.isCompleted?(0,G.jsx)(be,{className:r?`size-3.5`:`size-4`}):(0,G.jsx)(P,{className:r?`size-3.5`:`size-4`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:K(`font-semibold`,e.isCompleted?`text-foreground line-through decoration-primary/40`:`text-foreground`,r&&`text-xs`),children:e.label}),e.desc&&!r&&(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e.desc}),(0,G.jsx)(`p`,{"data-testid":`challenge-hint-${e.id}`,className:K(`mt-1 text-xs`,e.isCompleted||e.result?.pass?`text-primary/80`:`text-muted-foreground`),children:s})]})]});return t?(0,G.jsx)(`button`,{type:`button`,onClick:t,disabled:i,...c,children:l}):(0,G.jsx)(`div`,{...c,children:l})}function Pae(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 N3=({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=EU[e.theme||`slate`]??EU.slate,E=e.examples??[],D=t===-1,O=W.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`?Pae(a.text.trim()):{lead:``,rest:``},c=e.proseChunks.slice(n+1);return(0,G.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,G.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,G.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,G.jsxs)(`div`,{className:`relative max-w-2xl w-full text-center`,children:[o&&(0,G.jsx)(S3,{prose:o,variant:`heroLead`,className:`mb-5`}),s&&(0,G.jsx)(S3,{prose:s,variant:`heroBody`,className:`mb-2`}),c.map((e,t)=>{if(e.kind===`prose`){let n=e.text.trim();return n?(0,G.jsx)(S3,{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,G.jsx)(`div`,{className:`my-4 flex justify-center`,children:(0,G.jsx)(M3,{quest:n,onClick:()=>b?.(r),compact:!0})},`hero-challenge-${t}`):null}return null}),t.length>0&&(0,G.jsx)(C3,{activations:t.map((e,t)=>sH(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,G.jsxs)(`div`,{id:r,"data-section-id":i==="default"||i===`before-workouts`?e.id:void 0,className:K(`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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:K(`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,G.jsx)(`div`,{className:K(`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,G.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,G.jsxs)(`div`,{className:K(`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,G.jsx)(`div`,{className:`mb-4 flex items-center gap-2 select-none min-h-[14px]`,children:O.quest.isCompleted?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[9px] font-black uppercase tracking-wider text-emerald-800 dark:text-emerald-400 bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-500/20`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-emerald-500 dark:bg-emerald-400 animate-pulse`}),`Challenge Complete`]}):(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[9px] font-black uppercase tracking-wider text-muted-foreground bg-muted/60 px-2 py-0.5 rounded-full border border-border/50`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-zinc-400 dark:bg-zinc-500`}),O.chapterTitle,`: Challenge Pending`]})}),a?(0,G.jsx)(`h2`,{className:K(`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,G.jsx)(S3,{prose:n,className:t===0?`mb-6`:`mt-4 mb-6`},`prose-${t}`):null}if(e.kind===`button`)return(0,G.jsx)(C3,{activations:[sH(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,G.jsx)(`div`,{className:`my-6`,children:(0,G.jsx)(H4,{})},`hero-carousel-${t}`);if(e.widget===`workouts-list`&&g&&_&&y)return(0,G.jsx)(`div`,{id:`notebook-workouts`,className:`border-b border-border/50 bg-card my-6`,children:(0,G.jsx)(`div`,{className:`w-full mx-auto`,children:(0,G.jsx)(X4,{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,G.jsx)(`div`,{className:`my-4`,children:(0,G.jsx)(M3,{quest:n,onClick:()=>b?.(r),compact:!0})},`challenge-${t}`):null}return null}),E.length>0?(0,G.jsx)(w3,{examples:E,activeIndex:Math.min(p,E.length-1),onSelect:t=>f(e,t)}):null,s&&A?(0,G.jsx)(C3,{activations:e.buttons.map((e,t)=>sH(e,t)),fullBleed:S,runState:l?u:void 0,deps:d}):null]})]},`${e.id}-${i}`)};function Fae({sections:e,activeIndex:t,part:n,args:r}){return(0,G.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,G.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,G.jsx)(N3,{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 Iae({sections:e,part:t,partCount:n,title:r,pane:i,cardArgs:a,onActivateSection:o}){let s=(0,W.useRef)(null),c=(0,W.useMemo)(()=>B4(e),[e]),{slice:l,subscribe:u}=I4(s,!1,c),d=(0,W.useRef)(e);d.current=e;let[f,p]=(0,W.useState)(!1);(0,W.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,W.useState)(!1);(0,W.useEffect)(()=>u(()=>{let e=m();g(t=>t===e?t:e)}),[u]);let _=(0,W.useRef)(!1),v=(0,W.useRef)(-1),y=(0,W.useRef)(o);y.current=o,(0,W.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,G.jsxs)(`div`,{children:[(0,G.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,G.jsxs)(`div`,{className:`font-mono text-[11px] uppercase tracking-[0.22em] text-muted-foreground`,children:[`Part `,t,` / `,n]}),(0,G.jsx)(`h2`,{className:`mt-1 text-xl font-black uppercase tracking-tight text-foreground`,children:r})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(N4,{trackRef:s,height:`${(e.length+1)*100}vh`,stages:c,activeIndex:l.index,pane:f?i:null,captions:(0,G.jsx)(Fae,{sections:e,activeIndex:l.index,part:t,args:a}),status:(0,G.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,G.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} + 160px)`}},t.id))]})]})}function Lae({sections:e,groupKey:t,title:n,pane:r,cardArgs:i,onActivateSection:a}){let{groups:o,tail:s}=z4(e,t);return(0,G.jsxs)(G.Fragment,{children:[o.map((e,t)=>(0,G.jsx)(Iae,{sections:e,part:t+1,partCount:o.length,title:n,pane:r,cardArgs:i,onActivateSection:a},e[0]?.id??t)),s.length>0&&(0,G.jsx)(`div`,{className:`mx-auto w-full max-w-[1500px] px-6 lg:px-12`,"data-testid":`guide-static-tail`,children:(0,G.jsx)(`div`,{className:`lg:max-w-[50%]`,children:s.map((e,t)=>(0,G.jsx)(N3,{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 P3({videoId:e,title:t=`YouTube video`,onClose:n}){return(0,W.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,cE.createPortal)((0,G.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,G.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,G.jsx)(Bn,{className:`size-5`})}),(0,G.jsx)(`div`,{className:`aspect-video w-full max-w-5xl overflow-hidden rounded-lg border border-border bg-black shadow-2xl`,children:(0,G.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 F3({index:e,before:t,accentText:n,after:r,accent:i,blurb:a}){return(0,G.jsx)(`header`,{className:`flex items-center px-6 py-14 lg:px-12 xl:py-20 2xl:py-24 xl:px-16`,children:(0,G.jsxs)(`div`,{className:`mx-auto w-full max-w-[1500px] 2xl:max-w-[1720px]`,children:[(0,G.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,G.jsx)(`span`,{className:`font-mono text-xs font-normal tracking-normal text-muted-foreground`,children:e}),(0,G.jsxs)(`span`,{children:[t,n,r]})]}),(0,G.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 I3=`hsl(var(--primary))`,L3={ink:`hsl(var(--foreground))`,editor:I3,timer:I3,analytics:I3,library:I3,rounds:I3},Rae={editor:`WOD Editor & Autocomplete`,timer:`Clock`,analytics:`WQL Analytics`,metrics:`Own the Metrics`,result:`Run Results`},R3={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`},z3=`dQw4w9WgXcQ`,zae=`https://i.ytimg.com/vi/${z3}/hqdefault.jpg`;function B3({variant:e=`index`}){let t=nW(),{pathname:n}=z(),[r,i]=(0,W.useState)(null),a=(0,W.useMemo)(()=>yU(t).flatMap(e=>e.action?.type===`route`?[{id:e.id,label:e.label,to:e.action.to}]:[]),[t]),o=(0,W.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,G.jsx)(P3,{videoId:z3,title:r.label,onClose:()=>i(null)});return e===`university`?(0,G.jsxs)(`section`,{id:`tour-section-university`,"data-testid":`tour-section-university`,"aria-label":`Wod Wiki University`,children:[(0,G.jsx)(F3,{index:`05`,before:`Wod Wiki `,accentText:`University`,after:``,accent:L3.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,G.jsx)(`nav`,{"aria-label":`Wod Wiki University`,className:`px-6 pb-16 lg:px-12 xl:px-16`,children:(0,G.jsx)(`ul`,{className:`mx-auto flex w-full max-w-5xl flex-col gap-5`,children:a.map((e,t)=>(0,G.jsxs)(`li`,{className:K(`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,G.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,G.jsx)(`img`,{src:zae,alt:``,loading:`lazy`,className:`aspect-video w-full object-cover transition-transform duration-300 group-hover:scale-105`}),(0,G.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-black/25 transition-colors group-hover:bg-black/40`,children:(0,G.jsx)(bt,{className:`size-9 fill-white text-white`})})]}),(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1.5`,children:[(0,G.jsx)(ve,{to:e.to,className:`font-semibold hover:underline`,children:e.label}),(0,G.jsx)(`p`,{className:`text-sm leading-relaxed text-muted-foreground`,children:o.get(e.id)??e.to})]})]},e.id))})}),u]}):(0,G.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,G.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col rounded-lg border border-border overflow-hidden`,children:[(0,G.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,G.jsx)(`ul`,{className:`flex flex-col divide-y divide-border`,children:a.map((e,t)=>(0,G.jsxs)(`li`,{className:`flex items-stretch`,children:[(0,G.jsxs)(ve,{to:e.to,"aria-current":t===s?`page`:void 0,className:K(`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,G.jsxs)(`span`,{className:`flex w-full items-baseline justify-between gap-3`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:e.label}),t===l&&(0,G.jsx)(`span`,{className:`text-xs font-semibold text-primary`,"data-testid":`guide-next-marker`,children:`Next →`})]}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.to})]}),(0,G.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,G.jsx)(bt,{className:`size-3.5`}),`Watch`]})]},e.id))})]}),u]})}var Bae=`22rem`,Vae=`42rem`,Hae=`20rem`,Uae=`calc(100dvh - var(--canvas-sticky-top) - 2rem)`;function Wae(e){return{editorWidth:e||`50%`,editorMinWidth:Bae,editorMaxWidth:Vae,editorMinHeight:Hae,editorMaxHeight:Uae}}function V3(e){let t=Math.max(1,e.split(`
@@ -1113,7 +1113,7 @@ domain: swimming
1113
1113
  150m Cooldown
1114
1114
  \`\`\`
1115
1115
  `,w6=YU(qoe);if(!w6)throw Error(`The baked home page must remain a valid canvas document`);var T6=w6,tse={"markdown/canvas/home/welcome-1.md":Joe,"markdown/canvas/syntax/single-movement.md":Yoe,"markdown/canvas/syntax/timers-rest.md":Xoe,"markdown/canvas/syntax/groups-1.md":Zoe,"markdown/canvas/syntax/custom-metrics-1.md":Qoe,"markdown/canvas/syntax/dialect-climb-bouldering.md":$oe,"markdown/canvas/syntax/complex-swimming.md":ese};function E6(e){return{...tse,...e}}function nse(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 D6=`wodwiki.homeShared.v1`;function O6(){return typeof window<`u`&&window.localStorage?window.localStorage:null}function rse(e){try{O6()?.setItem(D6,JSON.stringify(e)),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`wodwiki:home-shared`,{detail:e}))}catch{}}function ise(){try{let e=O6()?.getItem(D6);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 ase(){try{O6()?.removeItem(D6)}catch{}}function ose({pageRoute:e,quests:t,running:n}){let{markComplete:r}=D1(e,t),i=(0,W.useMemo)(()=>t.filter(e=>e.validation?.type===`run-started`),[t]);(0,W.useEffect)(()=>{if(n)for(let e of i)r(e.id)},[n,i,r])}var sse={"session-insights":`qs-tour-analytics`},cse={"workout-complete":!0,"run-started":!0};function lse(e,t){let{markComplete:n}=D1(e,t),r=(0,W.useRef)(new Set);return r.current=new Set(t.filter(e=>!e.validation||!cse[e.validation.type]).map(e=>e.id)),(0,W.useCallback)(e=>{let t=sse[e];t&&r.current.has(t)&&n(t)},[n])}var use=.4;function dse(e){let{dispatch:t}=SR();(0,W.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*use,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(`
1116
- `),t])}var k6=(0,W.createContext)(null);function A6({children:e}){let t=(0,W.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,W.useState)(0),i=(0,W.useCallback)((e,n)=>{t.current[e]!==n&&(t.current[e]=n,r(e=>e+1))},[]);return(0,G.jsx)(k6.Provider,{value:{register:i,registry:t,version:n},children:e})}function j6(){return(0,W.useContext)(k6)||{registry:{current:{}},register:()=>()=>{},version:0}}function M6(e){let t=(0,W.useContext)(k6)?.register;return(0,W.useCallback)(n=>t?.(e,n),[e,t])}function fse({ringKey:e,el:t}){let{register:n}=j6();return(0,W.useLayoutEffect)(()=>{n(e,t)},[e,t,n]),null}function pse({target:e,accent:t,canvasRef:n}){let{registry:r,version:i}=j6(),[a,o]=(0,W.useState)(null),s=e?.key??null;return(0,W.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,G.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 N6(){return(0,G.jsxs)(`div`,{className:`@container flex w-full flex-col items-center text-center`,children:[(0,G.jsxs)(`h1`,{className:`text-[clamp(32px,6.5cqi,64px)] font-extrabold leading-[1.02] tracking-[-0.04em]`,children:[(0,G.jsxs)(`span`,{className:`block`,children:[(0,G.jsx)(`span`,{className:`mr-[0.35em]`,children:`Write it.`}),(0,G.jsx)(`span`,{children:`Time it.`})]}),(0,G.jsxs)(`span`,{className:`block`,children:[(0,G.jsx)(`span`,{className:`mr-[0.35em]`,children:`Track it.`}),(0,G.jsx)(`span`,{children:`Own it.`})]})]}),(0,G.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,G.jsx)(`br`,{}),`line and splits become queryable training data points.`]})]})}var P6=`dQw4w9WgXcQ`;function mse({onWatched:e}){let[t,n]=(0,W.useState)(!1);return(0,G.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-4 xl:gap-5`,children:[(0,G.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,G.jsxs)(`button`,{type:`button`,onClick:()=>n(!0),"data-testid":`tour-why-video`,"aria-label":`Play Why Wod Wiki? · YouTube video`,className:`block h-full w-full overflow-hidden rounded-xl`,children:[(0,G.jsx)(`img`,{src:`https://i.ytimg.com/vi/${P6}/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,G.jsx)(`span`,{className:`absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-transparent`}),(0,G.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,G.jsx)(bt,{className:`ml-1 size-6 fill-current xl:size-7`})}),(0,G.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,G.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,G.jsx)(Bn,{className:`size-4`})})]}),(0,G.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,G.jsx)(dt,{className:`size-4 animate-bounce`}),`Keep scrolling for the demo`]}),t&&(0,G.jsx)(P3,{videoId:P6,title:`Why Wod Wiki?`,onClose:()=>{n(!1),e?.()}})]})}var hse=`https://github.com/bitcobblers/wod-wiki`;function F6(){return(0,G.jsx)(`footer`,{"data-testid":`tour-footer`,className:`border-t border-border px-6 py-8`,children:(0,G.jsxs)(`p`,{className:`mx-auto flex max-w-3xl flex-wrap items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,G.jsxs)(`span`,{children:[`© `,new Date().getFullYear(),` WOD Wiki`]}),(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,G.jsx)(`a`,{href:hse,target:`_blank`,rel:`noopener noreferrer`,className:`underline-offset-4 transition-colors hover:text-foreground hover:underline`,children:`GitHub repository`})]})})}async function I6(){await _N.wipe();try{for(let e=localStorage.length-1;e>=0;e--){let t=localStorage.key(e);t&&t!==`wodwiki.dataSettings.v1`&&localStorage.removeItem(t)}}catch{}try{sessionStorage.clear()}catch{}}var gse=`https://github.com/bitcobblers/wod-wiki`,_se=`https://forms.gle/6YHpxwAJh6PAsyAQ6`,vse=`https://app.turso.tech/signup`,yse=`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`,bse=[{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.`}],xse=[{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.`}],L6=`underline-offset-4 transition-colors hover:text-foreground hover:underline`;function R6(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,G.jsxs)(G.Fragment,{children:[e.children,(0,G.jsx)(On,{className:`size-3.5 text-muted-foreground/50`,"aria-hidden":!0})]});return e.href===void 0?e.onClick===void 0?(0,G.jsx)(ve,{to:e.to,className:t,children:n}):(0,G.jsx)(`button`,{type:`button`,onClick:e.onClick,className:`text-left ${t}`,children:n}):(0,G.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:t,children:n})}function z6({children:e}){return(0,G.jsxs)(`li`,{className:`flex gap-2.5 text-sm leading-6 text-muted-foreground`,children:[(0,G.jsx)(`span`,{"aria-hidden":!0,className:`mt-[11px] size-1 shrink-0 rounded-full bg-muted-foreground/50`}),(0,G.jsx)(`span`,{children:e})]})}function Sse(){return(0,G.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-800`,children:`Active`})}function Cse(e){return(0,G.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsxs)(`span`,{className:`flex gap-2.5 text-[13px] leading-5 text-muted-foreground`,children:[(0,G.jsx)(`span`,{"aria-hidden":!0,className:`mt-[9px] size-1 shrink-0 rounded-full bg-muted-foreground/50`}),(0,G.jsx)(`span`,{children:e.feature.label})]}),(0,G.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 wse(){return(0,G.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,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,G.jsx)(be,{className:`size-5 shrink-0 text-emerald-600`,"aria-hidden":!0}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium text-foreground`,children:`Thanks for showing interest — please fill out the survey and give us feedback.`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Opens the interest survey in a new tab.`})]})]}),(0,G.jsxs)(q,{type:`button`,"data-testid":`hosted-survey-button`,onClick:()=>{KP.record(qP.hostedSurveyOpened),window.open(_se,`_blank`,`noopener,noreferrer`)},children:[`Fill out interest survey`,(0,G.jsx)(On,{className:`size-4`,"aria-hidden":!0})]})]})})}function B6(e){let t=e.icon;return(0,G.jsxs)(`article`,{className:`flex flex-col rounded-xl border border-border p-5 ${e.us?`bg-muted/40`:`bg-background`} ${e.className??``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-foreground text-background`,children:(0,G.jsx)(t,{className:`size-5`,"aria-hidden":!0})}),e.badge]}),e.eyebrow&&(0,G.jsx)(`p`,{className:`mt-3.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] ${e.us?`text-emerald-800`:`text-muted-foreground`}`,children:e.eyebrow}),(0,G.jsx)(`h3`,{className:`${e.eyebrow?`mt-1`:`mt-4`} text-base font-semibold text-foreground`,children:e.title}),(0,G.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-muted-foreground`,children:e.text}),(0,G.jsx)(`div`,{className:`mt-4 flex flex-1 flex-col gap-2 text-sm`,children:e.children})]})}function V6({label:e,features:t,interested:n,onInterested:r}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(`ul`,{className:`space-y-2`,children:t.map(e=>(0,G.jsx)(Cse,{feature:e,interested:n.has(e.id),onInterested:r},e.id))})]})}function H6(){let[e,t]=(0,W.useState)(!1),n=lt(),[r,i]=(0,W.useState)(new Set),a=e=>{i(t=>t.has(e)?t:new Set(t).add(e)),KP.record(qP.hostedInterestClicked,{feature:e})},[o]=(0,W.useState)(dN),s=async()=>{window.confirm(`Wipe every note, result, and setting stored in this browser? This cannot be undone.`)&&(t(!0),await I6(),window.location.reload())},c=async()=>{let e=Lz(),t=await Uz.create({journalDate:e,title:e,rawContent:``});KP.record(qP.noteCreated),n(rz(t.id))};return(0,G.jsxs)(`section`,{id:`tour-section-offerings`,"data-testid":`tour-section-offerings`,"aria-label":`You own your data`,children:[(0,G.jsx)(F3,{index:`04`,before:`Who owns the data? `,accentText:`You!!!`,after:``,accent:L3.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,G.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,G.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,G.jsx)(`span`,{children:`Current mode: API server`}),(0,G.jsx)(ve,{to:Q.settingsStorage,className:L6,children:`Configure data storage`})]}),(0,G.jsxs)(`div`,{className:`mx-auto grid max-w-5xl grid-cols-1 gap-5 md:grid-cols-3`,children:[(0,G.jsxs)(B6,{icon:Hn,eyebrow:`You own it`,title:`Playground in your browser`,badge:void 0,text:`Everything runs locally in this browser's IndexedDB — offline, no account, no server copy.`,children:[(0,G.jsx)(R6,{onClick:()=>void c(),children:`Create your journal`}),(0,G.jsx)(R6,{to:Q.playgroundRoot,children:`Start Writing in a Playground`}),(0,G.jsx)(R6,{to:`/feeds`,children:`Explore the notebooks`}),(0,G.jsxs)(`ul`,{className:`mt-1 space-y-1.5`,children:[(0,G.jsx)(z6,{children:`Offline and fast — notes and results never leave this browser by default.`}),(0,G.jsx)(z6,{children:`Tied to this browser — export or back it up before switching browsers or clearing site data.`})]}),(0,G.jsx)(`button`,{type:`button`,onClick:s,disabled:e,className:`mt-1 text-left text-xs text-muted-foreground disabled:opacity-50 ${L6}`,children:e?`Clearing…`:`Clear my data`}),(0,G.jsxs)(`div`,{className:`mt-auto border-t border-border pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,G.jsx)(`span`,{className:`mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-lg border border-border bg-background`,children:(0,G.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,className:`size-4`,"aria-hidden":!0,children:(0,G.jsx)(`path`,{d:yse})})}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium text-foreground`,children:`Backup & sync, optional`}),(0,G.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,G.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[(0,G.jsx)(R6,{href:vse,children:`Create a free Turso account`}),(0,G.jsx)(R6,{to:Q.settingsStorage,children:`Configure backup & sync`})]})]})]}),(0,G.jsxs)(B6,{icon:ye,eyebrow:`You own it`,title:`Self-hosted`,badge:(0,G.jsx)(Sse,{}),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,G.jsxs)(`ul`,{className:`mt-1 space-y-1.5`,children:[(0,G.jsx)(z6,{children:`Centralized data for a team or gym — one SQLite, Turso, or Postgres backend.`}),(0,G.jsxs)(z6,{children:[`Publish your notebooks as a feed with `,(0,G.jsx)(`code`,{className:`font-mono text-xs`,children:`wod build`}),` — every browser subscribes and syncs.`]}),(0,G.jsx)(z6,{children:`You run the server — network required, and server admin is on you.`})]}),(0,G.jsx)(`div`,{className:`mt-auto border-t border-border pt-4`,children:(0,G.jsx)(R6,{href:gse,children:`View source`})})]}),(0,G.jsxs)(B6,{icon:l,us:!0,eyebrow:`Us — we'd host it`,title:`Wod-Wiki hosted`,text:`Mark the features you want — the survey unlocks below.`,children:[(0,G.jsx)(V6,{label:`Individuals`,features:bse,interested:r,onInterested:a}),(0,G.jsx)(V6,{label:`Coaching & gyms`,features:xse,interested:r,onInterested:a})]})]}),r.size>0&&(0,G.jsx)(wse,{})]})]})}var U6=({doc:e,onDocChange:t,onBlocksChange:n,onRun:r,theme:i,withRingTargets:a=!1,editorSlot:o})=>{let s=M6(`editor.wodBlock`),c=M6(`editor.runButton`),l=(0,W.useRef)(null),u=(0,W.useRef)(null),[d,f]=(0,W.useState)(null),[p,m]=(0,W.useState)(null),h=(0,W.useCallback)(()=>{if(!a)return null;let e=l.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}}}f(t);let i=null,o=e.querySelector(`[data-testid="${$.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 m(i),{block:t,run:i}},[a]);(0,W.useLayoutEffect)(()=>{if(!a)return;let e=l.current;if(!e)return;h();let t=window.setTimeout(h,120),n=window.setTimeout(h,480),r=null;if(typeof ResizeObserver<`u`){r=new ResizeObserver(h),r.observe(e);let t=u.current?.contentDOM;t&&r.observe(t)}let i=new MutationObserver(e=>{e.some(e=>e.target instanceof Element&&e.target.closest(`.cm-note-editor`))&&h()});i.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`]});let o=0,s=0,c=()=>{h(),performance.now()-s<3e3&&(o=requestAnimationFrame(c))},d=()=>{s=performance.now(),cancelAnimationFrame(o),o=requestAnimationFrame(c)};d(),document.fonts?.ready?.then(d).catch(()=>{});let f=u.current?.scrollDOM;return f?.addEventListener(`scroll`,h,{passive:!0}),window.addEventListener(`resize`,h),()=>{window.clearTimeout(t),window.clearTimeout(n),r?.disconnect(),i.disconnect(),f?.removeEventListener(`scroll`,h),window.removeEventListener(`resize`,h),cancelAnimationFrame(o)}},[e,a,h]);let g=(0,W.useCallback)(()=>{r()},[r]),_=o??l4,v=(0,W.useMemo)(()=>[{id:`run`,label:`Run`,icon:(0,G.jsx)(bt,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:g},{id:`playground`,label:`Playground`,icon:(0,G.jsx)(Nr,{className:`h-3 w-3`}),onClick:e=>{Uoe(e)},splitIcon:(0,G.jsx)(Fe,{className:`h-3 w-3`}),splitSuccessIcon:(0,G.jsx)(xt,{className:`h-3 w-3 text-emerald-500`}),onSplitClick:e=>{v6(e)}}],[g]);return(0,G.jsx)(`div`,{className:`relative flex h-full flex-col bg-background text-left`,children:(0,G.jsxs)(`div`,{ref:l,className:`relative flex-1 min-h-0`,children:[(0,G.jsx)(_,{noteId:`canvas:home`,ariaLabel:`Home workout editor`,value:e,onChange:t,onBlocksChange:n,onStartWorkout:g,commands:v,onViewCreated:e=>{u.current=e,a&&h()},theme:i,readonly:!1,showLineNumbers:!1,showFrontmatter:!1,enableOverlay:!1,enableInlineRuntime:!1,className:`h-full`}),a&&d&&(0,G.jsx)(`div`,{ref:s,"data-testid":`tour-wod-block-region`,"aria-hidden":!0,className:`pointer-events-none absolute`,style:{top:d.top,left:d.left,width:d.width,height:d.height}}),a&&p&&(0,G.jsx)(`div`,{ref:c,"data-testid":`tour-run-button-region`,"aria-hidden":!0,className:`pointer-events-none absolute`,style:{top:p.top,left:p.left,width:p.width,height:p.height}})]})})};function Tse(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 W6=e=>{let t=Math.max(0,Math.round(e/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`},G6=e=>`${(Math.round(e/100)/10).toFixed(1)}s`;function Ese({onRun:e}){return(0,G.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,G.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,G.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,G.jsx)(bt,{className:`size-4`}),`Run to view the results`]})]})}function Dse({result:e,onRun:t}){let n=(0,W.useMemo)(()=>e?Tse(e):null,[e]);if(!e||!n)return(0,G.jsx)(Ese,{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,G.jsxs)(`div`,{className:`flex h-full w-full flex-col gap-4 overflow-y-auto p-4`,"data-testid":`tour-insights`,children:[(0,G.jsxs)(`div`,{"data-testid":`tour-insights-timeline`,children:[(0,G.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,G.jsx)(`div`,{title:`${e.label} — ${e.kind===`clock`?`countdown`:`to Next`} ${W6(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,G.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-4 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`size-2 rounded-sm`,style:{backgroundColor:`hsl(var(--metric-rest))`}}),`Countdown`]}),(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`size-2 rounded-sm`,style:{backgroundColor:`hsl(var(--metric-time))`}}),`To Next click`]}),(0,G.jsxs)(`span`,{className:`ml-auto`,children:[W6(i),` total`]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,G.jsxs)(`div`,{"data-testid":`tour-insights-impatience`,className:`rounded-xl border border-border bg-card p-4`,children:[(0,G.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground`,children:`Impatience Score`}),(0,G.jsx)(`p`,{className:`mt-2 text-2xl font-black tracking-tight text-foreground`,children:G6(a)}),(0,G.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 ${G6(u)}`:``}`})]}),(0,G.jsxs)(`div`,{"data-testid":`tour-insights-reaction`,className:`rounded-xl border border-border bg-card p-4`,children:[(0,G.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground`,children:`Reaction Time`}),(0,G.jsx)(`p`,{className:`mt-2 text-2xl font-black tracking-tight text-foreground`,children:s.length>0?G6(c):`—`}),(0,G.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[s.length,` click`,s.length===1?``:`s`,s.length>1?` · slowest ${G6(l)}`:``]})]})]})]})}var K6=864e5;function q6(e){return Math.round(e*10)/10}function J6(e,t,n=9){let r=new Date(e-t*K6);return r.setHours(n,0,0,0),r.getTime()}function Y6(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:J.Label,value:t,origin:`analyzed`},{type:J.Metric,value:n,unit:r,origin:`analyzed`,metadata:o}],sourceBlockKey:``,stackLevel:0})}var Ose=new Set([`tis`,`calc.acwr`,`calc.adherence`,`calc.ef`,`calc.pct1rm`]);function X6(e,t){return zv(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`||!Ose.has(n)||typeof t.value!=`number`?e:{...e,reducerStats:{observedCount:1,sum:t.value,min:t.value,max:t.value}}})}function kse(e=Date.now()){let t=[],n=new Map,r=[],i=[],a=(e,t)=>{let r=Cm(e);n.set(r,(n.get(r)??0)+t)};for(let n=0;n<16;n++){let o=(15-n)*7+1,s=J6(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`};Y6(r,`Total reps`,t.reps,`reps`,`totalReps`,n),Y6(r,`Training intensity score`,t.tis,`pts`,`tis`,n),Y6(r,`Total volume`,e,`kg`,`totalVolume`,n),Y6(r,`Estimated 1RM`,q6(t.top*(1+t.reps/30)),`kg`,`calc.e1rm`,n),Y6(r,`%1RM intensity`,q6(100/(1+t.reps/30)),`%`,`calc.pct1rm`,n)}let c=q6(i/100+13+o/10);Y6(r,`Session load`,c,`AU`,`sessionLoad`,{discipline:`strength`,intensityTier:`high`}),t.push(...X6(r,{noteId:`example-strength-w${n}`,resultId:`example-strength-w${n}-r`,blockContentId:`example-content-strength`,timestamp:s})),a(s,c)}let c=J6(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};Y6(e,`Total reps`,n,`reps`,`totalReps`,o),Y6(e,`Training intensity score`,q6(n*i),`pts`,`tis`,o),a&&Y6(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};Y6(e,`Total reps`,o,`reps`,`totalReps`,s),Y6(e,`Training intensity score`,q6(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};Y6(e,`Total reps`,n,`reps`,`totalReps`,a),Y6(e,`Training intensity score`,q6(n*i),`pts`,`tis`,a)}}let i=q6(30.6);Y6(e,`Session load`,i,`AU`,`sessionLoad`,{intensityTier:r}),t.push(...X6(e,{noteId:`example-conditioning-w${n}`,resultId:`example-conditioning-w${n}-r`,blockContentId:`example-content-conditioning`,timestamp:c})),a(c,i)}let l=J6(e,o+4,8);if(n%4==1)r.push(Cm(l));else{let e=6e3+100*n,r=q6(e/2.8),o=[],s={effortSlug:`running`,discipline:`running`,intensityTier:`low`};Y6(o,`Total distance`,e,`m`,`totalDistance`,s),Y6(o,`Elapsed time`,r,`s`,`elapsed`,s),Y6(o,`Training intensity score`,r,`pts`,`tis`,s);let c=q6(r/10);Y6(o,`Session load`,c,`AU`,`sessionLoad`,{intensityTier:`low`}),t.push(...X6(o,{noteId:`example-run-w${n}`,resultId:`example-run-w${n}-r`,blockContentId:`example-content-run`,timestamp:l})),a(l,c),i.push({day:Cm(l),pace:e/r})}let u=J6(e,o+6,10);{let e=4e3+50*n,r=q6(e/2),i=[],o={effortSlug:`rowing`,discipline:`rowing`,intensityTier:`moderate`};Y6(i,`Total distance`,e,`m`,`totalDistance`,o),Y6(i,`Elapsed time`,r,`s`,`elapsed`,o),Y6(i,`Training intensity score`,r,`pts`,`tis`,o);let s=q6(r/10);Y6(i,`Session load`,s,`AU`,`sessionLoad`,{intensityTier:`moderate`}),t.push(...X6(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*K6);return n.setHours(t,0,0,0),n.getTime()},c=(e,n,r)=>{let i=[];for(let[e,t,n]of r)Y6(i,e,t,n,e);t.push(...X6(i,{noteId:`example-calc`,resultId:e,blockContentId:`example-content-calc`,timestamp:n}))};for(let e of wm(n,o))e.acwr!==void 0&&c(`example-calc-d${e.day}`,s(e.day),[[`calc.acwr`,q6(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`,q6(l),`AU`],[`calc.atl`,q6(u),`AU`],[`calc.tsb`,q6(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`,q6(e.pace/141*1e5),`pts`]]);return t}function Ase(e=Date.now()){return new Fy(vb(kse(e)))}var jse=null;function Mse(){return jse??=Ase()}var Nse=[4,8,16],Pse={parse(e){let t=Number.parseInt(e,10);return Nse.includes(t)?t:null},serialize(e){return String(e)},withDefault(e){return{...this,defaultValue:e}}};function Z6(){return ie(`weeks`,Pse.withDefault(16))}function Fse({boardSlug:e}){let t=Mse(),n=nN(),r=(0,W.useMemo)(()=>n?Oz(n):[],[n]),i=(0,W.useMemo)(()=>r.find(t=>t.slug===e)??r[0],[r,e]),a=(0,W.useMemo)(()=>{if(!i?.rawContent)return null;try{let{meta:e,sections:t}=Ky(i.rawContent);return Tv(t,e)}catch{return null}},[i]),[o,s]=Z6(),[c,l]=(0,W.useMemo)(()=>{let e=Date.now();return[e-o*7*864e5,e]},[o]),[u,d]=(0,W.useState)(null);return(0,G.jsxs)(`div`,{className:`flex h-full w-full flex-col`,"data-testid":`tour-session-dashboard`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-5 pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`truncate text-[11px] font-semibold uppercase tracking-wide text-primary`,children:i?.title??e}),(0,G.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,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsx)(kT,{weeks:o,onWeeksChange:s})})]}),(0,G.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,G.jsx)(OT,{document:a,executor:t,onInspectWidget:d,rangeStart:c,rangeEnd:l}):(0,G.jsx)(`p`,{className:`pt-8 text-center text-sm text-muted-foreground`,children:`Loading board…`})}),(0,G.jsx)(n3,{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?yv(a.tokens):void 0,onApply:void 0})]})}var Ise=[`analytics`,`boards`],Lse={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 Q6({scope:e}){let t=Lse[e],n=t.heading;return(0,G.jsxs)(`div`,{children:[(0,G.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,G.jsx)(`span`,{className:`font-mono text-xs font-normal tracking-normal text-muted-foreground`,children:t.index}),(0,G.jsx)(`span`,{children:t.title})]}),(0,G.jsx)(`p`,{className:`mt-3 max-w-xl text-[clamp(14px,1.2vw,18px)] leading-[1.65] text-muted-foreground`,children:t.blurb})]})}var $6=[{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 e8({onClick:e}){return(0,G.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,G.jsx)(dr,{className:`size-3`}),`Editor`]})}function t8({session:e,onRun:t,onBackToEditor:n}){let[r,i]=(0,W.useState)(`analytics`),[a,o]=(0,W.useState)(0),s=$6[a],c=(0,W.useRef)(new Map);(0,W.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,G.jsx)(N1,{title:`Session Insights`,className:`h-[460px]`,headerActions:(0,G.jsx)(e8,{onClick:n}),children:(0,G.jsx)(Dse,{result:e,onRun:t})}):(0,G.jsxs)(`div`,{className:`flex h-full flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,G.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:$6.map((e,t)=>(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":a===t,"data-testid":`dashboard-slide-tab-${e.id}`,onClick:()=>o(t),className:K(`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,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(e=>(e+$6.length-1)%$6.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,G.jsx)(V,{className:`size-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(e=>(e+1)%$6.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,G.jsx)(gt,{className:`size-4`})})]})]}),(0,G.jsx)(N1,{title:s.title,className:`min-h-0 flex-1`,headerActions:(0,G.jsx)(e8,{onClick:n}),children:(0,G.jsx)(`div`,{className:`flex h-full w-full flex-col`,role:`tabpanel`,children:(0,G.jsx)(Fse,{boardSlug:s.id})},s.id)}),(0,G.jsxs)(`p`,{className:`text-center font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground`,children:[a+1,` / `,$6.length]})]}),d=(0,G.jsx)(`div`,{"data-testid":`tour-sticky-pane`,className:`sticky top-[104px] flex h-[calc(100dvh-104px)] flex-col items-center justify-center self-start`,children:(0,G.jsx)(`div`,{className:`relative w-full max-w-[700px]`,children:(0,G.jsx)(`div`,{className:`relative h-[460px]`,children:Ise.map(e=>(0,G.jsx)(`div`,{"aria-hidden":r!==e,"data-scope-active":r===e,className:K(`absolute inset-0 transition-opacity duration-500`,r===e?`opacity-100`:`invisible opacity-0`),children:u(e)},e))})})}),f=(e,t)=>(0,G.jsx)(`div`,{ref:l(e),"data-scope":e,className:`flex min-h-[85vh] flex-col justify-center scroll-mt-[104px]`,...t,children:(0,G.jsx)(Q6,{scope:e})}),p=e=>(0,G.jsxs)(`div`,{"data-testid":`tour-step-mobile-${e}`,"data-scope":e,className:`flex flex-col gap-4`,children:[(0,G.jsx)(Q6,{scope:e}),(0,G.jsx)(`div`,{className:`h-[460px]`,children:u(e)})]}),m=OK();return(0,G.jsx)(`section`,{id:`tour-section-insights`,"data-testid":`tour-section-insights`,className:`border-b border-border/60`,children:m?(0,G.jsxs)(`div`,{className:`flex flex-col gap-12 px-5 py-14`,children:[p(`analytics`),p(`boards`)]}):(0,G.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,G.jsxs)(`div`,{className:`flex flex-col`,children:[(0,G.jsx)(`div`,{id:`tour-scroll-target-insights`,className:`scroll-mt-[104px]`,children:f(`analytics`)}),f(`boards`,{id:`tour-section-boards`,"data-testid":`tour-section-boards`})]}),d]})})}function Rse(e){let t=e.match(/^notebook\.(.+)$/);return t?{slug:t[1]}:null}function zse(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 Bse(e,t,n){let r=[],i=new Map;if(t)for(let e of PM(`notebooks`,t))i.set(e.id,e),r.push(zse(e));let a=e.map(e=>{let t=Rse(e.chunkId);if(!t)return null;let r=i.get(t.slug),a=vP(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)),...Vse(t)]}function Vse(e){return so.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 Hse(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 Use(e,t,n,r){return Hse(Bse(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 Wse(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 Gse(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 n8=[`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 Kse(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return n8[Math.abs(t)%n8.length]}function qse(e){return(e.match(/[a-z0-9]/i)?.[0]??`•`).toUpperCase()}function Jse(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 Yse=4;function r8({feed:e,testId:t=`feed-card`,className:n,onImport:r,importing:i,busy:a,status:o,onToggleNotebookSubscription:s}){let[c,l]=Kse(e.slug).split(` `),u=Jse(e.latestDate),d=e.notebooks.slice(0,Yse),f=e.notebooks.length-d.length,p=e.installed&&e.feedId?e.href:void 0,m=e.notebooks.find(e=>e.image)?.image,h=(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[e.notebooks.length,` `,e.notebooks.length===1?`notebook`:`notebooks`]}),e.installed&&e.itemCount>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[e.itemCount,` `,e.itemCount===1?`item`:`items`]})]}),e.installed&&u&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[`updated `,u]})]}),!e.installed&&(0,G.jsx)(`span`,{"aria-hidden":!0,children:`·`}),!e.installed&&(0,G.jsx)(`span`,{children:`not imported`})]}),g=(0,G.jsx)(`div`,{className:K(`relative overflow-hidden bg-muted/40 aspect-[16/10]`,c),children:m?(0,G.jsx)(`img`,{src:m,alt:``,loading:`lazy`,className:`absolute inset-0 size-full object-cover`}):(0,G.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:[(0,G.jsx)(`span`,{className:K(`text-7xl font-black tracking-tighter select-none`,l),"aria-hidden":!0,children:qse(e.label)}),(0,G.jsx)($t,{className:K(`absolute bottom-4 right-4 size-6 opacity-50`,l),"aria-hidden":!0})]})});return(0,G.jsxs)(`article`,{"data-testid":t,"data-installed":e.installed,className:K(`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:[p?(0,G.jsx)(ve,{to:p,"data-testid":`${t}-open`,className:`block outline-none`,"aria-label":`Open the library for ${e.label}`,children:g}):g,(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col gap-2 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsx)(`h3`,{className:`min-w-0 text-sm font-bold leading-snug text-foreground`,children:p?(0,G.jsx)(ve,{to:p,className:`transition-colors hover:text-primary`,children:e.label}):e.label}),p?(0,G.jsx)(ve,{to:p,"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,G.jsx)(On,{className:`size-3.5`,"aria-hidden":!0})}):r&&e.feedId?(0,G.jsxs)(`button`,{type:`button`,"data-testid":`${t}-import`,disabled:i||a,onClick:()=>r(e.feedId),className:K(`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,G.jsx)(Sr,{className:`size-3 animate-spin`,"aria-hidden":!0}):(0,G.jsx)(Te,{className:`size-3`,"aria-hidden":!0}),i?`Importing`:`Import feed`]}):null]}),e.description&&(0,G.jsx)(`p`,{className:`line-clamp-2 text-xs leading-relaxed text-muted-foreground`,children:e.description}),e.notebooks.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`${t}-notebooks`,children:[d.map(n=>(0,G.jsxs)(`span`,{"data-testid":`${t}-notebook-${n.packageId}`,className:K(`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-800`:`border-border text-muted-foreground`),children:[n.installed?(0,G.jsx)(ve,{to:n.href,className:`hover:text-primary`,children:n.label}):(0,G.jsx)(`span`,{children:n.label}),s&&e.feedId&&n.chunkId&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.preventDefault(),t.stopPropagation(),s(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)),f>0&&(0,G.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`,children:[`+`,f,` more`]})]}),(0,G.jsxs)(`div`,{className:`mt-auto pt-1`,children:[h,o&&(0,G.jsx)(`p`,{role:o.tone===`error`?`alert`:`status`,"data-testid":`${t}-status`,className:K(`mt-1.5 flex items-start gap-1.5 text-xs`,o.tone===`error`?`text-destructive`:`text-muted-foreground`),children:(0,G.jsx)(`span`,{children:o.text})})]})]})]})}function i8({direction:e,children:t,testId:n,className:r}){let i=(0,W.useRef)(null),a=(0,W.useRef)(null),[o,s]=(0,W.useState)(1),c=A1(`(prefers-reduced-motion: reduce)`);(0,W.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,G.jsx)(`div`,{ref:i,"data-testid":n,className:K(`wod-marquee overflow-hidden`,r),children:(0,G.jsx)(`div`,{ref:a,className:K(`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,G.jsx)(`div`,{"data-marquee-copy":n,"aria-hidden":n>0,inert:n>0,className:`flex shrink-0 items-stretch gap-4 pr-4`,children:t},n))})})}var Xse=[{value:`updated`,label:`Updated`},{value:`name`,label:`Name`},{value:`size`,label:`Size`}],a8=`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 o8(e){let t=e.icon;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-foreground text-background`,children:(0,G.jsx)(t,{className:`size-5`,"aria-hidden":!0})}),(0,G.jsx)(`h3`,{className:`mt-4 text-base font-semibold text-foreground`,children:e.title}),(0,G.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-muted-foreground`,children:e.description})]}),e.note?(0,G.jsx)(`span`,{className:`mt-4 text-xs font-medium text-muted-foreground`,children:e.note}):(0,G.jsxs)(`span`,{className:`mt-4 inline-flex items-center gap-1.5 text-sm font-medium text-foreground`,children:[(0,G.jsx)(`span`,{children:e.action}),(0,G.jsx)(On,{className:`size-4 transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0})]})]})}function s8({feedDeps:e}={}){let t=(0,W.useMemo)(()=>({isNotebookSubscribed:hI,setNotebookSubscribed:gI,setFeedSubscribed:mI,subscribeFeedSubscriptions:vI,syncFeedSource:ML,readFeedCoverage:LL,...e}),[e]),n=lt(),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(`updated`),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)({}),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(),[h,g]=(0,W.useState)(0);(0,W.useEffect)(()=>t.subscribeFeedSubscriptions(()=>g(e=>e+1)),[t]);let _=s!==null,v=nN(),y=A1(`(min-width: 1024px)`),b=(0,W.useMemo)(()=>Use(CP(),v,SP(),(e,n)=>t.isNotebookSubscribed(e,n)),[v,h,t]),x=(0,W.useMemo)(()=>Gse(Wse(b,{text:r,feedId:p,subscribedOnly:d}),a),[b,r,a,p,d]),S=Math.ceil(x.length/2),C=x.slice(0,S),w=x.slice(S),T=(0,W.useCallback)(()=>{KP.record(qP.libraryOpened)},[]),[E,D]=(0,W.useState)(!0);(0,W.useEffect)(()=>{let e=!1,n=()=>{t.readFeedCoverage().then(t=>{e||D(t.libraryImported)}).catch(()=>{})};n();let r=t.subscribeFeedSubscriptions(n);return()=>{e=!0,r()}},[_,t]);let O=(0,W.useCallback)(async e=>{if(s)return;c(e);let n=t=>u(n=>({...n,[e]:t}));n({text:`Checking the feed…`,tone:`muted`});try{let r=await t.syncFeedSource(e,{onProgress:e=>n({text:hq(e),tone:`muted`})});n(r===`imported`||r===`current`?{text:mI(e,!0)?r===`imported`?`Imported — this feed is available offline.`:`Already up to date.`:`Subscribed for this session only — browser storage is unavailable.`,tone:`muted`}:{text:r===`server-stale`?`Published version is older than stored copy.`:r===`busy`?`Another tab is syncing. Try again shortly.`:`Sync failed. Check connection and try again.`,tone:`error`})}catch(e){n({text:e instanceof Error?e.message:String(e),tone:`error`})}finally{c(null)}},[s,t]),k=(0,W.useCallback)(async(e,n,r)=>{t.setNotebookSubscribed(e,n,r),r&&t.syncFeedSource(e,{force:!1})},[t]),A=(0,W.useCallback)(async()=>{let e=Lz(),t=await Uz.create({journalDate:e,title:e,rawContent:``});KP.record(qP.noteCreated),n(rz(t.id))},[n]),j=!!r.trim();return(0,G.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,G.jsx)(F3,{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,G.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`relative w-full sm:w-64`,children:[(0,G.jsx)(Ye,{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,G.jsx)(`input`,{type:`search`,value:r,onChange:e=>i(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 outline-none transition-colors focus:border-primary/50`}),r&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(``),"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,G.jsx)(Bn,{className:`size-3.5`})})]}),(0,G.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,G.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),"data-testid":`filter-subscribed-only`,className:`size-4 accent-primary rounded`}),(0,G.jsx)(`span`,{className:`text-[10px] font-black uppercase tracking-widest`,children:`Subscribed only`})]}),(0,G.jsxs)(`select`,{value:p??``,onChange:e=>m(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,G.jsx)(`option`,{value:``,children:`All feeds`}),SP().map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center gap-1.5`,role:`group`,"aria-label":`Sort feeds`,children:Xse.map(e=>{let t=a===e.value;return(0,G.jsx)(`button`,{type:`button`,"aria-pressed":t,"data-testid":`package-sort-${e.value}`,onClick:()=>o(e.value),className:K(`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,G.jsx)(`div`,{"data-testid":`jump-grid`,className:`mt-6`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[E?(0,G.jsx)(ve,{to:`/notebooks`,onClick:T,"data-testid":`jump-library`,className:a8,children:(0,G.jsx)(o8,{icon:Wt,title:`Library`,description:`Curated workouts and sessions, organized by tag.`,action:`Open the library`})}):(0,G.jsx)(`div`,{"data-testid":`jump-library`,"aria-disabled":`true`,className:`${a8} cursor-not-allowed opacity-60`,children:(0,G.jsx)(o8,{icon:Wt,title:`Library`,description:`Curated workouts and sessions, organized by tag.`,action:`Open the library`,note:`0 feeds synchronized`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{A()},"data-testid":`jump-new-note`,className:a8,children:(0,G.jsx)(o8,{icon:Et,title:`Start your own journal`,description:`Create today's note and log your first workout.`,action:`Create today's note`})})]})})]}),(0,G.jsx)(`div`,{"data-testid":`jump-rows`,className:`mt-6`,children:x.length>0?y?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(i8,{direction:`left`,testId:`jump-row-a`,children:C.map(e=>(0,G.jsx)(r8,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] sm:w-[320px] shrink-0`,onImport:O,importing:!!e.feedId&&s===e.feedId,busy:_,status:e.feedId?l[e.feedId]:void 0,onToggleNotebookSubscription:k},e.feedId??e.slug))}),w.length>0&&(0,G.jsx)(i8,{direction:`right`,testId:`jump-row-b`,className:`mt-4`,children:w.map(e=>(0,G.jsx)(r8,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] sm:w-[320px] shrink-0`,onImport:O,importing:!!e.feedId&&s===e.feedId,busy:_,status:e.feedId?l[e.feedId]:void 0,onToggleNotebookSubscription:k},e.feedId??e.slug))})]}):(0,G.jsx)(i8,{direction:`alternate`,testId:`jump-row-mobile`,children:x.map(e=>(0,G.jsx)(r8,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] shrink-0`,onImport:O,importing:!!e.feedId&&s===e.feedId,busy:_,status:e.feedId?l[e.feedId]:void 0,onToggleNotebookSubscription:k},e.feedId??e.slug))}):(0,G.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:(0,G.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,G.jsx)(`p`,{className:`text-sm font-bold text-muted-foreground`,children:`No feeds match your search.`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Try a different term or clear the filters.`}),j&&(0,G.jsx)(`button`,{type:`button`,"data-testid":`jump-clear-filters`,onClick:()=>{i(``),m(void 0),f(!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,G.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:(0,G.jsx)(`p`,{className:`mt-4 font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground xl:text-[11px]`,children:`— or keep scrolling ↓`})})]})}var Zse=`wods/examples/home/welcome-1.md`;function Qse({wodFiles:e,theme:t,quests:n,editorSlot:r,timerSlot:i,deps:a,jumpFeedDeps:o}){let s=a?.usePlaygroundRun??_1,c=a?.useQuickStartAutoComplete??k1,l=a?.useCompletionChallenge??O1,u=a?.useRunStartedChallenge??ose,d=a?.useTourScrollQuests??lse,f=a?.toast??Z,p=A1(`(prefers-reduced-motion: reduce)`),m=JP()?.track;YP(`/`);let h=(0,W.useMemo)(()=>TK(Zse,e),[e]),[g,_]=(0,W.useState)(()=>ise()),v=g?.content??h,y=g?g.by?.trim()||`anonymous`:void 0;(0,W.useEffect)(()=>{let e=e=>{let t=e.detail;t?.content&&(_(t),x(t.content))};return window.addEventListener(`wodwiki:home-shared`,e),()=>window.removeEventListener(`wodwiki:home-shared`,e)},[]);let[b,x]=(0,W.useState)(v),S=(0,W.useRef)(b);S.current=b;let C=(0,W.useRef)([]),w=(0,W.useRef)(!1),{run:T,start:E,finalize:D,end:O}=s(),k=(0,W.useRef)(T);k.current=T;let A=(0,W.useRef)(!1),j=(0,W.useRef)(!1),M=(0,W.useRef)(null),[N,P]=(0,W.useState)(!1),F=(0,W.useRef)(!1),I=(0,W.useRef)(null),[ee,L]=(0,W.useState)(null),[te,R]=(0,W.useState)(!1),ne=(0,W.useRef)(te);ne.current=te;let z=(0,W.useRef)(!1),B=(0,W.useRef)(()=>{}),[V,re]=(0,W.useState)(0),[ie,ae]=(0,W.useState)(!1),[oe,se]=(0,W.useState)(!1),[ce,le]=(0,W.useState)(null),H=(0,W.useCallback)(async(e,t,n)=>{if(!t||z.current)return!1;z.current=!0,j.current=!1,A.current=!1,M.current=null,le(t),re(e=>e+1),ae(!0),L(null),R(!0);try{await E(e,t,{pageTitle:`Home`,sectionTitle:n})}catch(e){return console.error(`[HomeTour] failed to persist playground run note:`,e),R(!1),le(null),f({title:`Could not start workout`,description:`The playground entry could not be saved.`,variant:`destructive`}),!1}finally{z.current=!1}return!0},[E]),ue=(0,W.useCallback)(async()=>{if(F.current=!1,P(!1),M.current)try{await D(M.current,!1),M.current=null}catch(e){console.error(`[HomeTour] retry save failed:`,e),f({title:`Session still not saved`,description:`The run is kept — try again.`,variant:`destructive`});return}let e=I.current;if(I.current=null,e)switch(e.kind){case`apply-doc`:w.current=!1,x(e.doc),R(!1),le(null),re(e=>e+1),ae(!1);break;case`restart`:await H(e.doc,e.block,e.sectionTitle)}},[H,D]),U=(0,W.useCallback)(e=>{if(!I.current){if(!k.current||j.current||!A.current||M.current){I.current=e,ue();return}I.current=e,F.current=!0,P(!0)}},[ue]),de=(0,W.useRef)(null),fe=(0,W.useRef)(null),pe=(0,W.useRef)(null);j4(`hero`,pe);let[me,he]=(0,W.useState)(!1),ge=(0,W.useRef)(me);ge.current=me;let _e=(0,W.useCallback)(()=>{let e=document.getElementById(`tour-section-editor`),t=de.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:p?`auto`:`smooth`})},[p]),ye=(0,W.useCallback)(()=>{he(!0),window.setTimeout(_e,350)},[_e]),be=(0,W.useCallback)(()=>{he(!1),window.scrollTo({top:0,behavior:p?`auto`:`smooth`})},[p]),xe=(0,W.useRef)(!1),Se=(0,W.useCallback)(()=>{U({kind:`apply-doc`,doc:v})},[v,U]);(0,W.useEffect)(()=>{let e=fe.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting?xe.current&&!ne.current&&(xe.current=!1,Se()):xe.current=!0});return t.observe(e),()=>t.disconnect()},[Se]);let Ce=(0,W.useCallback)(()=>{ase(),_(null),U({kind:`apply-doc`,doc:h})},[h,U]),we=(0,W.useCallback)(()=>{Se();let e=document.getElementById(`tour-section-editor`),t=de.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:p?`auto`:`smooth`})},[p,Se]);c({pageRoute:`/`,quests:n,initialSource:v,currentSource:b}),l({pageRoute:`/`,quests:n,completedResults:ee}),B.current=d(`/`,n),u({pageRoute:`/`,quests:n,running:oe}),(0,W.useEffect)(()=>{let e=document.getElementById(`tour-section-insights`);if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting&&B.current?.(`session-insights`)});return t.observe(e),()=>t.disconnect()},[]);let Te=(0,W.useCallback)(e=>{x(e),e!==v&&!w.current&&(w.current=!0,m?.(qP.demoEdited))},[v,m]),Ee=(0,W.useCallback)(e=>{C.current=e},[]),De=(0,W.useCallback)((e,t,n,r)=>{if(n){if(m?.(qP.demoRun),r&&se(!0),le(n),R(!0),ae(!0),re(e=>e+1),L(null),z.current||I.current){I.current={kind:`restart`,doc:t,block:n,sectionTitle:e};return}if(k.current&&A.current&&!j.current){I.current={kind:`restart`,doc:t,block:n,sectionTitle:e},F.current=!0,P(!0);return}if(k.current&&!j.current){O().then(()=>H(t,n,e));return}H(t,n,e)}},[H,O,m]),Oe=(0,W.useCallback)(()=>{De(`Run`,S.current,C.current[0],!0)},[De]),ke=(0,W.useCallback)(()=>{let e=()=>{let e=document.getElementById(`tour-section-insights`),t=de.current;if(!e||!t||typeof window.scrollTo!=`function`)return;let n=t.getBoundingClientRect().top+window.scrollY,r=Math.max(0,e.getBoundingClientRect().top+window.scrollY-n);window.scrollTo({top:r,behavior:p?`auto`:`smooth`})};if(ge.current){e();return}he(!0),window.setTimeout(e,350)},[p]),Ae=(0,W.useCallback)((e,t)=>{if(!(j.current&&!M.current))return(t.logs??[]).length===0?(j.current=!0,L(t),R(!1),ke(),ue()):(j.current=!0,D(t,t.completed).then(()=>{if(M.current=null,L(t),F.current||I.current)return R(!1),ue()}).catch(e=>{throw j.current=!1,A.current=!1,M.current=t,F.current=!1,P(!1),I.current=null,f({title:`Session not saved`,description:`The run could not be recorded. Nothing was lost — your next action retries the save.`,variant:`destructive`}),e}))},[D,ue,ke]),je=(0,W.useCallback)(()=>{R(!1),ke()},[ke]),Me=(0,W.useRef)(null),Ne=(0,W.useCallback)(e=>{Me.current=e},[]),Pe=(0,W.useCallback)(()=>{A.current=!0;let e=Me.current;ie&&e&&e.handle(new Gp(void 0,e.nowProvider)),ae(!1)},[ie]),{setL3Items:Fe}=SR(),Ie=(0,W.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:Oe}}},{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`}}],[Oe]);(0,W.useEffect)(()=>(Fe(Ie),()=>Fe([])),[Fe,Ie]),dse((0,W.useMemo)(()=>Ie.map(e=>e.action.type===`scroll`?e.action.sectionId:e.id),[Ie]));let Le=T?.block??ce,Re=te&&Le&&(0,G.jsx)(i??u2,{block:Le,resultId:T?.resultId,autoStart:ie,externalStop:N,onRunStarted:Pe,onRuntimeReady:Ne,onClose:je,onCompleteWorkout:Ae},V),ze=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(H6,{}),(0,G.jsxs)(`p`,{className:`-mt-8 text-center font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground xl:text-[11px]`,children:[`— or learn the language with examples`,` `,(0,G.jsx)(ve,{to:`/syntax`,className:`text-foreground underline underline-offset-4 transition-colors hover:text-primary`,children:`on the syntax page →`})]})]}),Be=(0,G.jsx)(M4,{gateId:`editor-pane`,segmentId:`hero`,className:`w-full max-w-[720px] xl:max-w-[820px] 2xl:max-w-[920px]`,children:(0,G.jsx)(N1,{title:y?y.toLowerCase().startsWith(`shared by`)?y:`shared by: ${y}`:`welcome-1.md`,headerActions:y&&(0,G.jsx)(`button`,{type:`button`,onClick:Ce,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,G.jsx)(U6,{doc:b,theme:t,onDocChange:Te,onBlocksChange:Ee,onRun:Oe,editorSlot:r})})}),Ve=(0,G.jsx)(`div`,{id:`tour-why-video-wrap`,"aria-hidden":me,className:K(`grid w-full transition-all duration-300 motion-reduce:transition-none`,me?`grid-rows-[0fr] opacity-0 invisible`:`grid-rows-[1fr] opacity-100`),children:(0,G.jsx)(`div`,{className:`min-h-0 overflow-hidden`,children:(0,G.jsx)(mse,{onWatched:ye})})}),He=(0,G.jsxs)(`div`,{ref:fe,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:[me&&(0,G.jsxs)(`button`,{type:`button`,onClick:be,"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,G.jsx)(bt,{className:`size-3`}),`Watch again`]}),Be]});return p?(0,G.jsxs)(`div`,{"data-testid":`home-tour`,children:[(0,G.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,G.jsx)(N6,{}),Ve,He]}),(0,G.jsx)(t8,{session:ee,onRun:Oe,onBackToEditor:we}),(0,G.jsx)(s8,{feedDeps:o}),ze,(0,G.jsx)(B3,{variant:`university`}),(0,G.jsx)(F6,{}),Re]}):(0,G.jsxs)(`div`,{"data-testid":`home-tour`,children:[(0,G.jsx)(`div`,{ref:de,"aria-hidden":!0,className:`h-px`}),(0,G.jsxs)(`section`,{ref:pe,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,G.jsx)(N6,{}),Ve,He]}),(0,G.jsx)(t8,{session:ee,onRun:Oe,onBackToEditor:we}),(0,G.jsx)(s8,{feedDeps:o}),ze,(0,G.jsx)(B3,{variant:`university`}),(0,G.jsx)(F6,{}),Re]})}function $se(e){return(0,G.jsx)(A6,{children:(0,G.jsx)(A4,{children:(0,G.jsx)(Qse,{...e})})})}function ece({wodFiles:e,theme:t}){let n=(0,W.useMemo)(()=>E6(e),[e]);return(0,W.useEffect)(()=>{Pw(`homeFirstPaint`)},[]),(0,G.jsx)($se,{wodFiles:n,theme:t,quests:T6.quests})}var tce=[`📓`,`🏋️`,`🔥`,`💪`,`⭐`,`🎯`,`🏃`,`🧘`,`🥊`,`🚴`],nce=({open:e,onOpenChange:t,onCreate:n,notebook:r,onSave:i})=>{let[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(`📓`),[d,f]=(0,W.useState)(!1),p=!!r;W.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,G.jsx)(eZ,{open:e,onOpenChange:t,children:(0,G.jsxs)(tZ,{className:`bg-popover text-popover-foreground border border-border`,children:[(0,G.jsxs)(nZ,{children:[(0,G.jsx)(rZ,{className:`text-foreground`,children:p?`Edit Notebook`:`Create Notebook`}),(0,G.jsx)(iZ,{children:p?`Rename, describe or re-icon this notebook.`:`Organize your sessions into collections.`})]}),(0,G.jsxs)(`div`,{className:`space-y-4 mt-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm font-medium text-foreground/80 mb-2 block`,children:`Icon`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:tce.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:K(`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,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`text-sm font-medium text-foreground/80 mb-1 block`,children:[`Name `,(0,G.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.keyCode===229||e.key===`Enter`&&!e.shiftKey&&a.trim()&&(e.preventDefault(),m())},placeholder:`e.g., Morning Routines`,autoFocus:!0,className:K(`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,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`text-sm font-medium text-foreground/80 mb-1 block`,children:[`Description `,(0,G.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`(optional)`})]}),(0,G.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`A brief description of this notebook...`,rows:2,className:K(`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,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(q,{variant:`default`,size:`sm`,onClick:()=>void m(),disabled:!a.trim()||d,children:d?`Saving…`:p?`Save`:`Create`})]})]})]})})};function c8({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,W.useRef)(a),[c,l]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{if(a>s.current){l(!0);let e=setTimeout(()=>l(!1),200);return s.current=a,()=>clearTimeout(e)}s.current=a},[a]),(0,G.jsxs)(`div`,{className:K(`w-full`,r),children:[n?(0,G.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,G.jsx)(`span`,{children:n}),(0,G.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[a,`/`,i]})]}):null,(0,G.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,G.jsx)(`div`,{className:K(`h-full rounded-pill transition-[width] duration-500 ease-out`,c?`bg-brand-deep`:`bg-brand`),style:{width:`${o}%`}})})]})}function l8(e,t,n,r){FJ.getState().open({placeholder:`Craft the query…`,wql:{initialQuery:e,execute:t,onApply:n,preferredChoices:r},sources:[pX()]})}function u8({query:e,onQueryChange:t,scopeOptions:n,execute:r,defaultQuery:i,compact:a=!1,className:o}){let s=(0,W.useCallback)(()=>l8(e,r,t,n),[e,r,t,n]);return a?(0,G.jsx)(`div`,{"data-testid":`stream-query-bar-dock`,className:K(`flex min-h-12 w-full items-stretch overflow-hidden rounded-xl border border-border bg-muted/40 shadow-xs`,o),children:(0,G.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,G.jsx)(Ye,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,G.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,G.jsx)(m,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]})}):(0,G.jsx)(`div`,{"data-testid":`stream-query-bar`,className:K(`flex min-w-0 flex-1 items-center gap-1 text-xs`,o),children:(0,G.jsx)(bD,{query:e,onQueryChange:t,compact:!0,showDiagnostics:!1,hiddenClauseTypes:[`agg`,`metric`,`rollup`,`pipes`],preferredChoices:n,placeholder:`Filter or search…`,className:`min-w-0 flex-1`})})}function rce(e,t){let n=t??Y(e);return n.error?null:n.groupBy?.length?n.groupBy.map(e=>String(e).toLowerCase()):null}function d8(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/(^-|-$)/g,``)||`default`}function f8(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=ice(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 ice(e,t,n){let r=t.toLowerCase(),i=US();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`:WS(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 pB(Array.from(t.entries()),`priority-then-alpha`,{priority:[`Strength`,`Gymnastics`,`Cardio`,`Running`,`Rowing`,`Weightlifting`]}).map(([e])=>e).map(e=>({id:`group-discipline-${d8(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 pB(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-origin-${d8(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 pB(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-source-${d8(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 pB(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-kind-${d8(e)}`,key:e,label:e,entries:t}))}if(r===`feed`){let t=new Map;for(let n of e){let e=n.feedId??(n.sourceNotebook===`journal`||n.sourceNotebook===`playground`?`local`:`core`),r=t.get(e);r?r.push(n):t.set(e,[n])}return pB(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-feed-${d8(e)}`,key:e,label:e===`local`?`Local`:e===`core`?`Core`:e,entries:t}))}if(!Xm.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 pB(Array.from(t.entries()),`alpha-sink-last`,{sink:`Unassigned`}).map(([e,t])=>({id:`group-property-${d8(r)}-${d8(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 pB(Array.from(a.entries()),`alpha-sink-last`,{sink:`Untagged`}).map(([e,t])=>({id:`group-tag-${d8(e)}`,key:e,label:e,entries:t}))}var ace=[{id:IR.route,label:`Journal`,profile:IR,scopeChoices:mE,shortcuts:!0},{id:RR.route,label:`Notes`,profile:RR,scopeChoices:mE,shortcuts:!0},{id:LR.route,label:`Notebooks`,profile:LR,scopeChoices:mE,shortcuts:!0},{id:zR.route,label:`Feeds`,profile:zR,scopeChoices:mE,shortcuts:!0},{id:BR.route,label:`Pages`,profile:BR,scopeChoices:mE,shortcuts:!0},{id:VR.route,label:`Efforts`,profile:VR,scopeChoices:mE,shortcuts:!0},{id:HR.route,label:`Equipment`,profile:HR,scopeChoices:mE,shortcuts:!0},{id:UR.route,label:`Tags`,profile:UR,shortcuts:!0},{id:WR.route,label:`Sessions`,profile:WR,scopeChoices:mE,shortcuts:!0},{id:GR.route,label:`Playgrounds`,profile:GR,scopeChoices:mE,shortcuts:!0}],p8={id:`/dashboards`,label:`Dashboards`,systemDefaultWql:`:dashboard{}`},m8={id:_B,label:`Command palette`,systemDefaultWql:lX,scopeChoices:mE},oce=[...ace,p8,m8];function sce(e){return oce.find(t=>t.id===e)}var h8=`w-full rounded-md border border-border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary/40`;function cce({open:e,onOpenChange:t,route:n,editing:r=null,initialQuery:i=``}){let[a,o]=(0,W.useState)(r?.label??``),[s,c]=(0,W.useState)(r?.icon??`bookmark`),[l,u]=(0,W.useState)(r?r.wql:i),[d,f]=(0,W.useState)(null),p=KB(n);(0,W.useEffect)(()=>{e&&(o(r?.label??``),c(r?.icon??`bookmark`),u(r?r.wql:i),f(null))},[e,r,i]);let m=r!==null&&!!r.to,h=r?.id!==`all`,g=a.trim(),_=l.trim(),v=_?oD(_).error??null:null,y=g?null:`Label is required.`,b=!!g&&!m&&(!h||!!_)&&!v;return(0,G.jsx)(dE,{open:e,onClose:()=>t(!1),title:r?`Edit shortcut`:`Save search shortcut`,description:`Saved shortcuts appear in this route's navigation panel. Stored ${FP?`on the server.`:`in this browser only.`}`,footer:(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(q,{type:`submit`,form:`save-wql-shortcut-form`,size:`sm`,disabled:!b,"data-testid":`shortcut-save`,children:`Save`})]}),children:(0,G.jsxs)(`form`,{id:`save-wql-shortcut-form`,onSubmit:async e=>{if(e.preventDefault(),!b)return;let i={id:r?.id??crypto.randomUUID(),label:g,icon:s,wql:m?r.wql:_,...r?.to===void 0?{}:{to:r.to}};if(!await eV(n,[...$B(n,void 0,p).filter(e=>e.id!==i.id),i])){f(`Couldn’t save — storage is unavailable. Your input is kept.`);return}t(!1)},className:`flex flex-col gap-4`,noValidate:!0,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{htmlFor:`shortcut-label`,className:`text-xs font-semibold text-muted-foreground`,children:`Label`}),(0,G.jsx)(`input`,{id:`shortcut-label`,value:a,onChange:e=>o(e.target.value),placeholder:`e.g. Strength this month`,"data-testid":`shortcut-label-input`,"aria-invalid":y?!0:void 0,className:h8}),y&&(0,G.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`shortcut-label-error`,children:y})]}),m?(0,G.jsxs)(`p`,{className:`rounded-md border border-border/60 bg-muted/30 px-3 py-2 text-xs text-muted-foreground`,children:[`Route action — always opens `,r?.to,`. Label and icon are editable.`]}):(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{htmlFor:`shortcut-query`,className:`text-xs font-semibold text-muted-foreground`,children:`Query (WQL)`}),(0,G.jsx)(`textarea`,{id:`shortcut-query`,rows:2,value:l,onChange:e=>u(e.target.value),placeholder:h?`find …`:`Empty — the plain route landing`,"data-testid":`shortcut-query-input`,"aria-invalid":v?!0:void 0,className:`${h8} font-mono text-xs`}),v?(0,G.jsxs)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`shortcut-query-error`,children:[`Couldn't parse — `,v]}):!_&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:h?`A shortcut needs a query.`:`Empty — opens the plain route landing.`})]}),(0,G.jsxs)(`fieldset`,{className:`space-y-1.5`,children:[(0,G.jsx)(`legend`,{className:`text-xs font-semibold text-muted-foreground`,children:`Icon`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Object.entries(zB).map(([e,t])=>(0,G.jsxs)(`label`,{title:e,className:s===e?`cursor-pointer rounded-md border border-primary bg-primary/10 p-1.5 text-primary`:`cursor-pointer rounded-md border border-border p-1.5 text-muted-foreground hover:text-foreground`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`shortcut-icon`,value:e,checked:s===e,onChange:()=>c(e),"aria-label":`Icon ${e}`,"data-testid":`shortcut-icon-${e}`,className:`sr-only`}),(0,G.jsx)(t,{className:`size-4`,"aria-hidden":`true`})]},e))})]}),d&&(0,G.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`shortcut-storage-error`,children:d})]})})}function g8({className:e,...t}){return(0,G.jsx)(zt,{"data-slot":`control`,...t,className:K(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,G.jsx)(`span`,{"aria-hidden":`true`,className:K(`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 lce=Object.fromEntries([...mE,...pE].map(e=>[e.value,e.label]));function _8({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,G.jsxs)(`div`,{className:`space-y-2`,children:[e.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((t,s)=>(0,G.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,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(dr,{className:`size-3`})}),(0,G.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,G.jsx)(cee,{className:`size-3`})})]}),(0,G.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,G.jsx)(Bn,{className:`size-3`})})]},t))}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.filter(t=>!e.includes(t.value)).map(t=>(0,G.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 uce({values:e,choices:t,onChange:n,testPrefix:r}){return(0,G.jsx)(_8,{values:e,choices:t,labels:lce,onChange:n,testPrefix:r,reorderable:!0})}function dce({values:e,onChange:t,testPrefix:n}){return(0,G.jsx)(_8,{values:e,choices:lB.map(e=>({value:e.id,label:e.label})),labels:Object.fromEntries(lB.map(e=>[e.id,e.label])),onChange:t,testPrefix:n,reorderable:!0})}function v8({label:e,enabled:t,onEnabledChange:n,testId:r,children:i}){return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:e}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[`Custom`,(0,G.jsx)(g8,{checked:t,onChange:n,"data-testid":r})]})]}),i]})}function fce({shortcuts:e,icons:t,landingId:n,onEdit:r,onDelete:i,onCreate:a,error:o,testPrefix:s}){return(0,G.jsxs)(`div`,{className:`space-y-2`,"data-testid":`${s}-shortcuts`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:`Saved shortcuts`}),(0,G.jsx)(q,{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,G.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,G.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`min-w-0 max-w-40 truncate text-xs font-medium`,children:e.label}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[10px] text-muted-foreground`,children:o}),(0,G.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,G.jsx)(me,{className:`size-3`})}),!e.to&&e.id!==n&&(0,G.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,G.jsx)(Dr,{className:`size-3`})})]},e.id)}),o&&(0,G.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`${s}-shortcut-error`,children:o})]})}function y8(e){return{defaultWql:e.defaultWql??``,customScope:e.typeOptions!==void 0,scopeOptions:e.typeOptions??[],customGroupBy:e.groupByOptions!==void 0,groupByOptions:e.groupByOptions??[]}}function pce(e){return{defaultWql:e.defaultWql.trim()||void 0,typeOptions:e.customScope?e.scopeOptions:void 0,groupByOptions:e.customGroupBy?e.groupByOptions:void 0}}function b8({surface:e,onSaved:t}){let n=IB(e.id),r=oV(e.id),[i,a]=(0,W.useState)(()=>y8(n)),[o,s]=(0,W.useState)(()=>n),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null);(0,W.useEffect)(()=>{a(y8(n)),s(n),l(null),d(null)},[n]);let m=e.profile?.defaultWql??e.systemDefaultWql??``,h=(()=>{let e=i.defaultWql.trim();return e?oD(e).error??null:null})(),g=pce(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&&oD(n).error)){if(!await kB(e.id,g)){l(`Save failed — storage is unavailable; the previous default still stands.`);return}l(null),s(OB(e.id)),t?.()}},x=async()=>{if(!await AB(e.id)){l(`Reset failed — storage is unavailable; the stored override still stands.`);return}l(null),s({}),a(y8({})),t?.()},S=async t=>{d(null),await eV(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,G.jsxs)(`div`,{className:`space-y-5`,"data-testid":`query-settings-panel`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:`Landing default query`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`System default: `,(0,G.jsx)(`span`,{className:`font-mono`,children:m})]}),(0,G.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,G.jsxs)(`p`,{className:`text-xs text-destructive`,"data-testid":`query-settings-wql-error`,children:[`Couldn't parse — `,h]}):!i.defaultWql.trim()&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Empty — the system default is used.`})]}),y.length>0&&(0,G.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,G.jsx)(v8,{label:`Where-stored options`,enabled:i.customScope,onEnabledChange:e=>a({...i,customScope:e}),testId:`query-settings-scope-custom`,children:i.customScope&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(uce,{values:i.scopeOptions,choices:C,onChange:e=>a({...i,scopeOptions:e}),testPrefix:`query-settings-scope`}),i.scopeOptions.length===0&&(0,G.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,G.jsxs)(v8,{label:`Group-by options`,enabled:i.customGroupBy,onEnabledChange:e=>a({...i,customGroupBy:e}),testId:`query-settings-group-custom`,children:[(0,G.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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(dce,{values:i.groupByOptions,onChange:e=>a({...i,groupByOptions:e}),testPrefix:`query-settings-group`}),i.groupByOptions.length===0&&(0,G.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,G.jsx)(fce,{shortcuts:r,icons:zB,landingId:`all`,onEdit:e=>p({editing:e}),onDelete:S,onCreate:()=>p({editing:null}),error:u,testPrefix:`query-settings`}),c&&(0,G.jsx)(`p`,{className:`text-xs text-destructive`,"data-testid":`query-settings-storage-error`,role:`alert`,children:c}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:x,disabled:!v,"data-testid":`query-settings-reset`,children:[(0,G.jsx)(ht,{className:`size-3.5`}),(0,G.jsx)(`span`,{children:`Reset to system default`})]}),(0,G.jsx)(q,{size:`sm`,onClick:b,disabled:!_||!!h,"data-testid":`query-settings-save`,children:`Save`})]}),f&&(0,G.jsx)(cce,{open:!0,onOpenChange:e=>{e||p(null)},route:e.id,editing:f.editing})]})}function x8({surface:e,open:t,onOpenChange:n}){return(0,G.jsx)(dE,{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,G.jsx)(b8,{surface:e})})}function S8({feedParam:e,onDismiss:t,onRegistered:n,onSubscribed:r}){let[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let t=!0,n=oP(e);return n?(a(n),l(!0),h(null),new XF(n).fetchManifest().then(e=>{if(!t)return;let n=zx(e);p(n),l(!1)}).catch(e=>{t&&(h(e instanceof Error?e.message:`Failed to probe feed manifest.`),l(!1))})):(a(null),p(null),l(!1)),()=>{t=!1}},[e]);let v=()=>{let e=oP(o);if(!e){h(`Invalid feed URL. Must be an HTTPS URL.`);return}a(e),l(!0),h(null),new XF(e).fetchManifest().then(e=>{let t=zx(e);p(t),l(!1)}).catch(e=>{h(e instanceof Error?e.message:`Failed to probe feed manifest.`),l(!1)})},y=async()=>{if(!(!i||!f||u)){d(!0);try{let e=pP(f.name??`Custom Feed`,i);mI(e.id,!1),await $I(e.id,f),n(e.id)}catch(e){h(e instanceof Error?e.message:`Failed to register feed.`)}finally{d(!1)}}},b=async()=>{if(!(!i||!f||u)){d(!0),h(null);try{let e=pP(f.name??`Custom Feed`,i);mI(e.id,!1),await $I(e.id,f),await ML(e.id,{subscribe:!1,manifest:f}),r(e.id)}catch(e){h(e instanceof Error?e.message:`Import failed.`)}finally{d(!1)}}},x=async()=>{if(!(!i||!f||u)){d(!0),h(null);try{let e=pP(f.name??`Custom Feed`,i);mI(e.id,!0),xI(e.id,g),await $I(e.id,f),await ML(e.id,{manifest:f}),r(e.id)}catch(e){h(e instanceof Error?e.message:`Sync failed.`)}finally{d(!1)}}};if(!i&&!f)return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border bg-card/60 p-4 mb-4`,"data-testid":`unknown-feed-intake-banner`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs font-semibold px-2 py-0.5 rounded bg-sky-500/10 text-sky-500 border border-sky-500/30`,children:`Unknown Feed`}),(0,G.jsxs)(`span`,{className:`text-sm font-semibold text-foreground`,children:[`Feed "`,e,`" is not registered`]})]}),(0,G.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 px-2 text-xs`,children:[(0,G.jsx)(Bn,{className:`size-3.5 mr-1`}),`Dismiss`]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:[`To browse or import this feed, enter its HTTPS seed directory URL (containing `,(0,G.jsx)(`code`,{children:`manifest.json`}),`):`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(WY,{value:o,onChange:e=>s(e.target.value),placeholder:`https://example.com/seed/`,className:`text-xs h-8 flex-1`}),(0,G.jsxs)(q,{size:`sm`,onClick:v,disabled:!o.trim()||c,className:`h-8 text-xs`,children:[c?(0,G.jsx)(Sr,{className:`size-3 animate-spin mr-1`}):null,`Probe Feed`]})]}),m&&(0,G.jsx)(`p`,{className:`text-xs text-destructive mt-2`,children:m})]});if(c)return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border bg-card/60 p-4 mb-4 flex items-center gap-3 text-xs text-muted-foreground`,"data-testid":`unknown-feed-intake-banner`,children:[(0,G.jsx)(Sr,{className:`size-4 animate-spin text-primary`}),(0,G.jsxs)(`span`,{children:[`Probing feed manifest at `,(0,G.jsxs)(`code`,{children:[i,`manifest.json`]}),`…`]})]});if(m&&!f)return(0,G.jsxs)(`div`,{className:`rounded-xl border border-destructive/40 bg-destructive/10 p-4 mb-4 text-xs`,"data-testid":`unknown-feed-intake-banner`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive font-semibold`,children:[(0,G.jsx)(Jr,{className:`size-4`}),(0,G.jsx)(`span`,{children:`Feed Probe Failed`})]}),(0,G.jsx)(q,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 px-2 text-xs`,children:`Dismiss`})]}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:m})]});if(!f)return null;let S=f.notebooks?.length??f.chunks.length,C=f.notebooks?.reduce((e,t)=>e+(t.count??0),0)??f.chunks.reduce((e,t)=>e+(t.count??0),0);return(0,G.jsxs)(`div`,{className:`rounded-xl border border-sky-500/40 bg-sky-500/5 p-4 mb-4 space-y-3`,"data-testid":`unknown-feed-intake-banner`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded bg-sky-500/20 text-sky-400 border border-sky-500/30`,children:`Feed Deep Link`}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:i})]}),(0,G.jsxs)(`h3`,{className:`text-base font-bold text-foreground mt-1`,children:[`Add "`,f.name??`Custom Feed`,`" to your Library?`]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:f.description??`Published whiteboard workouts and notebooks.`})]}),(0,G.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:t,disabled:u,className:`h-7 px-2 text-xs`,children:[(0,G.jsx)(Bn,{className:`size-3.5 mr-1`}),`Decline`]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2 text-xs bg-background/50 p-3 rounded-lg border border-border/40`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-muted-foreground block text-[10px] uppercase font-bold`,children:`Version`}),(0,G.jsxs)(`span`,{className:`font-mono`,children:[`v`,f.version,` (schema `,f.schema,`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-muted-foreground block text-[10px] uppercase font-bold`,children:`Notebooks`}),(0,G.jsxs)(`span`,{children:[S,` notebooks (`,C,` items)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-muted-foreground block text-[10px] uppercase font-bold`,children:`Built`}),(0,G.jsx)(`span`,{className:`font-mono`,children:f.builtAt?f.builtAt.slice(0,10):`unknown`})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-xs`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border text-primary`}),(0,G.jsx)(`span`,{children:`Auto-sync updates`})]})})]}),m&&(0,G.jsx)(`p`,{className:`text-xs text-destructive`,children:m}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2 pt-1`,children:[(0,G.jsx)(q,{variant:`outline`,size:`sm`,onClick:y,disabled:u,"data-testid":`feed-intake-browse`,className:`text-xs h-8`,children:`Browse in Library (Register Only)`}),(0,G.jsxs)(q,{variant:`outline`,size:`sm`,onClick:b,disabled:u,"data-testid":`feed-intake-once`,className:`text-xs h-8`,children:[u?(0,G.jsx)(Sr,{className:`size-3 animate-spin mr-1`}):null,`Import Once`]}),(0,G.jsxs)(q,{size:`sm`,onClick:x,disabled:u,"data-testid":`feed-intake-subscribe`,className:`text-xs h-8 bg-sky-600 hover:bg-sky-500 text-white`,children:[u?(0,G.jsx)(Sr,{className:`size-3 animate-spin mr-1`}):null,`✓ Subscribe & Sync All`]})]})]})}var C8=e=>KS(new Date(e)),mce=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 hce(e,t){Z(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 w8={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 T8(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??w8[e.outcome]}}function gce({source:e,running:t,disabled:n,onSync:r,onSubscribe:i,onUnsubscribe:a,onDelete:o,onAutoSync:s,onToggleNotebook:c,subscribedOnly:l}){let u=lt(),d=(0,W.useSyncExternalStore)(vI,()=>bI(e.id)),f=e.notebooks.filter(t=>t.id!==e.id),p=fI(e.id),m=f.filter(e=>e.subscribed).length;l&&f.filter(e=>e.subscribed);let h=e.autoImport,g=e.subscribed&&!e.upToDate&&e.remote!==null,_=e=>{let t=e.currentTarget.closest(`details`);t&&(t.open=!1)};return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,"data-testid":`feed-source-${e.id}`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-x-4 gap-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:e.label}),(0,G.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`}),h&&(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 flex-wrap justify-end`,children:[e.subscribed?g?(0,G.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>r(e.id),disabled:n,"data-testid":`feed-sync-${e.id}`,className:`gap-2`,children:[(0,G.jsx)(B,{className:`size-3.5 ${t?`animate-spin`:``}`}),(0,G.jsx)(`span`,{children:t?`Syncing…`:`Sync`})]}):(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,"data-testid":`feed-current-${e.id}`,children:[(0,G.jsx)(be,{className:`size-3.5 text-emerald-500`}),e.remote===null?`Remote unreachable`:`Up to date`]}):(0,G.jsxs)(q,{size:`sm`,onClick:()=>i(e.id),disabled:n,"data-testid":`feed-subscribe-${e.id}`,className:`gap-2`,children:[(0,G.jsx)(Te,{className:`size-3.5`}),(0,G.jsx)(`span`,{children:`Subscribe`})]}),(0,G.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,G.jsx)(`input`,{type:`checkbox`,className:`size-3.5 accent-primary`,checked:d,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,G.jsx)(`span`,{children:`Auto-sync`})]}),(0,G.jsxs)(`details`,{className:`relative shrink-0`,"data-testid":`feed-more-${e.id}`,onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),e.currentTarget.open=!1,e.currentTarget.querySelector(`summary`)?.focus())},children:[(0,G.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,G.jsx)(`div`,{className:`fixed inset-0 z-50`,"data-testid":`feed-more-backdrop`,"aria-hidden":`true`,onClick:e=>{e.stopPropagation(),_(e)}}),(0,G.jsxs)(`div`,{className:`absolute right-0 z-[60] 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`,onClick:e=>{let t=e.target;(t.closest(`button`)||t.closest(`a`))&&_(e)},children:[e.url?(0,G.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,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Published HTML: bundled with this app (no standalone URL)`}),e.repositoryUrl?(0,G.jsx)(`a`,{href:e.repositoryUrl,target:`_blank`,rel:`noopener noreferrer`,className:`break-all text-primary hover:underline`,children:`Git source directory`}):(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Git repository: not published`}),!h&&(0,G.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`}),!h&&(0,G.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,G.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono break-all`,"data-testid":`feed-origin-${e.id}`,children:e.url}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`feed-description-${e.id}`,children:e.description}),(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/20 px-3 py-2 flex flex-wrap items-center justify-between gap-3`,"data-testid":`feed-notebooks-${e.id}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:`Subscription Mode`}),(0,G.jsx)(`div`,{className:`mt-1 flex items-center gap-2`,children:(0,G.jsx)(`span`,{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded text-xs font-semibold ${p===`full`?`bg-emerald-500/10 text-emerald-600`:p===`partial`?`bg-amber-500/10 text-amber-600`:`bg-muted text-muted-foreground`}`,"data-testid":`feed-sub-mode-${e.id}`,children:p===`full`?`Full`:p===`partial`?`Partial (${m} of ${f.length} subscribed)`:`Unsubscribed`})})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(`/notebooks?q=:notebook{feed:${e.id},subscribed:true,false}`),"data-testid":`browse-notebooks-link-${e.id}`,className:`text-xs font-semibold text-primary hover:underline flex items-center gap-1`,children:`Browse notebooks in Library →`})]}),(0,G.jsxs)(`div`,{className:`grid gap-1 text-sm`,"data-testid":`feed-status-card`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Library`}),(0,G.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`,` · `,mce(e.bytes)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Local database`}),(0,G.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 ${C8(e.stored.importedAt)}`:`Not imported yet`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Published version`}),(0,G.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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Jr,{className:`size-3.5 text-muted-foreground`}),`Unavailable`]}):`Checking…`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Last check`}),(0,G.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-last-check`,children:e.checkedAt?C8(e.checkedAt):`—`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Last sync`}),(0,G.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-last-sync`,children:e.stored?C8(e.stored.importedAt):`Never`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Status`}),(0,G.jsx)(`span`,{className:`font-medium text-xs flex items-center gap-1.5`,"data-testid":`feed-sync-status`,children:e.subscribed?e.upToDate?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(be,{className:`size-3.5 text-emerald-500`}),`Up to date`]}):e.remote==null?`Unknown (remote unreachable)`:d?`Update available — applied automatically on next load`:`Update available — sync to apply`:`Not subscribed`})]})]})]})}function _ce({deps:e={}}={}){let{readFeedStatus:t=RL,syncFeedSource:n=ML,runFeedSync:r=kL}=e,[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(!0),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)([]),[m,h]=(0,W.useState)(``),[g,_]=(0,W.useState)(``),[v,y]=(0,W.useState)(null),[b,x]=(0,W.useState)(!0),[S,C]=(0,W.useState)(),w=(0,W.useCallback)(async()=>{l(null);try{a(await t())}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}},[]);(0,W.useEffect)(()=>{w()},[w]),(0,W.useEffect)(()=>vI(()=>{w()}),[w]),(0,W.useEffect)(()=>SL(()=>{w()}),[w]);let T=(0,W.useCallback)(async e=>{d(e??`all`),p([]);let t=e=>p(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{hce(e?await n(e,{force:!0,onProgress:t}):await r({force:!0,onProgress:t}),e?i?.sources.find(t=>t.id===e)?.label??e:`All sources`),await w()}finally{d(null)}},[w,i]),E=(0,W.useCallback)(async(e,t,n)=>{gI(e,t,n),n?await T(e):await w()},[T,w]),D=(0,W.useCallback)(async()=>{y(null);let e;try{e=pP(m,g)}catch(e){y(e instanceof Error?e.message:String(e));return}h(``),_(``),await T(e.id)},[m,g,T]),O=(0,W.useCallback)((e,t)=>{xI(e,t)||Z({title:`Couldn't save Auto-sync`,description:`Browser storage is unavailable — the choice lasts this session only.`,variant:`destructive`}),w()},[w]),k=(0,W.useCallback)(async e=>{let t=i?.sources.find(t=>t.id===e)?.label??e;if(window.confirm(`Unsubscribe from "${t}"? 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:n}=await FL(e);Z({title:`${t} unsubscribed`,description:`${n.toLocaleString()} imported ${n===1?`item`:`items`} removed. The source stays listed for a later Subscribe.`})}catch(e){Z({title:`${t} unsubscribe failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`});return}await w()}},[i,w]),A=(0,W.useCallback)(async e=>{let t=i?.sources.find(t=>t.id===e)?.label??e;if(window.confirm(`Delete "${t}"? Imported content is removed and the source is unregistered. Your own notes are never touched.`)){try{let{deleted:n}=await IL(e);Z({title:`${t} deleted`,description:`${n.toLocaleString()} imported ${n===1?`item`:`items`} removed and the source unregistered.`})}catch(e){Z({title:`${t} delete failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`});return}await w()}},[i,w]),j=f.at(-1)?.event;return(0,G.jsxs)(`div`,{className:`space-y-8`,children:[(0,G.jsxs)(`section`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,G.jsx)(Te,{className:`size-4 text-primary`}),`Content Sources`]}),(0,G.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.`})]}),c&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-destructive`,"data-testid":`feed-status-error`,children:[(0,G.jsx)(Jr,{className:`size-3.5 shrink-0`}),`Couldn't read the feed status from the active storage: `,c]}),j&&(0,G.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-border bg-card p-4`,"data-testid":`feed-sync-progress`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-sm font-medium`,children:[(0,G.jsx)(`span`,{children:u===null?f.some(e=>e.event.phase===`finished`&&e.event.outcome===`error`)?`Sync finished with errors`:`Sync finished`:`Syncing…`}),(0,G.jsxs)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:[`Source `,j.sourceIndex,` of `,j.totalSources]})]}),(0,G.jsxs)(`p`,{role:`status`,"aria-live":`polite`,className:`sr-only`,"data-testid":`feed-sync-live-status`,children:[j.sourceLabel,`: `,T8(j)]}),f.map(({event:e,imported:t,chunks:n})=>(0,G.jsxs)(`div`,{className:`space-y-2 border-t border-border/50 pt-3`,children:[(0,G.jsxs)(`p`,{className:`text-xs ${e.phase===`finished`&&e.outcome===`error`?`text-destructive`:`text-muted-foreground`}`,children:[(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:e.sourceLabel}),` · `,T8(e)]}),t&&t.totalChunks>0?(0,G.jsx)(c8,{value:t.completedChunks,max:t.totalChunks,label:`Chunks committed · ${e.sourceLabel}`}):e.phase===`finished`?null:(0,G.jsx)(`progress`,{"aria-label":`Checking ${e.sourceLabel}`,className:`h-2 w-full`}),t&&(0,G.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-xs tabular-nums`,"data-testid":`feed-sync-totals`,children:[(0,G.jsxs)(`span`,{children:[t.totalNotes.toLocaleString(),` notes`]}),(0,G.jsxs)(`span`,{children:[t.totalEfforts.toLocaleString(),` efforts`]}),(0,G.jsxs)(`span`,{children:[t.totalBlocks.toLocaleString(),` blocks`]}),t.skippedUserOwned>0&&(0,G.jsxs)(`span`,{children:[t.skippedUserOwned.toLocaleString(),` user-owned rows preserved`]}),t.deleted>0&&(0,G.jsxs)(`span`,{children:[t.deleted.toLocaleString(),` feed rows removed`]})]}),n.length>0&&(0,G.jsxs)(`details`,{className:`text-xs`,"data-testid":`feed-sync-chunks`,children:[(0,G.jsxs)(`summary`,{className:`cursor-pointer text-muted-foreground`,children:[`Committed chunks (`,n.length,`)`]}),(0,G.jsx)(`ul`,{className:`mt-2 max-h-32 space-y-1 overflow-y-auto font-mono text-muted-foreground`,children:n.map(e=>(0,G.jsx)(`li`,{children:e},e))})]})]},e.sourceId))]}),(0,G.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,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer select-none text-muted-foreground hover:text-foreground`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),"data-testid":`sync-subscribed-only-toggle`,className:`size-3.5 accent-primary rounded`}),(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:`Subscribed only`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Source:`}),(0,G.jsxs)(`select`,{value:S??``,onChange:e=>C(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,G.jsx)(`option`,{value:``,children:`All feeds`}),i?.sources.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-3`,"data-testid":`feed-source-list`,children:[i?.sources.filter(e=>{if(S&&e.id!==S)return!1;if(b){let t=e.notebooks.some(e=>e.subscribed);if(!e.subscribed&&!t)return!1}return!0}).map(e=>(0,G.jsx)(gce,{source:e,running:u===e.id||u===`all`,disabled:u!==null,onSync:e=>{T(e)},onSubscribe:e=>{T(e)},onUnsubscribe:e=>{k(e)},onDelete:e=>{A(e)},onAutoSync:O,onToggleNotebook:E,subscribedOnly:b},e.id)),o&&i===null&&(0,G.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground`,children:`Checking sources…`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-border/50`,children:[(0,G.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,G.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>{T(null)},disabled:u!==null||o,"data-testid":`feed-resync-button`,className:`gap-2`,children:[(0,G.jsx)(B,{className:`size-3.5 ${u===`all`?`animate-spin`:``}`}),(0,G.jsx)(`span`,{children:u===`all`?`Syncing all…`:`Sync All Sources`})]})]})]}),(0,G.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,G.jsx)(kn,{className:`size-4 text-primary`}),`Add a Source`]}),(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Register any URL serving a Wod Wiki feed (a directory with `,(0,G.jsx)(`code`,{children:`manifest.json`}),` and`,` `,(0,G.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,G.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,"data-testid":`feed-add-source-form`,children:[(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`feed-source-label`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Label`}),(0,G.jsx)(WY,{id:`feed-source-label`,value:m,onChange:e=>h(e.target.value),placeholder:`My library (optional — defaults to the host name)`,disabled:u!==null})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`feed-source-url`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Feed directory URL`}),(0,G.jsx)(WY,{id:`feed-source-url`,type:`text`,autoComplete:`off`,spellCheck:!1,value:g,onChange:e=>_(e.target.value),placeholder:`https://example.com/feed/library/`,className:`font-mono`,disabled:u!==null})]})]}),v&&(0,G.jsxs)(`p`,{role:`alert`,className:`flex items-start gap-1.5 text-xs text-destructive`,"data-testid":`feed-add-error`,children:[(0,G.jsx)(Jr,{className:`size-3.5 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:v})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsxs)(q,{size:`sm`,onClick:()=>{D()},disabled:u!==null||!g.trim(),"data-testid":`feed-add-button`,className:`gap-2`,children:[(0,G.jsx)(ut,{className:`size-3.5`}),(0,G.jsx)(`span`,{children:`Add & Sync`})]})})]})]})]})}var E8=[`cards`,`rows`,`feed`,`agenda`,`planner`],vce={stream:`cards`,table:`rows`},yce=`wodwiki.viewSettings.v1`,D8={"/notebooks":`/catalogs`,"/notes":`/feeds`,"/sessions":`/results`,"/dashboards":`/dashboard`},O8={"/notes":`/collections`},bce={"/feeds":`/feeds@2`};function k8(e){let t=e.startsWith(`/`)?e:`/${e}`;return bce[t]??t}var A8=new nw(yce);function j8(e,t){return{level:e,layout:t??`cards`,visibleFields:pK(e),groupBy:void 0}}function M8(e,t,n=A8,r){let i=j8(t,r),a=k8(e),o=D8[a],s=n.get(a,{alias:o});if(s==null&&o&&(s=n.get(o,{alias:O8[a]})),!s)return i;let c=typeof s.layout==`string`?s.layout:``,l=E8.includes(c)?c:vce[c]??`cards`,u=new Set(fK(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 xce(e,t,n=A8){let r=k8(e);n.set(r,{level:t.level,layout:t.layout,visibleFields:t.visibleFields,groupBy:t.groupBy})}function Sce(e,t,n=A8){let r=k8(e),i=D8[r],a=O8[r];return n.remove(r,i),a&&n.remove(a),j8(t)}function Cce(e,t,n){let[r,i]=(0,W.useState)(()=>M8(e,t,A8,n));(0,W.useEffect)(()=>{i(M8(e,t,A8,n))},[e,t,n]);let a=(0,W.useCallback)(t=>{i(n=>{let r=t(n);return xce(e,r),r})},[e]);return{settings:r,setLayout:(0,W.useCallback)(e=>{a(t=>({...t,layout:e}))},[a]),toggleField:(0,W.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,W.useCallback)(e=>{a(t=>({...t,visibleFields:e}))},[a]),setGroupBy:(0,W.useCallback)(e=>{a(t=>({...t,groupBy:e}))},[a]),resetSettings:(0,W.useCallback)(()=>{let n=Sce(e,t);i(n)},[e,t])}}function wce(e,t=200){let[n,r]=(0,W.useState)(t),i=(0,W.useRef)(null);(0,W.useEffect)(()=>{r(t)},[e,t]);let a=n<e.length,o=(0,W.useCallback)(t=>r(n=>Math.max(n,Math.min(Math.max(t,0),e.length))),[e.length]);return(0,W.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}}var N8={source:!0,tags:!0,notebook:!0,text:!0,type:!0,has:!0};function Tce(e,t){let n=Y(e);if(n.error)return e;if(Eh(n))return yg({...n,metric:t});if(!Th(n))return e;let r=/^:(journal|notebooks|playground)(?:\{|\s|$)/.exec(e.trim())?.[1],i=n.filters.filter(e=>!(!N8[e.key]||r&&e.key===`source`&&e.values.length===1&&e.values[0].value===r));return yg({family:`aggregate`,raw:``,agg:`sum`,metric:t,filters:n.filters.filter(e=>!N8[e.key]),groupBy:[`week`],window:n.window,...i.length>0||r||n.target!==`note`?{join:{target:r??n.target,filters:i}}:{}}).replace(/ where :(journal|notebooks|playground)$/,` where :$1{}`)}function Ece(e){let t=Y(e);return t.error?e:yg({...t,window:void 0})}function Dce(e,t){let n=Y(e);return n.error||n.family===`pipeline`?e:yg({...n,groupBy:[t]})}function P8(e){return e.kind===`note`&&!e.sourceNote?!1:e.kind===`note`}async function Oce(e){if(e.wodBlock?.content.trim())return e.wodBlock.content;let t=await Uz.resolve(e.id),n=nY(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 kce(e,t){return{id:e.wodBlock?.blockId??e.block?.blockId??xr(),contentId:e.wodBlock?.blockContentId??e.blockContentId,dialect:`time`,startLine:0,endLine:t.split(`
1116
+ `),t])}var k6=(0,W.createContext)(null);function A6({children:e}){let t=(0,W.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,W.useState)(0),i=(0,W.useCallback)((e,n)=>{t.current[e]!==n&&(t.current[e]=n,r(e=>e+1))},[]);return(0,G.jsx)(k6.Provider,{value:{register:i,registry:t,version:n},children:e})}function j6(){return(0,W.useContext)(k6)||{registry:{current:{}},register:()=>()=>{},version:0}}function M6(e){let t=(0,W.useContext)(k6)?.register;return(0,W.useCallback)(n=>t?.(e,n),[e,t])}function fse({ringKey:e,el:t}){let{register:n}=j6();return(0,W.useLayoutEffect)(()=>{n(e,t)},[e,t,n]),null}function pse({target:e,accent:t,canvasRef:n}){let{registry:r,version:i}=j6(),[a,o]=(0,W.useState)(null),s=e?.key??null;return(0,W.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,G.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 N6(){return(0,G.jsxs)(`div`,{className:`@container flex w-full flex-col items-center text-center`,children:[(0,G.jsxs)(`h1`,{className:`text-[clamp(32px,6.5cqi,64px)] font-extrabold leading-[1.02] tracking-[-0.04em]`,children:[(0,G.jsxs)(`span`,{className:`block`,children:[(0,G.jsx)(`span`,{className:`mr-[0.35em]`,children:`Write it.`}),(0,G.jsx)(`span`,{children:`Time it.`})]}),(0,G.jsxs)(`span`,{className:`block`,children:[(0,G.jsx)(`span`,{className:`mr-[0.35em]`,children:`Track it.`}),(0,G.jsx)(`span`,{children:`Own it.`})]})]}),(0,G.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,G.jsx)(`br`,{}),`line and splits become queryable training data points.`]})]})}var P6=`dQw4w9WgXcQ`;function mse({onWatched:e}){let[t,n]=(0,W.useState)(!1);return(0,G.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-4 xl:gap-5`,children:[(0,G.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,G.jsxs)(`button`,{type:`button`,onClick:()=>n(!0),"data-testid":`tour-why-video`,"aria-label":`Play Why Wod Wiki? · YouTube video`,className:`block h-full w-full overflow-hidden rounded-xl`,children:[(0,G.jsx)(`img`,{src:`https://i.ytimg.com/vi/${P6}/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,G.jsx)(`span`,{className:`absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-transparent`}),(0,G.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,G.jsx)(bt,{className:`ml-1 size-6 fill-current xl:size-7`})}),(0,G.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,G.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,G.jsx)(Bn,{className:`size-4`})})]}),(0,G.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,G.jsx)(dt,{className:`size-4 animate-bounce`}),`Keep scrolling for the demo`]}),t&&(0,G.jsx)(P3,{videoId:P6,title:`Why Wod Wiki?`,onClose:()=>{n(!1),e?.()}})]})}var hse=`https://github.com/bitcobblers/wod-wiki`;function F6(){return(0,G.jsx)(`footer`,{"data-testid":`tour-footer`,className:`border-t border-border px-6 py-8`,children:(0,G.jsxs)(`p`,{className:`mx-auto flex max-w-3xl flex-wrap items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,G.jsxs)(`span`,{children:[`© `,new Date().getFullYear(),` WOD Wiki`]}),(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,G.jsx)(`a`,{href:hse,target:`_blank`,rel:`noopener noreferrer`,className:`underline-offset-4 transition-colors hover:text-foreground hover:underline`,children:`GitHub repository`})]})})}async function I6(){await _N.wipe();try{for(let e=localStorage.length-1;e>=0;e--){let t=localStorage.key(e);t&&t!==`wodwiki.dataSettings.v1`&&localStorage.removeItem(t)}}catch{}try{sessionStorage.clear()}catch{}}var gse=`https://github.com/bitcobblers/wod-wiki`,_se=`https://forms.gle/6YHpxwAJh6PAsyAQ6`,vse=`https://app.turso.tech/signup`,yse=`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`,bse=[{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.`}],xse=[{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.`}],L6=`underline-offset-4 transition-colors hover:text-foreground hover:underline`;function R6(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,G.jsxs)(G.Fragment,{children:[e.children,(0,G.jsx)(On,{className:`size-3.5 text-muted-foreground/50`,"aria-hidden":!0})]});return e.href===void 0?e.onClick===void 0?(0,G.jsx)(ve,{to:e.to,className:t,children:n}):(0,G.jsx)(`button`,{type:`button`,onClick:e.onClick,className:`text-left ${t}`,children:n}):(0,G.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:t,children:n})}function z6({children:e}){return(0,G.jsxs)(`li`,{className:`flex gap-2.5 text-sm leading-6 text-muted-foreground`,children:[(0,G.jsx)(`span`,{"aria-hidden":!0,className:`mt-[11px] size-1 shrink-0 rounded-full bg-muted-foreground/50`}),(0,G.jsx)(`span`,{children:e})]})}function Sse(){return(0,G.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-800`,children:`Active`})}function Cse(e){return(0,G.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsxs)(`span`,{className:`flex gap-2.5 text-[13px] leading-5 text-muted-foreground`,children:[(0,G.jsx)(`span`,{"aria-hidden":!0,className:`mt-[9px] size-1 shrink-0 rounded-full bg-muted-foreground/50`}),(0,G.jsx)(`span`,{children:e.feature.label})]}),(0,G.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 wse(){return(0,G.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,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,G.jsx)(be,{className:`size-5 shrink-0 text-emerald-600`,"aria-hidden":!0}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium text-foreground`,children:`Thanks for showing interest — please fill out the survey and give us feedback.`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Opens the interest survey in a new tab.`})]})]}),(0,G.jsxs)(q,{type:`button`,"data-testid":`hosted-survey-button`,onClick:()=>{KP.record(qP.hostedSurveyOpened),window.open(_se,`_blank`,`noopener,noreferrer`)},children:[`Fill out interest survey`,(0,G.jsx)(On,{className:`size-4`,"aria-hidden":!0})]})]})})}function B6(e){let t=e.icon;return(0,G.jsxs)(`article`,{className:`flex flex-col rounded-xl border border-border p-5 ${e.us?`bg-muted/40`:`bg-background`} ${e.className??``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-foreground text-background`,children:(0,G.jsx)(t,{className:`size-5`,"aria-hidden":!0})}),e.badge]}),e.eyebrow&&(0,G.jsx)(`p`,{className:`mt-3.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] ${e.us?`text-emerald-800`:`text-muted-foreground`}`,children:e.eyebrow}),(0,G.jsx)(`h3`,{className:`${e.eyebrow?`mt-1`:`mt-4`} text-base font-semibold text-foreground`,children:e.title}),(0,G.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-muted-foreground`,children:e.text}),(0,G.jsx)(`div`,{className:`mt-4 flex flex-1 flex-col gap-2 text-sm`,children:e.children})]})}function V6({label:e,features:t,interested:n,onInterested:r}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(`ul`,{className:`space-y-2`,children:t.map(e=>(0,G.jsx)(Cse,{feature:e,interested:n.has(e.id),onInterested:r},e.id))})]})}function H6(){let[e,t]=(0,W.useState)(!1),n=lt(),[r,i]=(0,W.useState)(new Set),a=e=>{i(t=>t.has(e)?t:new Set(t).add(e)),KP.record(qP.hostedInterestClicked,{feature:e})},[o]=(0,W.useState)(dN),s=async()=>{window.confirm(`Wipe every note, result, and setting stored in this browser? This cannot be undone.`)&&(t(!0),await I6(),window.location.reload())},c=async()=>{let e=Lz(),t=await Uz.create({journalDate:e,title:e,rawContent:``});KP.record(qP.noteCreated),n(rz(t.id))};return(0,G.jsxs)(`section`,{id:`tour-section-offerings`,"data-testid":`tour-section-offerings`,"aria-label":`You own your data`,children:[(0,G.jsx)(F3,{index:`04`,before:`Who owns the data? `,accentText:`You!!!`,after:``,accent:L3.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,G.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,G.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,G.jsx)(`span`,{children:`Current mode: API server`}),(0,G.jsx)(ve,{to:Q.settingsStorage,className:L6,children:`Configure data storage`})]}),(0,G.jsxs)(`div`,{className:`mx-auto grid max-w-5xl grid-cols-1 gap-5 md:grid-cols-3`,children:[(0,G.jsxs)(B6,{icon:Hn,eyebrow:`You own it`,title:`Playground in your browser`,badge:void 0,text:`Everything runs locally in this browser's IndexedDB — offline, no account, no server copy.`,children:[(0,G.jsx)(R6,{onClick:()=>void c(),children:`Create your journal`}),(0,G.jsx)(R6,{to:Q.playgroundRoot,children:`Start Writing in a Playground`}),(0,G.jsx)(R6,{to:`/feeds`,children:`Explore the notebooks`}),(0,G.jsxs)(`ul`,{className:`mt-1 space-y-1.5`,children:[(0,G.jsx)(z6,{children:`Offline and fast — notes and results never leave this browser by default.`}),(0,G.jsx)(z6,{children:`Tied to this browser — export or back it up before switching browsers or clearing site data.`})]}),(0,G.jsx)(`button`,{type:`button`,onClick:s,disabled:e,className:`mt-1 text-left text-xs text-muted-foreground disabled:opacity-50 ${L6}`,children:e?`Clearing…`:`Clear my data`}),(0,G.jsxs)(`div`,{className:`mt-auto border-t border-border pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,G.jsx)(`span`,{className:`mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-lg border border-border bg-background`,children:(0,G.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,className:`size-4`,"aria-hidden":!0,children:(0,G.jsx)(`path`,{d:yse})})}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium text-foreground`,children:`Backup & sync, optional`}),(0,G.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,G.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[(0,G.jsx)(R6,{href:vse,children:`Create a free Turso account`}),(0,G.jsx)(R6,{to:Q.settingsStorage,children:`Configure backup & sync`})]})]})]}),(0,G.jsxs)(B6,{icon:ye,eyebrow:`You own it`,title:`Self-hosted`,badge:(0,G.jsx)(Sse,{}),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,G.jsxs)(`ul`,{className:`mt-1 space-y-1.5`,children:[(0,G.jsx)(z6,{children:`Centralized data for a team or gym — one SQLite, Turso, or Postgres backend.`}),(0,G.jsxs)(z6,{children:[`Publish your notebooks as a feed with `,(0,G.jsx)(`code`,{className:`font-mono text-xs`,children:`wod build`}),` — every browser subscribes and syncs.`]}),(0,G.jsx)(z6,{children:`You run the server — network required, and server admin is on you.`})]}),(0,G.jsx)(`div`,{className:`mt-auto border-t border-border pt-4`,children:(0,G.jsx)(R6,{href:gse,children:`View source`})})]}),(0,G.jsxs)(B6,{icon:l,us:!0,eyebrow:`Us — we'd host it`,title:`Wod-Wiki hosted`,text:`Mark the features you want — the survey unlocks below.`,children:[(0,G.jsx)(V6,{label:`Individuals`,features:bse,interested:r,onInterested:a}),(0,G.jsx)(V6,{label:`Coaching & gyms`,features:xse,interested:r,onInterested:a})]})]}),r.size>0&&(0,G.jsx)(wse,{})]})]})}var U6=({doc:e,onDocChange:t,onBlocksChange:n,onRun:r,theme:i,withRingTargets:a=!1,editorSlot:o})=>{let s=M6(`editor.wodBlock`),c=M6(`editor.runButton`),l=(0,W.useRef)(null),u=(0,W.useRef)(null),[d,f]=(0,W.useState)(null),[p,m]=(0,W.useState)(null),h=(0,W.useCallback)(()=>{if(!a)return null;let e=l.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}}}f(t);let i=null,o=e.querySelector(`[data-testid="${$.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 m(i),{block:t,run:i}},[a]);(0,W.useLayoutEffect)(()=>{if(!a)return;let e=l.current;if(!e)return;h();let t=window.setTimeout(h,120),n=window.setTimeout(h,480),r=null;if(typeof ResizeObserver<`u`){r=new ResizeObserver(h),r.observe(e);let t=u.current?.contentDOM;t&&r.observe(t)}let i=new MutationObserver(e=>{e.some(e=>e.target instanceof Element&&e.target.closest(`.cm-note-editor`))&&h()});i.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`]});let o=0,s=0,c=()=>{h(),performance.now()-s<3e3&&(o=requestAnimationFrame(c))},d=()=>{s=performance.now(),cancelAnimationFrame(o),o=requestAnimationFrame(c)};d(),document.fonts?.ready?.then(d).catch(()=>{});let f=u.current?.scrollDOM;return f?.addEventListener(`scroll`,h,{passive:!0}),window.addEventListener(`resize`,h),()=>{window.clearTimeout(t),window.clearTimeout(n),r?.disconnect(),i.disconnect(),f?.removeEventListener(`scroll`,h),window.removeEventListener(`resize`,h),cancelAnimationFrame(o)}},[e,a,h]);let g=(0,W.useCallback)(()=>{r()},[r]),_=o??l4,v=(0,W.useMemo)(()=>[{id:`run`,label:`Run`,icon:(0,G.jsx)(bt,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:g},{id:`playground`,label:`Playground`,icon:(0,G.jsx)(Nr,{className:`h-3 w-3`}),onClick:e=>{Uoe(e)},splitIcon:(0,G.jsx)(Fe,{className:`h-3 w-3`}),splitSuccessIcon:(0,G.jsx)(xt,{className:`h-3 w-3 text-emerald-500`}),onSplitClick:e=>{v6(e)}}],[g]);return(0,G.jsx)(`div`,{className:`relative flex h-full flex-col bg-background text-left`,children:(0,G.jsxs)(`div`,{ref:l,className:`relative flex-1 min-h-0`,children:[(0,G.jsx)(_,{noteId:`canvas:home`,ariaLabel:`Home workout editor`,value:e,onChange:t,onBlocksChange:n,onStartWorkout:g,commands:v,onViewCreated:e=>{u.current=e,a&&h()},theme:i,readonly:!1,showLineNumbers:!1,showFrontmatter:!1,enableOverlay:!1,enableInlineRuntime:!1,className:`h-full`}),a&&d&&(0,G.jsx)(`div`,{ref:s,"data-testid":`tour-wod-block-region`,"aria-hidden":!0,className:`pointer-events-none absolute`,style:{top:d.top,left:d.left,width:d.width,height:d.height}}),a&&p&&(0,G.jsx)(`div`,{ref:c,"data-testid":`tour-run-button-region`,"aria-hidden":!0,className:`pointer-events-none absolute`,style:{top:p.top,left:p.left,width:p.width,height:p.height}})]})})};function Tse(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 W6=e=>{let t=Math.max(0,Math.round(e/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`},G6=e=>`${(Math.round(e/100)/10).toFixed(1)}s`;function Ese({onRun:e}){return(0,G.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,G.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,G.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,G.jsx)(bt,{className:`size-4`}),`Run to view the results`]})]})}function Dse({result:e,onRun:t}){let n=(0,W.useMemo)(()=>e?Tse(e):null,[e]);if(!e||!n)return(0,G.jsx)(Ese,{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,G.jsxs)(`div`,{className:`flex h-full w-full flex-col gap-4 overflow-y-auto p-4`,"data-testid":`tour-insights`,children:[(0,G.jsxs)(`div`,{"data-testid":`tour-insights-timeline`,children:[(0,G.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,G.jsx)(`div`,{title:`${e.label} — ${e.kind===`clock`?`countdown`:`to Next`} ${W6(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,G.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-4 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`size-2 rounded-sm`,style:{backgroundColor:`hsl(var(--metric-rest))`}}),`Countdown`]}),(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`size-2 rounded-sm`,style:{backgroundColor:`hsl(var(--metric-time))`}}),`To Next click`]}),(0,G.jsxs)(`span`,{className:`ml-auto`,children:[W6(i),` total`]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,G.jsxs)(`div`,{"data-testid":`tour-insights-impatience`,className:`rounded-xl border border-border bg-card p-4`,children:[(0,G.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground`,children:`Impatience Score`}),(0,G.jsx)(`p`,{className:`mt-2 text-2xl font-black tracking-tight text-foreground`,children:G6(a)}),(0,G.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 ${G6(u)}`:``}`})]}),(0,G.jsxs)(`div`,{"data-testid":`tour-insights-reaction`,className:`rounded-xl border border-border bg-card p-4`,children:[(0,G.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground`,children:`Reaction Time`}),(0,G.jsx)(`p`,{className:`mt-2 text-2xl font-black tracking-tight text-foreground`,children:s.length>0?G6(c):`—`}),(0,G.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[s.length,` click`,s.length===1?``:`s`,s.length>1?` · slowest ${G6(l)}`:``]})]})]})]})}var K6=864e5;function q6(e){return Math.round(e*10)/10}function J6(e,t,n=9){let r=new Date(e-t*K6);return r.setHours(n,0,0,0),r.getTime()}function Y6(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:J.Label,value:t,origin:`analyzed`},{type:J.Metric,value:n,unit:r,origin:`analyzed`,metadata:o}],sourceBlockKey:``,stackLevel:0})}var Ose=new Set([`tis`,`calc.acwr`,`calc.adherence`,`calc.ef`,`calc.pct1rm`]);function X6(e,t){return zv(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`||!Ose.has(n)||typeof t.value!=`number`?e:{...e,reducerStats:{observedCount:1,sum:t.value,min:t.value,max:t.value}}})}function kse(e=Date.now()){let t=[],n=new Map,r=[],i=[],a=(e,t)=>{let r=Cm(e);n.set(r,(n.get(r)??0)+t)};for(let n=0;n<16;n++){let o=(15-n)*7+1,s=J6(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`};Y6(r,`Total reps`,t.reps,`reps`,`totalReps`,n),Y6(r,`Training intensity score`,t.tis,`pts`,`tis`,n),Y6(r,`Total volume`,e,`kg`,`totalVolume`,n),Y6(r,`Estimated 1RM`,q6(t.top*(1+t.reps/30)),`kg`,`calc.e1rm`,n),Y6(r,`%1RM intensity`,q6(100/(1+t.reps/30)),`%`,`calc.pct1rm`,n)}let c=q6(i/100+13+o/10);Y6(r,`Session load`,c,`AU`,`sessionLoad`,{discipline:`strength`,intensityTier:`high`}),t.push(...X6(r,{noteId:`example-strength-w${n}`,resultId:`example-strength-w${n}-r`,blockContentId:`example-content-strength`,timestamp:s})),a(s,c)}let c=J6(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};Y6(e,`Total reps`,n,`reps`,`totalReps`,o),Y6(e,`Training intensity score`,q6(n*i),`pts`,`tis`,o),a&&Y6(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};Y6(e,`Total reps`,o,`reps`,`totalReps`,s),Y6(e,`Training intensity score`,q6(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};Y6(e,`Total reps`,n,`reps`,`totalReps`,a),Y6(e,`Training intensity score`,q6(n*i),`pts`,`tis`,a)}}let i=q6(30.6);Y6(e,`Session load`,i,`AU`,`sessionLoad`,{intensityTier:r}),t.push(...X6(e,{noteId:`example-conditioning-w${n}`,resultId:`example-conditioning-w${n}-r`,blockContentId:`example-content-conditioning`,timestamp:c})),a(c,i)}let l=J6(e,o+4,8);if(n%4==1)r.push(Cm(l));else{let e=6e3+100*n,r=q6(e/2.8),o=[],s={effortSlug:`running`,discipline:`running`,intensityTier:`low`};Y6(o,`Total distance`,e,`m`,`totalDistance`,s),Y6(o,`Elapsed time`,r,`s`,`elapsed`,s),Y6(o,`Training intensity score`,r,`pts`,`tis`,s);let c=q6(r/10);Y6(o,`Session load`,c,`AU`,`sessionLoad`,{intensityTier:`low`}),t.push(...X6(o,{noteId:`example-run-w${n}`,resultId:`example-run-w${n}-r`,blockContentId:`example-content-run`,timestamp:l})),a(l,c),i.push({day:Cm(l),pace:e/r})}let u=J6(e,o+6,10);{let e=4e3+50*n,r=q6(e/2),i=[],o={effortSlug:`rowing`,discipline:`rowing`,intensityTier:`moderate`};Y6(i,`Total distance`,e,`m`,`totalDistance`,o),Y6(i,`Elapsed time`,r,`s`,`elapsed`,o),Y6(i,`Training intensity score`,r,`pts`,`tis`,o);let s=q6(r/10);Y6(i,`Session load`,s,`AU`,`sessionLoad`,{intensityTier:`moderate`}),t.push(...X6(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*K6);return n.setHours(t,0,0,0),n.getTime()},c=(e,n,r)=>{let i=[];for(let[e,t,n]of r)Y6(i,e,t,n,e);t.push(...X6(i,{noteId:`example-calc`,resultId:e,blockContentId:`example-content-calc`,timestamp:n}))};for(let e of wm(n,o))e.acwr!==void 0&&c(`example-calc-d${e.day}`,s(e.day),[[`calc.acwr`,q6(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`,q6(l),`AU`],[`calc.atl`,q6(u),`AU`],[`calc.tsb`,q6(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`,q6(e.pace/141*1e5),`pts`]]);return t}function Ase(e=Date.now()){return new Fy(vb(kse(e)))}var jse=null;function Mse(){return jse??=Ase()}var Nse=[4,8,16],Pse={parse(e){let t=Number.parseInt(e,10);return Nse.includes(t)?t:null},serialize(e){return String(e)},withDefault(e){return{...this,defaultValue:e}}};function Z6(){return ie(`weeks`,Pse.withDefault(16))}function Fse({boardSlug:e}){let t=Mse(),n=nN(),r=(0,W.useMemo)(()=>n?Oz(n):[],[n]),i=(0,W.useMemo)(()=>r.find(t=>t.slug===e)??r[0],[r,e]),a=(0,W.useMemo)(()=>{if(!i?.rawContent)return null;try{let{meta:e,sections:t}=Ky(i.rawContent);return Tv(t,e)}catch{return null}},[i]),[o,s]=Z6(),[c,l]=(0,W.useMemo)(()=>{let e=Date.now();return[e-o*7*864e5,e]},[o]),[u,d]=(0,W.useState)(null);return(0,G.jsxs)(`div`,{className:`flex h-full w-full flex-col`,"data-testid":`tour-session-dashboard`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-5 pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`truncate text-[11px] font-semibold uppercase tracking-wide text-primary`,children:i?.title??e}),(0,G.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,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsx)(kT,{weeks:o,onWeeksChange:s})})]}),(0,G.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,G.jsx)(OT,{document:a,executor:t,onInspectWidget:d,rangeStart:c,rangeEnd:l}):(0,G.jsx)(`p`,{className:`pt-8 text-center text-sm text-muted-foreground`,children:`Loading board…`})}),(0,G.jsx)(n3,{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?yv(a.tokens):void 0,onApply:void 0})]})}var Ise=[`analytics`,`boards`],Lse={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 Q6({scope:e}){let t=Lse[e],n=t.heading;return(0,G.jsxs)(`div`,{children:[(0,G.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,G.jsx)(`span`,{className:`font-mono text-xs font-normal tracking-normal text-muted-foreground`,children:t.index}),(0,G.jsx)(`span`,{children:t.title})]}),(0,G.jsx)(`p`,{className:`mt-3 max-w-xl text-[clamp(14px,1.2vw,18px)] leading-[1.65] text-muted-foreground`,children:t.blurb})]})}var $6=[{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 e8({onClick:e}){return(0,G.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,G.jsx)(dr,{className:`size-3`}),`Editor`]})}function t8({session:e,onRun:t,onBackToEditor:n}){let[r,i]=(0,W.useState)(`analytics`),[a,o]=(0,W.useState)(0),s=$6[a],c=(0,W.useRef)(new Map);(0,W.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,G.jsx)(N1,{title:`Session Insights`,className:`h-[460px]`,headerActions:(0,G.jsx)(e8,{onClick:n}),children:(0,G.jsx)(Dse,{result:e,onRun:t})}):(0,G.jsxs)(`div`,{className:`flex h-full flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,G.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:$6.map((e,t)=>(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":a===t,"data-testid":`dashboard-slide-tab-${e.id}`,onClick:()=>o(t),className:K(`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,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(e=>(e+$6.length-1)%$6.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,G.jsx)(V,{className:`size-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(e=>(e+1)%$6.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,G.jsx)(gt,{className:`size-4`})})]})]}),(0,G.jsx)(N1,{title:s.title,className:`min-h-0 flex-1`,headerActions:(0,G.jsx)(e8,{onClick:n}),children:(0,G.jsx)(`div`,{className:`flex h-full w-full flex-col`,role:`tabpanel`,children:(0,G.jsx)(Fse,{boardSlug:s.id})},s.id)}),(0,G.jsxs)(`p`,{className:`text-center font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground`,children:[a+1,` / `,$6.length]})]}),d=(0,G.jsx)(`div`,{"data-testid":`tour-sticky-pane`,className:`sticky top-[104px] flex h-[calc(100dvh-104px)] flex-col items-center justify-center self-start`,children:(0,G.jsx)(`div`,{className:`relative w-full max-w-[700px]`,children:(0,G.jsx)(`div`,{className:`relative h-[460px]`,children:Ise.map(e=>(0,G.jsx)(`div`,{"aria-hidden":r!==e,"data-scope-active":r===e,className:K(`absolute inset-0 transition-opacity duration-500`,r===e?`opacity-100`:`invisible opacity-0`),children:u(e)},e))})})}),f=(e,t)=>(0,G.jsx)(`div`,{ref:l(e),"data-scope":e,className:`flex min-h-[85vh] flex-col justify-center scroll-mt-[104px]`,...t,children:(0,G.jsx)(Q6,{scope:e})}),p=e=>(0,G.jsxs)(`div`,{"data-testid":`tour-step-mobile-${e}`,"data-scope":e,className:`flex flex-col gap-4`,children:[(0,G.jsx)(Q6,{scope:e}),(0,G.jsx)(`div`,{className:`h-[460px]`,children:u(e)})]}),m=OK();return(0,G.jsx)(`section`,{id:`tour-section-insights`,"data-testid":`tour-section-insights`,className:`border-b border-border/60`,children:m?(0,G.jsxs)(`div`,{className:`flex flex-col gap-12 px-5 py-14`,children:[p(`analytics`),p(`boards`)]}):(0,G.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,G.jsxs)(`div`,{className:`flex flex-col`,children:[(0,G.jsx)(`div`,{id:`tour-scroll-target-insights`,className:`scroll-mt-[104px]`,children:f(`analytics`)}),f(`boards`,{id:`tour-section-boards`,"data-testid":`tour-section-boards`})]}),d]})})}function Rse(e){let t=e.match(/^notebook\.(.+)$/);return t?{slug:t[1]}:null}function zse(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 Bse(e,t,n){let r=[],i=new Map;if(t)for(let e of PM(`notebooks`,t))i.set(e.id,e),r.push(zse(e));let a=e.map(e=>{let t=Rse(e.chunkId);if(!t)return null;let r=i.get(t.slug),a=vP(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)),...Vse(t)]}function Vse(e){return so.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 Hse(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 Use(e,t,n,r){return Hse(Bse(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 Wse(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 Gse(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 n8=[`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 Kse(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return n8[Math.abs(t)%n8.length]}function qse(e){return(e.match(/[a-z0-9]/i)?.[0]??`•`).toUpperCase()}function Jse(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 Yse=4;function r8({feed:e,testId:t=`feed-card`,className:n,onImport:r,importing:i,busy:a,status:o,onToggleNotebookSubscription:s}){let[c,l]=Kse(e.slug).split(` `),u=Jse(e.latestDate),d=e.notebooks.slice(0,Yse),f=e.notebooks.length-d.length,p=e.installed&&e.feedId?e.href:void 0,m=e.notebooks.find(e=>e.image)?.image,h=(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[e.notebooks.length,` `,e.notebooks.length===1?`notebook`:`notebooks`]}),e.installed&&e.itemCount>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[e.itemCount,` `,e.itemCount===1?`item`:`items`]})]}),e.installed&&u&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[`updated `,u]})]}),!e.installed&&(0,G.jsx)(`span`,{"aria-hidden":!0,children:`·`}),!e.installed&&(0,G.jsx)(`span`,{children:`not imported`})]}),g=(0,G.jsx)(`div`,{className:K(`relative overflow-hidden bg-muted/40 aspect-[16/10]`,c),children:m?(0,G.jsx)(`img`,{src:m,alt:``,loading:`lazy`,className:`absolute inset-0 size-full object-cover`}):(0,G.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:[(0,G.jsx)(`span`,{className:K(`text-7xl font-black tracking-tighter select-none`,l),"aria-hidden":!0,children:qse(e.label)}),(0,G.jsx)($t,{className:K(`absolute bottom-4 right-4 size-6 opacity-50`,l),"aria-hidden":!0})]})});return(0,G.jsxs)(`article`,{"data-testid":t,"data-installed":e.installed,className:K(`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:[p?(0,G.jsx)(ve,{to:p,"data-testid":`${t}-open`,className:`block outline-none`,"aria-label":`Open the library for ${e.label}`,children:g}):g,(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col gap-2 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsx)(`h3`,{className:`min-w-0 text-sm font-bold leading-snug text-foreground`,children:p?(0,G.jsx)(ve,{to:p,className:`transition-colors hover:text-primary`,children:e.label}):e.label}),p?(0,G.jsx)(ve,{to:p,"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,G.jsx)(On,{className:`size-3.5`,"aria-hidden":!0})}):r&&e.feedId?(0,G.jsxs)(`button`,{type:`button`,"data-testid":`${t}-import`,disabled:i||a,onClick:()=>r(e.feedId),className:K(`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,G.jsx)(Sr,{className:`size-3 animate-spin`,"aria-hidden":!0}):(0,G.jsx)(Te,{className:`size-3`,"aria-hidden":!0}),i?`Importing`:`Import feed`]}):null]}),e.description&&(0,G.jsx)(`p`,{className:`line-clamp-2 text-xs leading-relaxed text-muted-foreground`,children:e.description}),e.notebooks.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`${t}-notebooks`,children:[d.map(n=>(0,G.jsxs)(`span`,{"data-testid":`${t}-notebook-${n.packageId}`,className:K(`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-800`:`border-border text-muted-foreground`),children:[n.installed?(0,G.jsx)(ve,{to:n.href,className:`hover:text-primary`,children:n.label}):(0,G.jsx)(`span`,{children:n.label}),s&&e.feedId&&n.chunkId&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.preventDefault(),t.stopPropagation(),s(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)),f>0&&(0,G.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`,children:[`+`,f,` more`]})]}),(0,G.jsxs)(`div`,{className:`mt-auto pt-1`,children:[h,o&&(0,G.jsx)(`p`,{role:o.tone===`error`?`alert`:`status`,"data-testid":`${t}-status`,className:K(`mt-1.5 flex items-start gap-1.5 text-xs`,o.tone===`error`?`text-destructive`:`text-muted-foreground`),children:(0,G.jsx)(`span`,{children:o.text})})]})]})]})}function i8({direction:e,children:t,testId:n,className:r}){let i=(0,W.useRef)(null),a=(0,W.useRef)(null),[o,s]=(0,W.useState)(1),c=A1(`(prefers-reduced-motion: reduce)`);(0,W.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,G.jsx)(`div`,{ref:i,"data-testid":n,className:K(`wod-marquee overflow-hidden`,r),children:(0,G.jsx)(`div`,{ref:a,className:K(`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,G.jsx)(`div`,{"data-marquee-copy":n,"aria-hidden":n>0,inert:n>0,className:`flex shrink-0 items-stretch gap-4 pr-4`,children:t},n))})})}var Xse=[{value:`updated`,label:`Updated`},{value:`name`,label:`Name`},{value:`size`,label:`Size`}],a8=`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 o8(e){let t=e.icon;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-foreground text-background`,children:(0,G.jsx)(t,{className:`size-5`,"aria-hidden":!0})}),(0,G.jsx)(`h3`,{className:`mt-4 text-base font-semibold text-foreground`,children:e.title}),(0,G.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-muted-foreground`,children:e.description})]}),e.note?(0,G.jsx)(`span`,{className:`mt-4 text-xs font-medium text-muted-foreground`,children:e.note}):(0,G.jsxs)(`span`,{className:`mt-4 inline-flex items-center gap-1.5 text-sm font-medium text-foreground`,children:[(0,G.jsx)(`span`,{children:e.action}),(0,G.jsx)(On,{className:`size-4 transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0})]})]})}function s8({feedDeps:e}={}){let t=(0,W.useMemo)(()=>({isNotebookSubscribed:hI,setNotebookSubscribed:gI,setFeedSubscribed:mI,subscribeFeedSubscriptions:vI,syncFeedSource:ML,readFeedCoverage:LL,...e}),[e]),n=lt(),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(`updated`),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)({}),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(),[h,g]=(0,W.useState)(0);(0,W.useEffect)(()=>t.subscribeFeedSubscriptions(()=>g(e=>e+1)),[t]);let _=s!==null,v=nN(),y=A1(`(min-width: 1024px)`),b=(0,W.useMemo)(()=>Use(CP(),v,SP(),(e,n)=>t.isNotebookSubscribed(e,n)),[v,h,t]),x=(0,W.useMemo)(()=>Gse(Wse(b,{text:r,feedId:p,subscribedOnly:d}),a),[b,r,a,p,d]),S=Math.ceil(x.length/2),C=x.slice(0,S),w=x.slice(S),T=(0,W.useCallback)(()=>{KP.record(qP.libraryOpened)},[]),[E,D]=(0,W.useState)(!0);(0,W.useEffect)(()=>{let e=!1,n=()=>{t.readFeedCoverage().then(t=>{e||D(t.libraryImported)}).catch(()=>{})};n();let r=t.subscribeFeedSubscriptions(n);return()=>{e=!0,r()}},[_,t]);let O=(0,W.useCallback)(async e=>{if(s)return;c(e);let n=t=>u(n=>({...n,[e]:t}));n({text:`Checking the feed…`,tone:`muted`});try{let r=await t.syncFeedSource(e,{onProgress:e=>n({text:hq(e),tone:`muted`})});n(r===`imported`||r===`current`?{text:mI(e,!0)?r===`imported`?`Imported — this feed is available offline.`:`Already up to date.`:`Subscribed for this session only — browser storage is unavailable.`,tone:`muted`}:{text:r===`server-stale`?`Published version is older than stored copy.`:r===`busy`?`Another tab is syncing. Try again shortly.`:`Sync failed. Check connection and try again.`,tone:`error`})}catch(e){n({text:e instanceof Error?e.message:String(e),tone:`error`})}finally{c(null)}},[s,t]),k=(0,W.useCallback)(async(e,n,r)=>{t.setNotebookSubscribed(e,n,r),r&&t.syncFeedSource(e,{force:!1})},[t]),A=(0,W.useCallback)(async()=>{let e=Lz(),t=await Uz.create({journalDate:e,title:e,rawContent:``});KP.record(qP.noteCreated),n(rz(t.id))},[n]),j=!!r.trim();return(0,G.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,G.jsx)(F3,{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,G.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`relative w-full sm:w-64`,children:[(0,G.jsx)(Ye,{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,G.jsx)(`input`,{type:`search`,value:r,onChange:e=>i(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 outline-none transition-colors focus:border-primary/50`}),r&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(``),"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,G.jsx)(Bn,{className:`size-3.5`})})]}),(0,G.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,G.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),"data-testid":`filter-subscribed-only`,className:`size-4 accent-primary rounded`}),(0,G.jsx)(`span`,{className:`text-[10px] font-black uppercase tracking-widest`,children:`Subscribed only`})]}),(0,G.jsxs)(`select`,{value:p??``,onChange:e=>m(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,G.jsx)(`option`,{value:``,children:`All feeds`}),SP().map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center gap-1.5`,role:`group`,"aria-label":`Sort feeds`,children:Xse.map(e=>{let t=a===e.value;return(0,G.jsx)(`button`,{type:`button`,"aria-pressed":t,"data-testid":`package-sort-${e.value}`,onClick:()=>o(e.value),className:K(`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,G.jsx)(`div`,{"data-testid":`jump-grid`,className:`mt-6`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[E?(0,G.jsx)(ve,{to:`/notebooks`,onClick:T,"data-testid":`jump-library`,className:a8,children:(0,G.jsx)(o8,{icon:Wt,title:`Library`,description:`Curated workouts and sessions, organized by tag.`,action:`Open the library`})}):(0,G.jsx)(`div`,{"data-testid":`jump-library`,"aria-disabled":`true`,className:`${a8} cursor-not-allowed opacity-60`,children:(0,G.jsx)(o8,{icon:Wt,title:`Library`,description:`Curated workouts and sessions, organized by tag.`,action:`Open the library`,note:`0 feeds synchronized`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{A()},"data-testid":`jump-new-note`,className:a8,children:(0,G.jsx)(o8,{icon:Et,title:`Start your own journal`,description:`Create today's note and log your first workout.`,action:`Create today's note`})})]})})]}),(0,G.jsx)(`div`,{"data-testid":`jump-rows`,className:`mt-6`,children:x.length>0?y?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(i8,{direction:`left`,testId:`jump-row-a`,children:C.map(e=>(0,G.jsx)(r8,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] sm:w-[320px] shrink-0`,onImport:O,importing:!!e.feedId&&s===e.feedId,busy:_,status:e.feedId?l[e.feedId]:void 0,onToggleNotebookSubscription:k},e.feedId??e.slug))}),w.length>0&&(0,G.jsx)(i8,{direction:`right`,testId:`jump-row-b`,className:`mt-4`,children:w.map(e=>(0,G.jsx)(r8,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] sm:w-[320px] shrink-0`,onImport:O,importing:!!e.feedId&&s===e.feedId,busy:_,status:e.feedId?l[e.feedId]:void 0,onToggleNotebookSubscription:k},e.feedId??e.slug))})]}):(0,G.jsx)(i8,{direction:`alternate`,testId:`jump-row-mobile`,children:x.map(e=>(0,G.jsx)(r8,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] shrink-0`,onImport:O,importing:!!e.feedId&&s===e.feedId,busy:_,status:e.feedId?l[e.feedId]:void 0,onToggleNotebookSubscription:k},e.feedId??e.slug))}):(0,G.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:(0,G.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,G.jsx)(`p`,{className:`text-sm font-bold text-muted-foreground`,children:`No feeds match your search.`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Try a different term or clear the filters.`}),j&&(0,G.jsx)(`button`,{type:`button`,"data-testid":`jump-clear-filters`,onClick:()=>{i(``),m(void 0),f(!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,G.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:(0,G.jsx)(`p`,{className:`mt-4 font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground xl:text-[11px]`,children:`— or keep scrolling ↓`})})]})}var Zse=`wods/examples/home/welcome-1.md`;function Qse({wodFiles:e,theme:t,quests:n,editorSlot:r,timerSlot:i,deps:a,jumpFeedDeps:o}){let s=a?.usePlaygroundRun??_1,c=a?.useQuickStartAutoComplete??k1,l=a?.useCompletionChallenge??O1,u=a?.useRunStartedChallenge??ose,d=a?.useTourScrollQuests??lse,f=a?.toast??Z,p=A1(`(prefers-reduced-motion: reduce)`),m=JP()?.track;YP(`/`);let h=(0,W.useMemo)(()=>TK(Zse,e),[e]),[g,_]=(0,W.useState)(()=>ise()),v=g?.content??h,y=g?g.by?.trim()||`anonymous`:void 0;(0,W.useEffect)(()=>{let e=e=>{let t=e.detail;t?.content&&(_(t),x(t.content))};return window.addEventListener(`wodwiki:home-shared`,e),()=>window.removeEventListener(`wodwiki:home-shared`,e)},[]);let[b,x]=(0,W.useState)(v),S=(0,W.useRef)(b);S.current=b;let C=(0,W.useRef)([]),w=(0,W.useRef)(!1),{run:T,start:E,finalize:D,end:O}=s(),k=(0,W.useRef)(T);k.current=T;let A=(0,W.useRef)(!1),j=(0,W.useRef)(!1),M=(0,W.useRef)(null),[N,P]=(0,W.useState)(!1),F=(0,W.useRef)(!1),I=(0,W.useRef)(null),[ee,L]=(0,W.useState)(null),[te,R]=(0,W.useState)(!1),ne=(0,W.useRef)(te);ne.current=te;let z=(0,W.useRef)(!1),B=(0,W.useRef)(()=>{}),[V,re]=(0,W.useState)(0),[ie,ae]=(0,W.useState)(!1),[oe,se]=(0,W.useState)(!1),[ce,le]=(0,W.useState)(null),H=(0,W.useCallback)(async(e,t,n)=>{if(!t||z.current)return!1;z.current=!0,j.current=!1,A.current=!1,M.current=null,le(t),re(e=>e+1),ae(!0),L(null),R(!0);try{await E(e,t,{pageTitle:`Home`,sectionTitle:n})}catch(e){return console.error(`[HomeTour] failed to persist playground run note:`,e),R(!1),le(null),f({title:`Could not start workout`,description:`The playground entry could not be saved.`,variant:`destructive`}),!1}finally{z.current=!1}return!0},[E]),ue=(0,W.useCallback)(async()=>{if(F.current=!1,P(!1),M.current)try{await D(M.current,!1),M.current=null}catch(e){console.error(`[HomeTour] retry save failed:`,e),f({title:`Session still not saved`,description:`The run is kept — try again.`,variant:`destructive`});return}let e=I.current;if(I.current=null,e)switch(e.kind){case`apply-doc`:w.current=!1,x(e.doc),R(!1),le(null),re(e=>e+1),ae(!1);break;case`restart`:await H(e.doc,e.block,e.sectionTitle)}},[H,D]),U=(0,W.useCallback)(e=>{if(!I.current){if(!k.current||j.current||!A.current||M.current){I.current=e,ue();return}I.current=e,F.current=!0,P(!0)}},[ue]),de=(0,W.useRef)(null),fe=(0,W.useRef)(null),pe=(0,W.useRef)(null);j4(`hero`,pe);let[me,he]=(0,W.useState)(!1),ge=(0,W.useRef)(me);ge.current=me;let _e=(0,W.useCallback)(()=>{let e=document.getElementById(`tour-section-editor`),t=de.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:p?`auto`:`smooth`})},[p]),ye=(0,W.useCallback)(()=>{he(!0),window.setTimeout(_e,350)},[_e]),be=(0,W.useCallback)(()=>{he(!1),window.scrollTo({top:0,behavior:p?`auto`:`smooth`})},[p]),xe=(0,W.useRef)(!1),Se=(0,W.useCallback)(()=>{U({kind:`apply-doc`,doc:v})},[v,U]);(0,W.useEffect)(()=>{let e=fe.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting?xe.current&&!ne.current&&(xe.current=!1,Se()):xe.current=!0});return t.observe(e),()=>t.disconnect()},[Se]);let Ce=(0,W.useCallback)(()=>{ase(),_(null),U({kind:`apply-doc`,doc:h})},[h,U]),we=(0,W.useCallback)(()=>{Se();let e=document.getElementById(`tour-section-editor`),t=de.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:p?`auto`:`smooth`})},[p,Se]);c({pageRoute:`/`,quests:n,initialSource:v,currentSource:b}),l({pageRoute:`/`,quests:n,completedResults:ee}),B.current=d(`/`,n),u({pageRoute:`/`,quests:n,running:oe}),(0,W.useEffect)(()=>{let e=document.getElementById(`tour-section-insights`);if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting&&B.current?.(`session-insights`)});return t.observe(e),()=>t.disconnect()},[]);let Te=(0,W.useCallback)(e=>{x(e),e!==v&&!w.current&&(w.current=!0,m?.(qP.demoEdited))},[v,m]),Ee=(0,W.useCallback)(e=>{C.current=e},[]),De=(0,W.useCallback)((e,t,n,r)=>{if(n){if(m?.(qP.demoRun),r&&se(!0),le(n),R(!0),ae(!0),re(e=>e+1),L(null),z.current||I.current){I.current={kind:`restart`,doc:t,block:n,sectionTitle:e};return}if(k.current&&A.current&&!j.current){I.current={kind:`restart`,doc:t,block:n,sectionTitle:e},F.current=!0,P(!0);return}if(k.current&&!j.current){O().then(()=>H(t,n,e));return}H(t,n,e)}},[H,O,m]),Oe=(0,W.useCallback)(()=>{De(`Run`,S.current,C.current[0],!0)},[De]),ke=(0,W.useCallback)(()=>{let e=()=>{let e=document.getElementById(`tour-section-insights`),t=de.current;if(!e||!t||typeof window.scrollTo!=`function`)return;let n=t.getBoundingClientRect().top+window.scrollY,r=Math.max(0,e.getBoundingClientRect().top+window.scrollY-n);window.scrollTo({top:r,behavior:p?`auto`:`smooth`})};if(ge.current){e();return}he(!0),window.setTimeout(e,350)},[p]),Ae=(0,W.useCallback)((e,t)=>{if(!(j.current&&!M.current))return(t.logs??[]).length===0?(j.current=!0,L(t),R(!1),ke(),ue()):(j.current=!0,D(t,t.completed).then(()=>{if(M.current=null,L(t),F.current||I.current)return R(!1),ue()}).catch(e=>{throw j.current=!1,A.current=!1,M.current=t,F.current=!1,P(!1),I.current=null,f({title:`Session not saved`,description:`The run could not be recorded. Nothing was lost — your next action retries the save.`,variant:`destructive`}),e}))},[D,ue,ke]),je=(0,W.useCallback)(()=>{R(!1),ke()},[ke]),Me=(0,W.useRef)(null),Ne=(0,W.useCallback)(e=>{Me.current=e},[]),Pe=(0,W.useCallback)(()=>{A.current=!0;let e=Me.current;ie&&e&&e.handle(new Gp(void 0,e.nowProvider)),ae(!1)},[ie]),{setL3Items:Fe}=SR(),Ie=(0,W.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:Oe}}},{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`}}],[Oe]);(0,W.useEffect)(()=>(Fe(Ie),()=>Fe([])),[Fe,Ie]),dse((0,W.useMemo)(()=>Ie.map(e=>e.action.type===`scroll`?e.action.sectionId:e.id),[Ie]));let Le=T?.block??ce,Re=te&&Le&&(0,G.jsx)(i??u2,{block:Le,resultId:T?.resultId,autoStart:ie,externalStop:N,onRunStarted:Pe,onRuntimeReady:Ne,onClose:je,onCompleteWorkout:Ae},V),ze=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(H6,{}),(0,G.jsxs)(`p`,{className:`-mt-8 text-center font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground xl:text-[11px]`,children:[`— or learn the language with examples`,` `,(0,G.jsx)(ve,{to:`/syntax`,className:`text-foreground underline underline-offset-4 transition-colors hover:text-primary`,children:`on the syntax page →`})]})]}),Be=(0,G.jsx)(M4,{gateId:`editor-pane`,segmentId:`hero`,className:`w-full max-w-[720px] xl:max-w-[820px] 2xl:max-w-[920px]`,children:(0,G.jsx)(N1,{title:y?y.toLowerCase().startsWith(`shared by`)?y:`shared by: ${y}`:`welcome-1.md`,headerActions:y&&(0,G.jsx)(`button`,{type:`button`,onClick:Ce,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,G.jsx)(U6,{doc:b,theme:t,onDocChange:Te,onBlocksChange:Ee,onRun:Oe,editorSlot:r})})}),Ve=(0,G.jsx)(`div`,{id:`tour-why-video-wrap`,"aria-hidden":me,className:K(`grid w-full transition-all duration-300 motion-reduce:transition-none`,me?`grid-rows-[0fr] opacity-0 invisible`:`grid-rows-[1fr] opacity-100`),children:(0,G.jsx)(`div`,{className:`min-h-0 overflow-hidden`,children:(0,G.jsx)(mse,{onWatched:ye})})}),He=(0,G.jsxs)(`div`,{ref:fe,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:[me&&(0,G.jsxs)(`button`,{type:`button`,onClick:be,"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,G.jsx)(bt,{className:`size-3`}),`Watch again`]}),Be]});return p?(0,G.jsxs)(`div`,{"data-testid":$.tour.HOME_TOUR,children:[(0,G.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,G.jsx)(N6,{}),Ve,He]}),(0,G.jsx)(t8,{session:ee,onRun:Oe,onBackToEditor:we}),(0,G.jsx)(s8,{feedDeps:o}),ze,(0,G.jsx)(B3,{variant:`university`}),(0,G.jsx)(F6,{}),Re]}):(0,G.jsxs)(`div`,{"data-testid":$.tour.HOME_TOUR,children:[(0,G.jsx)(`div`,{ref:de,"aria-hidden":!0,className:`h-px`}),(0,G.jsxs)(`section`,{ref:pe,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,G.jsx)(N6,{}),Ve,He]}),(0,G.jsx)(t8,{session:ee,onRun:Oe,onBackToEditor:we}),(0,G.jsx)(s8,{feedDeps:o}),ze,(0,G.jsx)(B3,{variant:`university`}),(0,G.jsx)(F6,{}),Re]})}function $se(e){return(0,G.jsx)(A6,{children:(0,G.jsx)(A4,{children:(0,G.jsx)(Qse,{...e})})})}function ece({wodFiles:e,theme:t}){let n=(0,W.useMemo)(()=>E6(e),[e]);return(0,W.useEffect)(()=>{Pw(`homeFirstPaint`)},[]),(0,G.jsx)($se,{wodFiles:n,theme:t,quests:T6.quests})}var tce=[`📓`,`🏋️`,`🔥`,`💪`,`⭐`,`🎯`,`🏃`,`🧘`,`🥊`,`🚴`],nce=({open:e,onOpenChange:t,onCreate:n,notebook:r,onSave:i})=>{let[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(`📓`),[d,f]=(0,W.useState)(!1),p=!!r;W.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,G.jsx)(eZ,{open:e,onOpenChange:t,children:(0,G.jsxs)(tZ,{className:`bg-popover text-popover-foreground border border-border`,children:[(0,G.jsxs)(nZ,{children:[(0,G.jsx)(rZ,{className:`text-foreground`,children:p?`Edit Notebook`:`Create Notebook`}),(0,G.jsx)(iZ,{children:p?`Rename, describe or re-icon this notebook.`:`Organize your sessions into collections.`})]}),(0,G.jsxs)(`div`,{className:`space-y-4 mt-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm font-medium text-foreground/80 mb-2 block`,children:`Icon`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:tce.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:K(`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,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`text-sm font-medium text-foreground/80 mb-1 block`,children:[`Name `,(0,G.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.keyCode===229||e.key===`Enter`&&!e.shiftKey&&a.trim()&&(e.preventDefault(),m())},placeholder:`e.g., Morning Routines`,autoFocus:!0,className:K(`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,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`text-sm font-medium text-foreground/80 mb-1 block`,children:[`Description `,(0,G.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`(optional)`})]}),(0,G.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`A brief description of this notebook...`,rows:2,className:K(`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,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(q,{variant:`default`,size:`sm`,onClick:()=>void m(),disabled:!a.trim()||d,children:d?`Saving…`:p?`Save`:`Create`})]})]})]})})};function c8({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,W.useRef)(a),[c,l]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{if(a>s.current){l(!0);let e=setTimeout(()=>l(!1),200);return s.current=a,()=>clearTimeout(e)}s.current=a},[a]),(0,G.jsxs)(`div`,{className:K(`w-full`,r),children:[n?(0,G.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,G.jsx)(`span`,{children:n}),(0,G.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[a,`/`,i]})]}):null,(0,G.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,G.jsx)(`div`,{className:K(`h-full rounded-pill transition-[width] duration-500 ease-out`,c?`bg-brand-deep`:`bg-brand`),style:{width:`${o}%`}})})]})}function l8(e,t,n,r){FJ.getState().open({placeholder:`Craft the query…`,wql:{initialQuery:e,execute:t,onApply:n,preferredChoices:r},sources:[pX()]})}function u8({query:e,onQueryChange:t,scopeOptions:n,execute:r,defaultQuery:i,compact:a=!1,className:o}){let s=(0,W.useCallback)(()=>l8(e,r,t,n),[e,r,t,n]);return a?(0,G.jsx)(`div`,{"data-testid":`stream-query-bar-dock`,className:K(`flex min-h-12 w-full items-stretch overflow-hidden rounded-xl border border-border bg-muted/40 shadow-xs`,o),children:(0,G.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,G.jsx)(Ye,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,G.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,G.jsx)(m,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]})}):(0,G.jsx)(`div`,{"data-testid":`stream-query-bar`,className:K(`flex min-w-0 flex-1 items-center gap-1 text-xs`,o),children:(0,G.jsx)(bD,{query:e,onQueryChange:t,compact:!0,showDiagnostics:!1,hiddenClauseTypes:[`agg`,`metric`,`rollup`,`pipes`],preferredChoices:n,placeholder:`Filter or search…`,className:`min-w-0 flex-1`})})}function rce(e,t){let n=t??Y(e);return n.error?null:n.groupBy?.length?n.groupBy.map(e=>String(e).toLowerCase()):null}function d8(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/(^-|-$)/g,``)||`default`}function f8(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=ice(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 ice(e,t,n){let r=t.toLowerCase(),i=US();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`:WS(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 pB(Array.from(t.entries()),`priority-then-alpha`,{priority:[`Strength`,`Gymnastics`,`Cardio`,`Running`,`Rowing`,`Weightlifting`]}).map(([e])=>e).map(e=>({id:`group-discipline-${d8(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 pB(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-origin-${d8(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 pB(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-source-${d8(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 pB(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-kind-${d8(e)}`,key:e,label:e,entries:t}))}if(r===`feed`){let t=new Map;for(let n of e){let e=n.feedId??(n.sourceNotebook===`journal`||n.sourceNotebook===`playground`?`local`:`core`),r=t.get(e);r?r.push(n):t.set(e,[n])}return pB(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-feed-${d8(e)}`,key:e,label:e===`local`?`Local`:e===`core`?`Core`:e,entries:t}))}if(!Xm.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 pB(Array.from(t.entries()),`alpha-sink-last`,{sink:`Unassigned`}).map(([e,t])=>({id:`group-property-${d8(r)}-${d8(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 pB(Array.from(a.entries()),`alpha-sink-last`,{sink:`Untagged`}).map(([e,t])=>({id:`group-tag-${d8(e)}`,key:e,label:e,entries:t}))}var ace=[{id:IR.route,label:`Journal`,profile:IR,scopeChoices:mE,shortcuts:!0},{id:RR.route,label:`Notes`,profile:RR,scopeChoices:mE,shortcuts:!0},{id:LR.route,label:`Notebooks`,profile:LR,scopeChoices:mE,shortcuts:!0},{id:zR.route,label:`Feeds`,profile:zR,scopeChoices:mE,shortcuts:!0},{id:BR.route,label:`Pages`,profile:BR,scopeChoices:mE,shortcuts:!0},{id:VR.route,label:`Efforts`,profile:VR,scopeChoices:mE,shortcuts:!0},{id:HR.route,label:`Equipment`,profile:HR,scopeChoices:mE,shortcuts:!0},{id:UR.route,label:`Tags`,profile:UR,shortcuts:!0},{id:WR.route,label:`Sessions`,profile:WR,scopeChoices:mE,shortcuts:!0},{id:GR.route,label:`Playgrounds`,profile:GR,scopeChoices:mE,shortcuts:!0}],p8={id:`/dashboards`,label:`Dashboards`,systemDefaultWql:`:dashboard{}`},m8={id:_B,label:`Command palette`,systemDefaultWql:lX,scopeChoices:mE},oce=[...ace,p8,m8];function sce(e){return oce.find(t=>t.id===e)}var h8=`w-full rounded-md border border-border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary/40`;function cce({open:e,onOpenChange:t,route:n,editing:r=null,initialQuery:i=``}){let[a,o]=(0,W.useState)(r?.label??``),[s,c]=(0,W.useState)(r?.icon??`bookmark`),[l,u]=(0,W.useState)(r?r.wql:i),[d,f]=(0,W.useState)(null),p=KB(n);(0,W.useEffect)(()=>{e&&(o(r?.label??``),c(r?.icon??`bookmark`),u(r?r.wql:i),f(null))},[e,r,i]);let m=r!==null&&!!r.to,h=r?.id!==`all`,g=a.trim(),_=l.trim(),v=_?oD(_).error??null:null,y=g?null:`Label is required.`,b=!!g&&!m&&(!h||!!_)&&!v;return(0,G.jsx)(dE,{open:e,onClose:()=>t(!1),title:r?`Edit shortcut`:`Save search shortcut`,description:`Saved shortcuts appear in this route's navigation panel. Stored ${FP?`on the server.`:`in this browser only.`}`,footer:(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(q,{type:`submit`,form:`save-wql-shortcut-form`,size:`sm`,disabled:!b,"data-testid":`shortcut-save`,children:`Save`})]}),children:(0,G.jsxs)(`form`,{id:`save-wql-shortcut-form`,onSubmit:async e=>{if(e.preventDefault(),!b)return;let i={id:r?.id??crypto.randomUUID(),label:g,icon:s,wql:m?r.wql:_,...r?.to===void 0?{}:{to:r.to}};if(!await eV(n,[...$B(n,void 0,p).filter(e=>e.id!==i.id),i])){f(`Couldn’t save — storage is unavailable. Your input is kept.`);return}t(!1)},className:`flex flex-col gap-4`,noValidate:!0,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{htmlFor:`shortcut-label`,className:`text-xs font-semibold text-muted-foreground`,children:`Label`}),(0,G.jsx)(`input`,{id:`shortcut-label`,value:a,onChange:e=>o(e.target.value),placeholder:`e.g. Strength this month`,"data-testid":`shortcut-label-input`,"aria-invalid":y?!0:void 0,className:h8}),y&&(0,G.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`shortcut-label-error`,children:y})]}),m?(0,G.jsxs)(`p`,{className:`rounded-md border border-border/60 bg-muted/30 px-3 py-2 text-xs text-muted-foreground`,children:[`Route action — always opens `,r?.to,`. Label and icon are editable.`]}):(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{htmlFor:`shortcut-query`,className:`text-xs font-semibold text-muted-foreground`,children:`Query (WQL)`}),(0,G.jsx)(`textarea`,{id:`shortcut-query`,rows:2,value:l,onChange:e=>u(e.target.value),placeholder:h?`find …`:`Empty — the plain route landing`,"data-testid":`shortcut-query-input`,"aria-invalid":v?!0:void 0,className:`${h8} font-mono text-xs`}),v?(0,G.jsxs)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`shortcut-query-error`,children:[`Couldn't parse — `,v]}):!_&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:h?`A shortcut needs a query.`:`Empty — opens the plain route landing.`})]}),(0,G.jsxs)(`fieldset`,{className:`space-y-1.5`,children:[(0,G.jsx)(`legend`,{className:`text-xs font-semibold text-muted-foreground`,children:`Icon`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Object.entries(zB).map(([e,t])=>(0,G.jsxs)(`label`,{title:e,className:s===e?`cursor-pointer rounded-md border border-primary bg-primary/10 p-1.5 text-primary`:`cursor-pointer rounded-md border border-border p-1.5 text-muted-foreground hover:text-foreground`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`shortcut-icon`,value:e,checked:s===e,onChange:()=>c(e),"aria-label":`Icon ${e}`,"data-testid":`shortcut-icon-${e}`,className:`sr-only`}),(0,G.jsx)(t,{className:`size-4`,"aria-hidden":`true`})]},e))})]}),d&&(0,G.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`shortcut-storage-error`,children:d})]})})}function g8({className:e,...t}){return(0,G.jsx)(zt,{"data-slot":`control`,...t,className:K(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,G.jsx)(`span`,{"aria-hidden":`true`,className:K(`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 lce=Object.fromEntries([...mE,...pE].map(e=>[e.value,e.label]));function _8({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,G.jsxs)(`div`,{className:`space-y-2`,children:[e.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((t,s)=>(0,G.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,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(dr,{className:`size-3`})}),(0,G.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,G.jsx)(cee,{className:`size-3`})})]}),(0,G.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,G.jsx)(Bn,{className:`size-3`})})]},t))}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.filter(t=>!e.includes(t.value)).map(t=>(0,G.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 uce({values:e,choices:t,onChange:n,testPrefix:r}){return(0,G.jsx)(_8,{values:e,choices:t,labels:lce,onChange:n,testPrefix:r,reorderable:!0})}function dce({values:e,onChange:t,testPrefix:n}){return(0,G.jsx)(_8,{values:e,choices:lB.map(e=>({value:e.id,label:e.label})),labels:Object.fromEntries(lB.map(e=>[e.id,e.label])),onChange:t,testPrefix:n,reorderable:!0})}function v8({label:e,enabled:t,onEnabledChange:n,testId:r,children:i}){return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:e}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[`Custom`,(0,G.jsx)(g8,{checked:t,onChange:n,"data-testid":r})]})]}),i]})}function fce({shortcuts:e,icons:t,landingId:n,onEdit:r,onDelete:i,onCreate:a,error:o,testPrefix:s}){return(0,G.jsxs)(`div`,{className:`space-y-2`,"data-testid":`${s}-shortcuts`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:`Saved shortcuts`}),(0,G.jsx)(q,{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,G.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,G.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`min-w-0 max-w-40 truncate text-xs font-medium`,children:e.label}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[10px] text-muted-foreground`,children:o}),(0,G.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,G.jsx)(me,{className:`size-3`})}),!e.to&&e.id!==n&&(0,G.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,G.jsx)(Dr,{className:`size-3`})})]},e.id)}),o&&(0,G.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`${s}-shortcut-error`,children:o})]})}function y8(e){return{defaultWql:e.defaultWql??``,customScope:e.typeOptions!==void 0,scopeOptions:e.typeOptions??[],customGroupBy:e.groupByOptions!==void 0,groupByOptions:e.groupByOptions??[]}}function pce(e){return{defaultWql:e.defaultWql.trim()||void 0,typeOptions:e.customScope?e.scopeOptions:void 0,groupByOptions:e.customGroupBy?e.groupByOptions:void 0}}function b8({surface:e,onSaved:t}){let n=IB(e.id),r=oV(e.id),[i,a]=(0,W.useState)(()=>y8(n)),[o,s]=(0,W.useState)(()=>n),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null);(0,W.useEffect)(()=>{a(y8(n)),s(n),l(null),d(null)},[n]);let m=e.profile?.defaultWql??e.systemDefaultWql??``,h=(()=>{let e=i.defaultWql.trim();return e?oD(e).error??null:null})(),g=pce(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&&oD(n).error)){if(!await kB(e.id,g)){l(`Save failed — storage is unavailable; the previous default still stands.`);return}l(null),s(OB(e.id)),t?.()}},x=async()=>{if(!await AB(e.id)){l(`Reset failed — storage is unavailable; the stored override still stands.`);return}l(null),s({}),a(y8({})),t?.()},S=async t=>{d(null),await eV(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,G.jsxs)(`div`,{className:`space-y-5`,"data-testid":`query-settings-panel`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:`Landing default query`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`System default: `,(0,G.jsx)(`span`,{className:`font-mono`,children:m})]}),(0,G.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,G.jsxs)(`p`,{className:`text-xs text-destructive`,"data-testid":`query-settings-wql-error`,children:[`Couldn't parse — `,h]}):!i.defaultWql.trim()&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Empty — the system default is used.`})]}),y.length>0&&(0,G.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,G.jsx)(v8,{label:`Where-stored options`,enabled:i.customScope,onEnabledChange:e=>a({...i,customScope:e}),testId:`query-settings-scope-custom`,children:i.customScope&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(uce,{values:i.scopeOptions,choices:C,onChange:e=>a({...i,scopeOptions:e}),testPrefix:`query-settings-scope`}),i.scopeOptions.length===0&&(0,G.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,G.jsxs)(v8,{label:`Group-by options`,enabled:i.customGroupBy,onEnabledChange:e=>a({...i,customGroupBy:e}),testId:`query-settings-group-custom`,children:[(0,G.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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(dce,{values:i.groupByOptions,onChange:e=>a({...i,groupByOptions:e}),testPrefix:`query-settings-group`}),i.groupByOptions.length===0&&(0,G.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,G.jsx)(fce,{shortcuts:r,icons:zB,landingId:`all`,onEdit:e=>p({editing:e}),onDelete:S,onCreate:()=>p({editing:null}),error:u,testPrefix:`query-settings`}),c&&(0,G.jsx)(`p`,{className:`text-xs text-destructive`,"data-testid":`query-settings-storage-error`,role:`alert`,children:c}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:x,disabled:!v,"data-testid":`query-settings-reset`,children:[(0,G.jsx)(ht,{className:`size-3.5`}),(0,G.jsx)(`span`,{children:`Reset to system default`})]}),(0,G.jsx)(q,{size:`sm`,onClick:b,disabled:!_||!!h,"data-testid":`query-settings-save`,children:`Save`})]}),f&&(0,G.jsx)(cce,{open:!0,onOpenChange:e=>{e||p(null)},route:e.id,editing:f.editing})]})}function x8({surface:e,open:t,onOpenChange:n}){return(0,G.jsx)(dE,{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,G.jsx)(b8,{surface:e})})}function S8({feedParam:e,onDismiss:t,onRegistered:n,onSubscribed:r}){let[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let t=!0,n=oP(e);return n?(a(n),l(!0),h(null),new XF(n).fetchManifest().then(e=>{if(!t)return;let n=zx(e);p(n),l(!1)}).catch(e=>{t&&(h(e instanceof Error?e.message:`Failed to probe feed manifest.`),l(!1))})):(a(null),p(null),l(!1)),()=>{t=!1}},[e]);let v=()=>{let e=oP(o);if(!e){h(`Invalid feed URL. Must be an HTTPS URL.`);return}a(e),l(!0),h(null),new XF(e).fetchManifest().then(e=>{let t=zx(e);p(t),l(!1)}).catch(e=>{h(e instanceof Error?e.message:`Failed to probe feed manifest.`),l(!1)})},y=async()=>{if(!(!i||!f||u)){d(!0);try{let e=pP(f.name??`Custom Feed`,i);mI(e.id,!1),await $I(e.id,f),n(e.id)}catch(e){h(e instanceof Error?e.message:`Failed to register feed.`)}finally{d(!1)}}},b=async()=>{if(!(!i||!f||u)){d(!0),h(null);try{let e=pP(f.name??`Custom Feed`,i);mI(e.id,!1),await $I(e.id,f),await ML(e.id,{subscribe:!1,manifest:f}),r(e.id)}catch(e){h(e instanceof Error?e.message:`Import failed.`)}finally{d(!1)}}},x=async()=>{if(!(!i||!f||u)){d(!0),h(null);try{let e=pP(f.name??`Custom Feed`,i);mI(e.id,!0),xI(e.id,g),await $I(e.id,f),await ML(e.id,{manifest:f}),r(e.id)}catch(e){h(e instanceof Error?e.message:`Sync failed.`)}finally{d(!1)}}};if(!i&&!f)return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border bg-card/60 p-4 mb-4`,"data-testid":`unknown-feed-intake-banner`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs font-semibold px-2 py-0.5 rounded bg-sky-500/10 text-sky-500 border border-sky-500/30`,children:`Unknown Feed`}),(0,G.jsxs)(`span`,{className:`text-sm font-semibold text-foreground`,children:[`Feed "`,e,`" is not registered`]})]}),(0,G.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 px-2 text-xs`,children:[(0,G.jsx)(Bn,{className:`size-3.5 mr-1`}),`Dismiss`]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:[`To browse or import this feed, enter its HTTPS seed directory URL (containing `,(0,G.jsx)(`code`,{children:`manifest.json`}),`):`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(WY,{value:o,onChange:e=>s(e.target.value),placeholder:`https://example.com/seed/`,className:`text-xs h-8 flex-1`}),(0,G.jsxs)(q,{size:`sm`,onClick:v,disabled:!o.trim()||c,className:`h-8 text-xs`,children:[c?(0,G.jsx)(Sr,{className:`size-3 animate-spin mr-1`}):null,`Probe Feed`]})]}),m&&(0,G.jsx)(`p`,{className:`text-xs text-destructive mt-2`,children:m})]});if(c)return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border bg-card/60 p-4 mb-4 flex items-center gap-3 text-xs text-muted-foreground`,"data-testid":`unknown-feed-intake-banner`,children:[(0,G.jsx)(Sr,{className:`size-4 animate-spin text-primary`}),(0,G.jsxs)(`span`,{children:[`Probing feed manifest at `,(0,G.jsxs)(`code`,{children:[i,`manifest.json`]}),`…`]})]});if(m&&!f)return(0,G.jsxs)(`div`,{className:`rounded-xl border border-destructive/40 bg-destructive/10 p-4 mb-4 text-xs`,"data-testid":`unknown-feed-intake-banner`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive font-semibold`,children:[(0,G.jsx)(Jr,{className:`size-4`}),(0,G.jsx)(`span`,{children:`Feed Probe Failed`})]}),(0,G.jsx)(q,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 px-2 text-xs`,children:`Dismiss`})]}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:m})]});if(!f)return null;let S=f.notebooks?.length??f.chunks.length,C=f.notebooks?.reduce((e,t)=>e+(t.count??0),0)??f.chunks.reduce((e,t)=>e+(t.count??0),0);return(0,G.jsxs)(`div`,{className:`rounded-xl border border-sky-500/40 bg-sky-500/5 p-4 mb-4 space-y-3`,"data-testid":`unknown-feed-intake-banner`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded bg-sky-500/20 text-sky-400 border border-sky-500/30`,children:`Feed Deep Link`}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:i})]}),(0,G.jsxs)(`h3`,{className:`text-base font-bold text-foreground mt-1`,children:[`Add "`,f.name??`Custom Feed`,`" to your Library?`]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:f.description??`Published whiteboard workouts and notebooks.`})]}),(0,G.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:t,disabled:u,className:`h-7 px-2 text-xs`,children:[(0,G.jsx)(Bn,{className:`size-3.5 mr-1`}),`Decline`]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2 text-xs bg-background/50 p-3 rounded-lg border border-border/40`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-muted-foreground block text-[10px] uppercase font-bold`,children:`Version`}),(0,G.jsxs)(`span`,{className:`font-mono`,children:[`v`,f.version,` (schema `,f.schema,`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-muted-foreground block text-[10px] uppercase font-bold`,children:`Notebooks`}),(0,G.jsxs)(`span`,{children:[S,` notebooks (`,C,` items)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-muted-foreground block text-[10px] uppercase font-bold`,children:`Built`}),(0,G.jsx)(`span`,{className:`font-mono`,children:f.builtAt?f.builtAt.slice(0,10):`unknown`})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-xs`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border text-primary`}),(0,G.jsx)(`span`,{children:`Auto-sync updates`})]})})]}),m&&(0,G.jsx)(`p`,{className:`text-xs text-destructive`,children:m}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2 pt-1`,children:[(0,G.jsx)(q,{variant:`outline`,size:`sm`,onClick:y,disabled:u,"data-testid":`feed-intake-browse`,className:`text-xs h-8`,children:`Browse in Library (Register Only)`}),(0,G.jsxs)(q,{variant:`outline`,size:`sm`,onClick:b,disabled:u,"data-testid":`feed-intake-once`,className:`text-xs h-8`,children:[u?(0,G.jsx)(Sr,{className:`size-3 animate-spin mr-1`}):null,`Import Once`]}),(0,G.jsxs)(q,{size:`sm`,onClick:x,disabled:u,"data-testid":`feed-intake-subscribe`,className:`text-xs h-8 bg-sky-600 hover:bg-sky-500 text-white`,children:[u?(0,G.jsx)(Sr,{className:`size-3 animate-spin mr-1`}):null,`✓ Subscribe & Sync All`]})]})]})}var C8=e=>KS(new Date(e)),mce=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 hce(e,t){Z(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 w8={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 T8(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??w8[e.outcome]}}function gce({source:e,running:t,disabled:n,onSync:r,onSubscribe:i,onUnsubscribe:a,onDelete:o,onAutoSync:s,onToggleNotebook:c,subscribedOnly:l}){let u=lt(),d=(0,W.useSyncExternalStore)(vI,()=>bI(e.id)),f=e.notebooks.filter(t=>t.id!==e.id),p=fI(e.id),m=f.filter(e=>e.subscribed).length;l&&f.filter(e=>e.subscribed);let h=e.autoImport,g=e.subscribed&&!e.upToDate&&e.remote!==null,_=e=>{let t=e.currentTarget.closest(`details`);t&&(t.open=!1)};return(0,G.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,"data-testid":`feed-source-${e.id}`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-x-4 gap-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:e.label}),(0,G.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`}),h&&(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 flex-wrap justify-end`,children:[e.subscribed?g?(0,G.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>r(e.id),disabled:n,"data-testid":`feed-sync-${e.id}`,className:`gap-2`,children:[(0,G.jsx)(B,{className:`size-3.5 ${t?`animate-spin`:``}`}),(0,G.jsx)(`span`,{children:t?`Syncing…`:`Sync`})]}):(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,"data-testid":`feed-current-${e.id}`,children:[(0,G.jsx)(be,{className:`size-3.5 text-emerald-500`}),e.remote===null?`Remote unreachable`:`Up to date`]}):(0,G.jsxs)(q,{size:`sm`,onClick:()=>i(e.id),disabled:n,"data-testid":`feed-subscribe-${e.id}`,className:`gap-2`,children:[(0,G.jsx)(Te,{className:`size-3.5`}),(0,G.jsx)(`span`,{children:`Subscribe`})]}),(0,G.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,G.jsx)(`input`,{type:`checkbox`,className:`size-3.5 accent-primary`,checked:d,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,G.jsx)(`span`,{children:`Auto-sync`})]}),(0,G.jsxs)(`details`,{className:`relative shrink-0`,"data-testid":`feed-more-${e.id}`,onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),e.currentTarget.open=!1,e.currentTarget.querySelector(`summary`)?.focus())},children:[(0,G.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,G.jsx)(`div`,{className:`fixed inset-0 z-50`,"data-testid":`feed-more-backdrop`,"aria-hidden":`true`,onClick:e=>{e.stopPropagation(),_(e)}}),(0,G.jsxs)(`div`,{className:`absolute right-0 z-[60] 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`,onClick:e=>{let t=e.target;(t.closest(`button`)||t.closest(`a`))&&_(e)},children:[e.url?(0,G.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,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Published HTML: bundled with this app (no standalone URL)`}),e.repositoryUrl?(0,G.jsx)(`a`,{href:e.repositoryUrl,target:`_blank`,rel:`noopener noreferrer`,className:`break-all text-primary hover:underline`,children:`Git source directory`}):(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Git repository: not published`}),!h&&(0,G.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`}),!h&&(0,G.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,G.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono break-all`,"data-testid":`feed-origin-${e.id}`,children:e.url}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`feed-description-${e.id}`,children:e.description}),(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/20 px-3 py-2 flex flex-wrap items-center justify-between gap-3`,"data-testid":`feed-notebooks-${e.id}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:`Subscription Mode`}),(0,G.jsx)(`div`,{className:`mt-1 flex items-center gap-2`,children:(0,G.jsx)(`span`,{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded text-xs font-semibold ${p===`full`?`bg-emerald-500/10 text-emerald-600`:p===`partial`?`bg-amber-500/10 text-amber-600`:`bg-muted text-muted-foreground`}`,"data-testid":`feed-sub-mode-${e.id}`,children:p===`full`?`Full`:p===`partial`?`Partial (${m} of ${f.length} subscribed)`:`Unsubscribed`})})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(`/notebooks?q=:notebook{feed:${e.id},subscribed:true,false}`),"data-testid":`browse-notebooks-link-${e.id}`,className:`text-xs font-semibold text-primary hover:underline flex items-center gap-1`,children:`Browse notebooks in Library →`})]}),(0,G.jsxs)(`div`,{className:`grid gap-1 text-sm`,"data-testid":`feed-status-card`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Library`}),(0,G.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`,` · `,mce(e.bytes)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Local database`}),(0,G.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 ${C8(e.stored.importedAt)}`:`Not imported yet`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Published version`}),(0,G.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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Jr,{className:`size-3.5 text-muted-foreground`}),`Unavailable`]}):`Checking…`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Last check`}),(0,G.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-last-check`,children:e.checkedAt?C8(e.checkedAt):`—`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Last sync`}),(0,G.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-last-sync`,children:e.stored?C8(e.stored.importedAt):`Never`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Status`}),(0,G.jsx)(`span`,{className:`font-medium text-xs flex items-center gap-1.5`,"data-testid":`feed-sync-status`,children:e.subscribed?e.upToDate?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(be,{className:`size-3.5 text-emerald-500`}),`Up to date`]}):e.remote==null?`Unknown (remote unreachable)`:d?`Update available — applied automatically on next load`:`Update available — sync to apply`:`Not subscribed`})]})]})]})}function _ce({deps:e={}}={}){let{readFeedStatus:t=RL,syncFeedSource:n=ML,runFeedSync:r=kL}=e,[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(!0),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)([]),[m,h]=(0,W.useState)(``),[g,_]=(0,W.useState)(``),[v,y]=(0,W.useState)(null),[b,x]=(0,W.useState)(!0),[S,C]=(0,W.useState)(),w=(0,W.useCallback)(async()=>{l(null);try{a(await t())}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}},[]);(0,W.useEffect)(()=>{w()},[w]),(0,W.useEffect)(()=>vI(()=>{w()}),[w]),(0,W.useEffect)(()=>SL(()=>{w()}),[w]);let T=(0,W.useCallback)(async e=>{d(e??`all`),p([]);let t=e=>p(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{hce(e?await n(e,{force:!0,onProgress:t}):await r({force:!0,onProgress:t}),e?i?.sources.find(t=>t.id===e)?.label??e:`All sources`),await w()}finally{d(null)}},[w,i]),E=(0,W.useCallback)(async(e,t,n)=>{gI(e,t,n),n?await T(e):await w()},[T,w]),D=(0,W.useCallback)(async()=>{y(null);let e;try{e=pP(m,g)}catch(e){y(e instanceof Error?e.message:String(e));return}h(``),_(``),await T(e.id)},[m,g,T]),O=(0,W.useCallback)((e,t)=>{xI(e,t)||Z({title:`Couldn't save Auto-sync`,description:`Browser storage is unavailable — the choice lasts this session only.`,variant:`destructive`}),w()},[w]),k=(0,W.useCallback)(async e=>{let t=i?.sources.find(t=>t.id===e)?.label??e;if(window.confirm(`Unsubscribe from "${t}"? 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:n}=await FL(e);Z({title:`${t} unsubscribed`,description:`${n.toLocaleString()} imported ${n===1?`item`:`items`} removed. The source stays listed for a later Subscribe.`})}catch(e){Z({title:`${t} unsubscribe failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`});return}await w()}},[i,w]),A=(0,W.useCallback)(async e=>{let t=i?.sources.find(t=>t.id===e)?.label??e;if(window.confirm(`Delete "${t}"? Imported content is removed and the source is unregistered. Your own notes are never touched.`)){try{let{deleted:n}=await IL(e);Z({title:`${t} deleted`,description:`${n.toLocaleString()} imported ${n===1?`item`:`items`} removed and the source unregistered.`})}catch(e){Z({title:`${t} delete failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`});return}await w()}},[i,w]),j=f.at(-1)?.event;return(0,G.jsxs)(`div`,{className:`space-y-8`,children:[(0,G.jsxs)(`section`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,G.jsx)(Te,{className:`size-4 text-primary`}),`Content Sources`]}),(0,G.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.`})]}),c&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-destructive`,"data-testid":`feed-status-error`,children:[(0,G.jsx)(Jr,{className:`size-3.5 shrink-0`}),`Couldn't read the feed status from the active storage: `,c]}),j&&(0,G.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-border bg-card p-4`,"data-testid":`feed-sync-progress`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-sm font-medium`,children:[(0,G.jsx)(`span`,{children:u===null?f.some(e=>e.event.phase===`finished`&&e.event.outcome===`error`)?`Sync finished with errors`:`Sync finished`:`Syncing…`}),(0,G.jsxs)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:[`Source `,j.sourceIndex,` of `,j.totalSources]})]}),(0,G.jsxs)(`p`,{role:`status`,"aria-live":`polite`,className:`sr-only`,"data-testid":`feed-sync-live-status`,children:[j.sourceLabel,`: `,T8(j)]}),f.map(({event:e,imported:t,chunks:n})=>(0,G.jsxs)(`div`,{className:`space-y-2 border-t border-border/50 pt-3`,children:[(0,G.jsxs)(`p`,{className:`text-xs ${e.phase===`finished`&&e.outcome===`error`?`text-destructive`:`text-muted-foreground`}`,children:[(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:e.sourceLabel}),` · `,T8(e)]}),t&&t.totalChunks>0?(0,G.jsx)(c8,{value:t.completedChunks,max:t.totalChunks,label:`Chunks committed · ${e.sourceLabel}`}):e.phase===`finished`?null:(0,G.jsx)(`progress`,{"aria-label":`Checking ${e.sourceLabel}`,className:`h-2 w-full`}),t&&(0,G.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-xs tabular-nums`,"data-testid":`feed-sync-totals`,children:[(0,G.jsxs)(`span`,{children:[t.totalNotes.toLocaleString(),` notes`]}),(0,G.jsxs)(`span`,{children:[t.totalEfforts.toLocaleString(),` efforts`]}),(0,G.jsxs)(`span`,{children:[t.totalBlocks.toLocaleString(),` blocks`]}),t.skippedUserOwned>0&&(0,G.jsxs)(`span`,{children:[t.skippedUserOwned.toLocaleString(),` user-owned rows preserved`]}),t.deleted>0&&(0,G.jsxs)(`span`,{children:[t.deleted.toLocaleString(),` feed rows removed`]})]}),n.length>0&&(0,G.jsxs)(`details`,{className:`text-xs`,"data-testid":`feed-sync-chunks`,children:[(0,G.jsxs)(`summary`,{className:`cursor-pointer text-muted-foreground`,children:[`Committed chunks (`,n.length,`)`]}),(0,G.jsx)(`ul`,{className:`mt-2 max-h-32 space-y-1 overflow-y-auto font-mono text-muted-foreground`,children:n.map(e=>(0,G.jsx)(`li`,{children:e},e))})]})]},e.sourceId))]}),(0,G.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,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer select-none text-muted-foreground hover:text-foreground`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),"data-testid":`sync-subscribed-only-toggle`,className:`size-3.5 accent-primary rounded`}),(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:`Subscribed only`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Source:`}),(0,G.jsxs)(`select`,{value:S??``,onChange:e=>C(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,G.jsx)(`option`,{value:``,children:`All feeds`}),i?.sources.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-3`,"data-testid":`feed-source-list`,children:[i?.sources.filter(e=>{if(S&&e.id!==S)return!1;if(b){let t=e.notebooks.some(e=>e.subscribed);if(!e.subscribed&&!t)return!1}return!0}).map(e=>(0,G.jsx)(gce,{source:e,running:u===e.id||u===`all`,disabled:u!==null,onSync:e=>{T(e)},onSubscribe:e=>{T(e)},onUnsubscribe:e=>{k(e)},onDelete:e=>{A(e)},onAutoSync:O,onToggleNotebook:E,subscribedOnly:b},e.id)),o&&i===null&&(0,G.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground`,children:`Checking sources…`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-border/50`,children:[(0,G.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,G.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>{T(null)},disabled:u!==null||o,"data-testid":`feed-resync-button`,className:`gap-2`,children:[(0,G.jsx)(B,{className:`size-3.5 ${u===`all`?`animate-spin`:``}`}),(0,G.jsx)(`span`,{children:u===`all`?`Syncing all…`:`Sync All Sources`})]})]})]}),(0,G.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,G.jsx)(kn,{className:`size-4 text-primary`}),`Add a Source`]}),(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Register any URL serving a Wod Wiki feed (a directory with `,(0,G.jsx)(`code`,{children:`manifest.json`}),` and`,` `,(0,G.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,G.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,"data-testid":`feed-add-source-form`,children:[(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`feed-source-label`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Label`}),(0,G.jsx)(WY,{id:`feed-source-label`,value:m,onChange:e=>h(e.target.value),placeholder:`My library (optional — defaults to the host name)`,disabled:u!==null})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`feed-source-url`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Feed directory URL`}),(0,G.jsx)(WY,{id:`feed-source-url`,type:`text`,autoComplete:`off`,spellCheck:!1,value:g,onChange:e=>_(e.target.value),placeholder:`https://example.com/feed/library/`,className:`font-mono`,disabled:u!==null})]})]}),v&&(0,G.jsxs)(`p`,{role:`alert`,className:`flex items-start gap-1.5 text-xs text-destructive`,"data-testid":`feed-add-error`,children:[(0,G.jsx)(Jr,{className:`size-3.5 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:v})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsxs)(q,{size:`sm`,onClick:()=>{D()},disabled:u!==null||!g.trim(),"data-testid":`feed-add-button`,className:`gap-2`,children:[(0,G.jsx)(ut,{className:`size-3.5`}),(0,G.jsx)(`span`,{children:`Add & Sync`})]})})]})]})]})}var E8=[`cards`,`rows`,`feed`,`agenda`,`planner`],vce={stream:`cards`,table:`rows`},yce=`wodwiki.viewSettings.v1`,D8={"/notebooks":`/catalogs`,"/notes":`/feeds`,"/sessions":`/results`,"/dashboards":`/dashboard`},O8={"/notes":`/collections`},bce={"/feeds":`/feeds@2`};function k8(e){let t=e.startsWith(`/`)?e:`/${e}`;return bce[t]??t}var A8=new nw(yce);function j8(e,t){return{level:e,layout:t??`cards`,visibleFields:pK(e),groupBy:void 0}}function M8(e,t,n=A8,r){let i=j8(t,r),a=k8(e),o=D8[a],s=n.get(a,{alias:o});if(s==null&&o&&(s=n.get(o,{alias:O8[a]})),!s)return i;let c=typeof s.layout==`string`?s.layout:``,l=E8.includes(c)?c:vce[c]??`cards`,u=new Set(fK(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 xce(e,t,n=A8){let r=k8(e);n.set(r,{level:t.level,layout:t.layout,visibleFields:t.visibleFields,groupBy:t.groupBy})}function Sce(e,t,n=A8){let r=k8(e),i=D8[r],a=O8[r];return n.remove(r,i),a&&n.remove(a),j8(t)}function Cce(e,t,n){let[r,i]=(0,W.useState)(()=>M8(e,t,A8,n));(0,W.useEffect)(()=>{i(M8(e,t,A8,n))},[e,t,n]);let a=(0,W.useCallback)(t=>{i(n=>{let r=t(n);return xce(e,r),r})},[e]);return{settings:r,setLayout:(0,W.useCallback)(e=>{a(t=>({...t,layout:e}))},[a]),toggleField:(0,W.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,W.useCallback)(e=>{a(t=>({...t,visibleFields:e}))},[a]),setGroupBy:(0,W.useCallback)(e=>{a(t=>({...t,groupBy:e}))},[a]),resetSettings:(0,W.useCallback)(()=>{let n=Sce(e,t);i(n)},[e,t])}}function wce(e,t=200){let[n,r]=(0,W.useState)(t),i=(0,W.useRef)(null);(0,W.useEffect)(()=>{r(t)},[e,t]);let a=n<e.length,o=(0,W.useCallback)(t=>r(n=>Math.max(n,Math.min(Math.max(t,0),e.length))),[e.length]);return(0,W.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}}var N8={source:!0,tags:!0,notebook:!0,text:!0,type:!0,has:!0};function Tce(e,t){let n=Y(e);if(n.error)return e;if(Eh(n))return yg({...n,metric:t});if(!Th(n))return e;let r=/^:(journal|notebooks|playground)(?:\{|\s|$)/.exec(e.trim())?.[1],i=n.filters.filter(e=>!(!N8[e.key]||r&&e.key===`source`&&e.values.length===1&&e.values[0].value===r));return yg({family:`aggregate`,raw:``,agg:`sum`,metric:t,filters:n.filters.filter(e=>!N8[e.key]),groupBy:[`week`],window:n.window,...i.length>0||r||n.target!==`note`?{join:{target:r??n.target,filters:i}}:{}}).replace(/ where :(journal|notebooks|playground)$/,` where :$1{}`)}function Ece(e){let t=Y(e);return t.error?e:yg({...t,window:void 0})}function Dce(e,t){let n=Y(e);return n.error||n.family===`pipeline`?e:yg({...n,groupBy:[t]})}function P8(e){return e.kind===`note`&&!e.sourceNote?!1:e.kind===`note`}async function Oce(e){if(e.wodBlock?.content.trim())return e.wodBlock.content;let t=await Uz.resolve(e.id),n=nY(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 kce(e,t){return{id:e.wodBlock?.blockId??e.block?.blockId??xr(),contentId:e.wodBlock?.blockContentId??e.blockContentId,dialect:`time`,startLine:0,endLine:t.split(`
1117
1117
  `).length,content:t,state:`idle`,widgetIds:{},version:1,createdAt:Date.now()}}async function Ace(e,t,n={}){let r=await Oce(e),i=kce(e,r),a=xr();if(tH(e)){let n=await Uz.getById(e.id),r=e.wodBlock||e.block?n.blocks?.[i.id]:Object.values(n.blocks??{}).find(e=>e.kind===`wod`);if(!r)throw Error(`The selected saved workout is unavailable.`);dF.set(a,{block:{...i,id:r.id},noteId:e.id,origin:`playground`,returnTo:eH(e)}),t(cz(a));return}let o=await(n.createJournalNoteFromWorkout??d6)({workoutName:e.title,category:e.sourceNotebook,sourceNoteId:e.id,sourceNoteLabel:e.subtitle??e.title,sourceNotePath:eH(e),wodContent:r}),s=Object.values(o.blocks??{}).find(e=>e.kind===`wod`);if(!s)throw Error(`The saved journal workout is unavailable.`);dF.set(a,{block:{...i,id:s.id},noteId:o.id}),t(nz(o.journalDate??``,a))}var jce={note:Rr,effort:ot,result:vn,segment:$t,event:Qt,dashboard:gr,equipment:Er,tag:Jt,feed:p,notebook:br},Mce={note:`Note`,effort:`Effort`,result:`Result`,segment:`Segment`,event:`Event`,dashboard:`Dashboard`,equipment:`Equipment`,tag:`Tag`,feed:`Feed`,notebook:`Notebook`},Nce={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`,feed:`bg-amber-500/10 text-amber-600 group-hover:bg-amber-500/20`,notebook:`bg-emerald-500/10 text-emerald-600 group-hover:bg-emerald-500/20`};function F8({entry:e,leading:t,actions:n,dateLabel:r,visibleFieldIds:i,tone:a=`secondary`,onAddToToday:o,onRunStart:s,moveNotebookTargets:c,onMoveNotebook:l,onToggleSubscribe:u,onCloneRemote:d,onPublishFeed:f,onTogglePublicNotebook:m,onEditNotebook:h,onDeleteNotebook:g}){let _=lt(),v=e.kind===`note`?e.sourceNotebook:void 0,y=!!v&&v!==`journal`&&v!==`playground`&&v!==`guides`,b=v===`playground`?Or:v===`guides`?br:y?p:jce[e.kind],x=v===`playground`?`Playground`:v===`guides`?`Guide`:y?`Notebook`:Mce[e.kind],S=y?`bg-amber-500/10 text-amber-600 group-hover:bg-amber-500/20`:Nce[e.kind],C=a===`primary`,w=nH(e),T=eH(e),E=i?new Set(i):null,D=!E||E.has(`date`),O=!E||E.has(`sourceNotebook`)||E.has(`protocol`)||E.has(`elapsedTime`)||E.has(`splitDuration`)||E.has(`discipline`)||E.has(`met`)||E.has(`canonicalSlug`),k=!E||E.has(`excerpt`)||E.has(`movements`)||E.has(`tags`)||E.has(`aliases`);return(0,G.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>_(eH(e)),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),_(eH(e)))},className:`flex flex-wrap sm:flex-nowrap items-center gap-3 sm:gap-4 px-4 sm:px-6 py-3.5 hover:bg-muted/40 transition-colors text-left group w-full cursor-pointer ${C?`bg-primary/[0.025]`:``}`,"data-testid":`library-row-${e.kind}`,children:[t,(0,G.jsx)(`div`,{className:`flex-shrink-0 size-9 rounded-xl flex items-center justify-center transition-colors ${S}`,children:(0,G.jsx)(b,{className:`size-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,G.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,G.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,G.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:x}),(e.kind===`feed`||e.kind===`notebook`)&&e.feedId!==`local`&&e.feedId!==`core`&&(0,G.jsx)(`span`,{className:`text-[9px] font-bold uppercase tracking-wider rounded-full px-2 py-0.5 border ${e.subscribed?`border-emerald-500/40 bg-emerald-500/10 text-emerald-600`:`border-border bg-muted text-muted-foreground`}`,"data-testid":`library-row-sub-status-${e.sourceNote}`,children:e.subscribed?`Subscribed`:`Unsubscribed`}),e.kind===`notebook`&&e.feedId===`local`&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[9px] font-bold uppercase tracking-wider rounded-full px-2 py-0.5 border ${e.isPublic?`border-emerald-500/40 bg-emerald-500/10 text-emerald-600`:`border-border bg-muted/60 text-muted-foreground`}`,"data-testid":`library-row-visibility-${e.sourceNotebook}`,children:[e.isPublic?(0,G.jsx)(wn,{className:`size-2.5`}):(0,G.jsx)(un,{className:`size-2.5`}),e.isPublic?`Public`:`Private`]}),e.kind===`feed`&&e.unpublishedChanges&&(0,G.jsx)(`span`,{className:`text-[9px] font-bold uppercase tracking-wider rounded-full px-2 py-0.5 border border-amber-500/40 bg-amber-500/10 text-amber-600`,children:`Unpublished changes`}),e.isRemotePreview&&(0,G.jsx)(`span`,{className:`text-[9px] font-bold uppercase tracking-wider rounded-full px-2 py-0.5 border border-sky-500/40 bg-sky-500/10 text-sky-600`,children:`Remote Preview`}),e.execution?.effortSlug&&(0,G.jsx)(ve,{to:bz(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}),w&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(ve,{to:T,"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,G.jsx)(ve,{to:w,"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&&O&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 truncate`,children:e.subtitle})]}),k&&(e.block?(0,G.jsx)(`div`,{className:`mt-0.5`,"data-testid":`library-row-block-preview`,children:e.block.preview.map((e,t)=>(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground truncate font-mono`,children:e},t))}):e.detail?(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground truncate mt-0.5`,children:e.detail}):null)]}),(()=>{let t=r??(e.execution?.timestamp?new Date(e.execution.timestamp).toLocaleTimeString(`en-US`,{hour:`numeric`,minute:`2-digit`}):void 0);return t&&D?(0,G.jsx)(`span`,{className:`flex-shrink-0 text-[10px] text-muted-foreground/70 tabular-nums self-start sm:self-auto pt-0.5 sm:pt-0`,"data-testid":`library-row-date`,children:t}):null})(),n??(0,G.jsx)(Pce,{entry:e,onAddToToday:o,onRunStart:s,moveNotebookTargets:c,onMoveNotebook:l,onToggleSubscribe:u,onCloneRemote:d,onPublishFeed:f,onTogglePublicNotebook:m,onEditNotebook:h,onDeleteNotebook:g})]})}function Pce({entry:e,onAddToToday:t,onRunStart:n,moveNotebookTargets:r,onMoveNotebook:i,onToggleSubscribe:a,onCloneRemote:o,onPublishFeed:s,onTogglePublicNotebook:c,onEditNotebook:l,onDeleteNotebook:u}){let d=lt(),[f,m]=(0,W.useState)(!1),h=rH(e),g=nH(e),_=iH(e)&&!!t,v=P8(e)&&!!n,y=e.notebookId??`notebook/journal`,b=r?.filter(e=>e.id!==y)??[],x=!!i&&e.kind===`note`&&(e.editable??!0)&&b.length>0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 focus-within:opacity-100 transition-opacity max-sm:basis-full max-sm:justify-end max-sm:pt-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(L8,{title:g?`Details`:`Open`,testId:`action-open`,onClick:()=>d(eH(e)),children:(0,G.jsx)(bt,{className:`size-3.5`})}),(e.kind===`feed`||e.kind===`notebook`)&&e.feedId!==`local`&&e.feedId!==`core`&&a&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>a(e),"data-testid":e.subscribed?`row-unsubscribe-${e.sourceNote}`:`row-subscribe-${e.sourceNote}`,className:`h-7 px-2.5 rounded-lg text-[11px] font-semibold flex items-center gap-1 transition-colors ${e.subscribed?`border border-border text-muted-foreground hover:text-destructive hover:border-destructive/40`:`bg-primary text-primary-foreground hover:bg-primary/90`}`,children:[(0,G.jsx)(Te,{className:`size-3`}),(0,G.jsx)(`span`,{children:e.subscribed?`Unsubscribe`:`Subscribe`})]}),e.kind===`notebook`&&e.feedId===`local`&&c&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>c(e),"data-testid":`row-toggle-public-${e.sourceNotebook}`,className:`h-7 px-2.5 rounded-lg border border-border text-[11px] font-semibold flex items-center gap-1 text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[e.isPublic?(0,G.jsx)(un,{className:`size-3`}):(0,G.jsx)(wn,{className:`size-3`}),(0,G.jsx)(`span`,{children:e.isPublic?`Make Private`:`Make Public`})]}),e.kind===`notebook`&&e.feedId===`local`&&l&&(0,G.jsx)(`button`,{type:`button`,title:`Edit ${e.title}`,"aria-label":`Edit ${e.title}`,onClick:()=>l(e),"data-testid":`notebook-edit-${e.sourceNotebook}`,className:`size-8 max-sm:min-h-11 max-sm:min-w-11 rounded-lg flex items-center justify-center text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors`,children:(0,G.jsx)(me,{className:`size-3.5`})}),e.kind===`notebook`&&e.feedId===`local`&&u&&(f?(0,G.jsx)(`button`,{type:`button`,title:`Notes in this notebook return to the journal`,onClick:()=>{m(!1),u(e)},"data-testid":`notebook-delete-confirm-${e.sourceNotebook}`,className:`h-7 px-2.5 rounded-lg bg-destructive text-destructive-foreground hover:bg-destructive/90 text-[11px] font-semibold flex items-center gap-1 transition-colors`,children:`Confirm delete`}):(0,G.jsx)(`button`,{type:`button`,title:`Delete ${e.title}`,"aria-label":`Delete ${e.title}`,onClick:()=>m(!0),"data-testid":`notebook-delete-${e.sourceNotebook}`,className:`size-8 max-sm:min-h-11 max-sm:min-w-11 rounded-lg flex items-center justify-center text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors`,children:(0,G.jsx)(Dr,{className:`size-3.5`})})),e.kind===`feed`&&e.sourceNote===`local`&&s&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(e),"data-testid":`row-publish-local-feed`,className:`h-7 px-2.5 rounded-lg bg-primary text-primary-foreground hover:bg-primary/90 text-[11px] font-semibold flex items-center gap-1 transition-colors`,children:[(0,G.jsx)(ze,{className:`size-3`}),(0,G.jsx)(`span`,{children:`Publish / Export`})]}),e.isRemotePreview&&o&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(e),"data-testid":`row-clone-remote-${e.id}`,className:`h-7 px-2.5 rounded-lg border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 text-[11px] font-semibold flex items-center gap-1 transition-colors`,children:[(0,G.jsx)(Fe,{className:`size-3`}),(0,G.jsx)(`span`,{children:`Clone`})]}),g&&(0,G.jsx)(L8,{title:`Notebook`,testId:`action-notebook`,onClick:()=>d(g),children:(0,G.jsx)(p,{className:`size-3.5`})}),_&&(0,G.jsx)(L8,{title:`Add to today`,testId:`action-add`,onClick:()=>t?.(e),children:(0,G.jsx)(ut,{className:`size-3.5`})}),v&&(0,G.jsx)(L8,{title:`Run`,testId:`action-run`,onClick:()=>n?.(e),children:(0,G.jsx)(bt,{className:`size-3.5`})}),x&&b.length>0&&(0,G.jsx)(I8,{targets:b,triggerTestId:`action-move`,itemTestIdPrefix:`action-move-`,triggerClassName:`size-8 max-sm:min-h-11 max-sm:min-w-11 rounded-lg flex items-center justify-center text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors`,onMove:t=>i?.(e,t)}),h&&(0,G.jsx)(L8,{title:`Compare`,testId:`action-compare`,onClick:()=>d(h),children:(0,G.jsx)(te,{className:`size-3.5`})})]})}function I8({targets:e,triggerTestId:t,itemTestIdPrefix:n,triggerClassName:r,onMove:i}){return(0,G.jsxs)(YG,{children:[(0,G.jsx)(XG,{asChild:!0,children:(0,G.jsx)(`button`,{type:`button`,title:`Move to notebook`,"data-testid":t,className:r,children:(0,G.jsx)(Vt,{className:`size-3.5`})})}),(0,G.jsxs)(ZG,{align:`end`,children:[(0,G.jsx)($G,{children:`Move to notebook`}),(0,G.jsx)(eK,{}),e.map(e=>(0,G.jsxs)(QG,{"data-testid":`${n}${e.id}`,onClick:()=>i(e.id),children:[(0,G.jsx)(`span`,{className:`w-5 text-center`,children:e.icon}),(0,G.jsx)(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))]})]})}function L8({title:e,testId:t,onClick:n,children:r}){return(0,G.jsx)(`button`,{type:`button`,title:e,onClick:n,"data-testid":t,className:`size-8 max-sm:min-h-11 max-sm:min-w-11 rounded-lg flex items-center justify-center text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors`,children:r})}function Fce({entries:e,level:t,visibleFieldIds:n,onRowClick:r,emptyMessage:i=`No entries to display`,className:a=``,stickyHeaderTop:o}){let s=lt(),c=(0,W.useMemo)(()=>t||(e.length>0?lK(e[0]):`note`),[t,e]),l=(0,W.useMemo)(()=>fK(c),[c]),u=(0,W.useMemo)(()=>{let e=new Set(n??pK(c));return l.filter(t=>e.has(t.id))},[l,n,c]),d=e=>{r?r(e):s(eH(e))},[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(`asc`),g=e=>{f===e?h(e=>e===`asc`?`desc`:`asc`):(p(e),h(`asc`))},_=(0,W.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,G.jsx)(`div`,{className:`w-full py-16 text-center text-sm text-muted-foreground ${a}`,"data-testid":`property-table-empty`,children:i}):(0,G.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,G.jsxs)(`table`,{className:`w-full text-left border-collapse text-xs`,children:[(0,G.jsx)(`thead`,{className:o===void 0?void 0:`sticky z-10`,style:o===void 0?void 0:{top:`${o}px`},children:(0,G.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,G.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,G.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 ${t===`text-right`?`justify-end`:t===`text-center`?`justify-center`:`justify-start`}`,children:[(0,G.jsx)(`span`,{children:e.label}),f===e.id?(0,G.jsx)(`span`,{className:`text-primary font-bold text-xs`,"aria-label":m===`asc`?`sorted ascending`:`sorted descending`,children:m===`asc`?`↑`:`↓`}):(0,G.jsx)(`span`,{className:`opacity-0 group-hover/th:opacity-40 text-muted-foreground text-[10px]`,"aria-hidden":`true`,children:`↕`})]})},e.id)})})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-border/60`,children:_.map(e=>{let t=nH(e),n=eH(e);return(0,G.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,G.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,G.jsx)(ve,{to:bz(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,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`font-medium text-foreground group-hover:text-primary transition-colors`,children:a}),t&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 ml-auto`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(ve,{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,G.jsx)(ve,{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 Ice={note:Rr,effort:ot,result:vn,segment:$t,event:Qt,dashboard:gr,equipment:Er,tag:Jt,feed:p,notebook:br},Lce={note:`Note`,effort:`Effort`,result:`Result`,segment:`Segment`,event:`Event`,dashboard:`Dashboard`,equipment:`Equipment`,tag:`Tag`,feed:`Feed`,notebook:`Notebook`},R8=8;function Rce({entry:e}){let t=e.execution;if(!t)return null;let n=[];return t.elapsedMs!=null&&n.push({label:RV(t.elapsedMs)}),t.reps!=null&&n.push({label:`${t.reps} reps`}),t.loadLbs!=null&&n.push({label:`${t.loadLbs} lb`}),t.distanceMeters!=null&&n.push({label:`${(t.distanceMeters/1e3).toFixed(2)} km`}),t.tis!=null&&n.push({label:`TIS Score ${t.tis.toFixed(1)}`,title:`Training Intensity Score`}),n.length===0?null:(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`stream-feed-metrics`,children:n.map(e=>(0,G.jsx)(`span`,{title:e.title,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.label},e.label))})}function zce({entry:e}){let[t,n]=(0,W.useState)(!1),r=e.wodBlock?.content.trim(),i=r?r.split(`
1118
1118
  `):e.excerpt??e.block?.preview??[],a=i.length>R8,o=t||!a?i:i.slice(0,R8);return i.length===0&&!e.detail?null:(0,G.jsxs)(`div`,{className:`mt-1.5`,"data-testid":`stream-feed-preview`,children:[i.length>0&&(0,G.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(`
1119
1119
  `)}),i.length===0&&e.detail&&(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e.detail}),a&&(0,G.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-R8} lines)`})]})}function Bce({groups:e,batch:t,onRunEntry:n,onSendToPlayground:r,onAddToToday:i,moveNotebookTargets:a,onMoveNotebook:o,onEditNotebook:s,onDeleteNotebook:c,stickyOffset:l}){let[u,d]=(0,W.useState)(null);return(0,G.jsxs)(`div`,{className:`flex-1 divide-y divide-border/40`,"data-testid":`stream-feed`,children:[e.map(e=>(0,G.jsxs)(`section`,{id:e.id,"data-testid":`stream-feed-group-${e.key}`,children:[(0,G.jsx)(RG,{top:l,icon:(0,G.jsx)(jt,{className:`size-3 shrink-0 text-muted-foreground`}),label:e.label,badge:e.isToday?(0,G.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,G.jsx)(`div`,{className:`divide-y divide-border/30`,children:e.entries.map(e=>{let t=e.kind===`note`?e.sourceNotebook:void 0,l=!!t&&t!==`journal`&&t!==`playground`&&t!==`guides`,f=t===`playground`?Or:t===`guides`?br:l?p:Ice[e.kind],m=t===`playground`?`Playground`:t===`guides`?`Guide`:l?`Notebook`:Lce[e.kind],h=eH(e),g=nH(e),_=!tH(e)&&e.kind===`note`,v=iH(e)&&!!i,y=e.notebookId??`notebook/journal`,b=a?.filter(e=>e.id!==y)??[],x=!!o&&e.kind===`note`&&(e.editable??!0)&&b.length>0;return(0,G.jsx)(`article`,{"data-testid":`stream-feed-item`,className:`px-6 py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`flex-shrink-0 size-9 rounded-xl bg-primary/10 flex items-center justify-center`,children:(0,G.jsx)(f,{className:`size-4 text-primary`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-bold text-foreground min-w-0 basis-full sm:basis-auto sm:truncate`,children:(0,G.jsx)(ve,{to:h,className:`hover:text-primary transition-colors`,children:e.title})}),(0,G.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.subtitle&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:e.subtitle})]}),(0,G.jsx)(zce,{entry:e}),(0,G.jsx)(Rce,{entry:e}),(0,G.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(ve,{to:h,"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:g?`Details`:`Open`}),g&&(0,G.jsxs)(ve,{to:g,"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,G.jsx)(p,{className:`size-3`}),`Feed`]}),P8(e)&&(0,G.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,G.jsx)(bt,{className:`size-3`}),`Run`]}),_&&r&&(0,G.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,G.jsx)(or,{className:`size-3`}),`Playground`]}),v&&(0,G.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,G.jsx)(ut,{className:`size-3`}),`Add`]}),x&&(0,G.jsx)(I8,{targets:b,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.kind===`notebook`&&e.feedId===`local`&&s&&(0,G.jsxs)(`button`,{type:`button`,"aria-label":`Edit ${e.title}`,onClick:()=>s(e),"data-testid":`notebook-edit-${e.sourceNotebook}`,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,G.jsx)(me,{className:`size-3`}),`Edit`]}),e.kind===`notebook`&&e.feedId===`local`&&c&&(u===e.id?(0,G.jsx)(`button`,{type:`button`,title:`Notes in this notebook return to the journal`,onClick:()=>{d(null),c(e)},"data-testid":`notebook-delete-confirm-${e.sourceNotebook}`,className:`inline-flex min-h-[44px] items-center gap-1.5 rounded-full bg-destructive text-destructive-foreground px-3 text-[10px] font-black uppercase tracking-widest hover:bg-destructive/90 transition-colors`,children:`Confirm delete`}):(0,G.jsxs)(`button`,{type:`button`,"aria-label":`Delete ${e.title}`,onClick:()=>d(e.id),"data-testid":`notebook-delete-${e.sourceNotebook}`,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-destructive hover:border-destructive/50 transition-colors`,children:[(0,G.jsx)(Dr,{className:`size-3`}),`Delete`]}))]})]})]})},e.id)})})]},e.id)),t.hasMore&&(0,G.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 z8(e){return Iz(e)}function B8(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,(n??1)-1,r??1)}function V8(e){let t=new Map,n=[];for(let r of e){let e=r.date;if(!e){n.push(r);continue}let i=t.get(e);i?i.push(r):t.set(e,[r])}return{byDay:t,undated:n}}function H8(e){return(e.getDay()+6)%7}function U8(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function W8(e,t,n,r){let i=z8(e),a=e.getDay();return{key:i,date:e,dayOfMonth:e.getDate(),inMonth:t,isToday:i===r,isWeekend:a===0||a===6,entries:n.byDay.get(i)??[]}}function Vce(e,t,n=z8(new Date)){let r=e.getFullYear(),i=e.getMonth(),a=new Date(r,i,1),o=U8(a,-H8(a)),s=[];for(let e=0;e<6;e++){let a=[];for(let s=0;s<7;s++){let c=U8(o,e*7+s);a.push(W8(c,c.getMonth()===i&&c.getFullYear()===r,t,n))}s.push({label:`${X8[a[0].date.getMonth()]} ${a[0].date.getDate()}`,days:a})}return s}function Hce(e,t,n=z8(new Date)){let r=e.getFullYear(),i=e.getMonth(),a=new Date(r,i,1),o=new Date(r,i+1,0),s=U8(a,-H8(a)),c=U8(o,6-H8(o)),l=[];for(let e=s;e<=c;e=U8(e,7)){let a=[];for(let o=0;o<7;o++){let s=U8(e,o);a.push(W8(s,s.getMonth()===i&&s.getFullYear()===r,t,n))}l.push({label:`${X8[a[0].date.getMonth()]} ${a[0].date.getDate()}`,days:a})}return l}function Uce(e,t,n=z8(new Date)){let r=e.getFullYear(),i=e.getMonth();return[...t.byDay.keys()].filter(e=>{let t=B8(e);return t.getFullYear()===r&&t.getMonth()===i}).sort().map(e=>W8(B8(e),!0,t,n))}function Wce(e){return`${Kce[e.getMonth()]} ${e.getFullYear()}`}function G8(e){return X8[e.getMonth()]}function K8(e,t){return new Date(e.getFullYear(),e.getMonth()+t,1)}function Gce(e){return e<=0?0:e===1?1:e===2?2:3}function q8(e){let t=e.notebookId;return t?t.replace(/^notebook\//,``):e.sourceNotebook}var J8=[{bar:`bg-rose-500`,chip:`bg-rose-500/12 text-rose-700 dark:text-rose-300`},{bar:`bg-amber-500`,chip:`bg-amber-500/12 text-amber-700 dark:text-amber-300`},{bar:`bg-emerald-500`,chip:`bg-emerald-500/12 text-emerald-700 dark:text-emerald-300`},{bar:`bg-sky-500`,chip:`bg-sky-500/12 text-sky-700 dark:text-sky-300`},{bar:`bg-violet-500`,chip:`bg-violet-500/12 text-violet-700 dark:text-violet-300`},{bar:`bg-cyan-500`,chip:`bg-cyan-500/12 text-cyan-700 dark:text-cyan-300`}];function Y8(e){if(!e)return{bar:`bg-muted-foreground`,chip:`bg-muted text-muted-foreground`};let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return J8[Math.abs(t)%J8.length]}var X8=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Kce=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Z8=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function Q8(e){let[t,n]=(0,W.useState)(()=>e??new Date);return{anchor:t,label:Wce(t),previous:(0,W.useCallback)(()=>n(e=>K8(e,-1)),[]),next:(0,W.useCallback)(()=>n(e=>K8(e,1)),[]),today:(0,W.useCallback)(()=>n(new Date),[])}}function $8({nav:e,meta:t,right:n}){return(0,G.jsx)(`div`,{className:`border-b border-border/60 px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(q,{variant:`ghost`,size:`icon`,onClick:e.previous,"aria-label":`Previous month`,className:`size-11 shrink-0`,children:(0,G.jsx)(V,{className:`size-4`,"aria-hidden":!0})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1 px-1`,children:[(0,G.jsx)(`div`,{className:`truncate text-sm font-bold text-foreground`,children:e.label}),t&&(0,G.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:t})]}),(0,G.jsx)(q,{variant:`ghost`,size:`icon`,onClick:e.next,"aria-label":`Next month`,className:`size-11 shrink-0`,children:(0,G.jsx)(gt,{className:`size-4`,"aria-hidden":!0})}),(0,G.jsx)(q,{variant:`outline`,size:`sm`,onClick:e.today,className:`min-h-11 shrink-0`,children:`Today`}),n]})})}function qce({entry:e}){let t=Y8(q8(e));return(0,G.jsxs)(ve,{to:eH(e),className:`flex min-h-6 items-center gap-1.5 rounded border border-border/60 bg-card px-1.5 py-0.5 text-[11px] text-foreground transition-colors hover:bg-muted/60`,title:`${e.title} — ${q8(e)}`,"data-testid":`calendar-entry-chip`,children:[(0,G.jsx)(`span`,{className:`h-3 w-0.5 shrink-0 rounded-full ${t.bar}`,"aria-hidden":!0}),(0,G.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title||`Untitled`})]})}function e5({entries:e}){return e.length===0?null:(0,G.jsxs)(`div`,{className:`mx-4 mb-6 rounded-lg border border-dashed border-border bg-muted/30 p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(jt,{className:`size-3.5 text-muted-foreground`,"aria-hidden":!0}),(0,G.jsxs)(`h3`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[`Undated · `,e.length]})]}),(0,G.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:`The calendar has no day for these. Give them one to place them.`}),(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:e.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex min-h-6 items-center gap-1.5 rounded border border-border/60 bg-card px-1.5 py-0.5 text-[11px]`,children:[(0,G.jsx)(`span`,{className:`h-3 w-0.5 shrink-0 rounded-full ${Y8(q8(e)).bar}`,"aria-hidden":!0}),(0,G.jsx)(`span`,{className:`max-w-[16rem] truncate`,children:e.title||`Untitled`})]},e.id))})]})}function t5(e,t){let n=e===1?`entry`:`entries`;return t?`${e} ${t} ${n}`:`${e} ${n}`}function Jce({day:e,top:t,onCreateOnDay:n}){let r=Z8[(e.date.getDay()+6)%7];return(0,G.jsxs)(`div`,{id:`calendar-day-${e.key}`,style:{top:`${t}px`},className:`sticky z-10 flex items-center gap-3 border-y border-border/60 bg-card/95 px-4 py-1.5 backdrop-blur`,"data-testid":`calendar-agenda-day`,children:[(0,G.jsxs)(`div`,{className:`flex w-9 shrink-0 flex-col items-center leading-none`,children:[(0,G.jsx)(`span`,{className:`text-[9px] font-bold uppercase tracking-[0.1em] text-muted-foreground`,children:r}),(0,G.jsx)(`span`,{className:`text-xl font-extrabold tracking-tight ${e.isToday?`text-primary`:`text-foreground`}`,children:e.dayOfMonth})]}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1 text-[11px] text-muted-foreground`,children:[G8(e.date),` `,e.date.getFullYear()]}),e.isToday&&(0,G.jsx)(`span`,{className:`rounded-full bg-primary/10 px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-wider text-primary`,children:`Today`}),(0,G.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground`,children:t5(e.entries.length)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>n(e.key),className:`grid size-7 shrink-0 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-primary`,"aria-label":`Add an entry on ${G8(e.date)} ${e.dayOfMonth}`,title:`Add an entry on this day`,"data-testid":`calendar-agenda-add-button`,children:(0,G.jsx)(ut,{className:`size-3.5`,"aria-hidden":!0})})]})}function Yce({days:e}){let t=e.filter(e=>e.inMonth),n=t[0]?.date.getMonth()??0,r=t[0]?.date.getFullYear()??new Date().getFullYear(),i=new Date(r,n+1,0).getDate(),a=new Map(t.map(e=>[e.dayOfMonth,e])),o=[];for(let e=1;e<=i;e++){let t=a.get(e),i=Gce(t?.entries.length??0),s=i===0?`bg-muted`:i===1?`bg-primary/25`:i===2?`bg-primary/50`:`bg-primary`,c=t5(t?.entries.length??0),l=`${e} ${G8(new Date(r,n,e))} — ${c}`;o.push((0,G.jsx)(`button`,{type:`button`,onClick:()=>document.getElementById(`calendar-day-${t?.key}`)?.scrollIntoView({block:`start`}),disabled:!t,title:l,"aria-label":l,className:`h-6 flex-1 rounded-sm ${s} ${t?`cursor-pointer`:`cursor-default`}`},e))}return(0,G.jsxs)(`div`,{className:`hidden items-center gap-3 border-b border-border/60 px-4 py-2 lg:flex`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Load`}),(0,G.jsx)(`div`,{className:`flex flex-1 gap-0.5`,children:o}),(0,G.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:[`1 → `,i]})]})}function Xce({entries:e,stickyOffset:t,visibleFieldIds:n,onAddToToday:r,onRunStart:i,moveNotebookTargets:a,onMoveNotebook:o,onCreateOnDay:s}){let c=Q8(),l=(0,W.useMemo)(()=>V8(e),[e]),u=(0,W.useMemo)(()=>Uce(c.anchor,l),[c.anchor,l]),d=(0,W.useMemo)(()=>Vce(c.anchor,l),[c.anchor,l]),f=`${c.anchor.getFullYear()}-${String(c.anchor.getMonth()+1).padStart(2,`0`)}`,p=e.filter(e=>e.date?.startsWith(f)),m=e.filter(e=>e.date).length;return e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col bg-background`,"data-testid":`calendar-agenda-view`,children:[(0,G.jsx)($8,{nav:c}),(0,G.jsx)(`p`,{className:`px-4 py-16 text-center text-xs text-muted-foreground`,children:`No entries match your search.`})]}):(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col bg-background`,"data-testid":`calendar-agenda-view`,children:[(0,G.jsx)($8,{nav:c,meta:`${p.length} of ${t5(m,`dated`)} in ${c.label}`}),(0,G.jsx)(Yce,{days:d.flatMap(e=>e.days)}),u.length===0?(0,G.jsxs)(`p`,{className:`px-4 py-16 text-center text-xs text-muted-foreground`,children:[`Nothing dated in `,c.label,`. Step to another month, or widen the date window.`]}):(0,G.jsx)(`div`,{className:`flex-1 pb-6`,children:u.map(e=>(0,G.jsxs)(`section`,{children:[(0,G.jsx)(Jce,{day:e,top:t,onCreateOnDay:s??(()=>{})}),(0,G.jsx)(`div`,{className:`divide-y divide-border/30`,children:e.entries.map(t=>(0,G.jsx)(F8,{entry:t,visibleFieldIds:n,tone:e.isToday?`primary`:`secondary`,onAddToToday:r,onRunStart:i,moveNotebookTargets:a,onMoveNotebook:o},t.id))})]},e.key))}),(0,G.jsx)(e5,{entries:l.undated})]})}var Zce=3;function Qce({day:e,onCreateOnDay:t}){let n=e.entries.slice(0,Zce),r=e.entries.length-n.length,i=`${G8(e.date)} ${e.dayOfMonth}`;return(0,G.jsxs)(`div`,{className:`group/cell relative flex min-h-[5.5rem] min-w-0 flex-col gap-1 border-l border-border/50 p-1.5 first:border-l-0 ${e.inMonth?``:`bg-muted/40`}`,"data-testid":`calendar-planner-cell`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>t(e.key),className:`absolute inset-0 h-full w-full cursor-pointer`,"aria-label":`Add an entry on ${i}`,"data-testid":`calendar-planner-cell-add`}),(0,G.jsxs)(`div`,{className:`pointer-events-none relative flex items-baseline gap-1`,children:[(0,G.jsx)(`span`,{className:`font-mono text-[11px] font-bold ${e.isToday?`text-primary`:e.inMonth?`text-foreground`:`text-muted-foreground/50`}`,children:e.dayOfMonth}),e.isToday&&(0,G.jsx)(`span`,{className:`rounded-full bg-primary/10 px-1 text-[8px] font-bold uppercase tracking-wider text-primary`,children:`Today`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>t(e.key),className:`pointer-events-auto ml-auto grid size-5 place-items-center rounded text-muted-foreground/60 transition-colors hover:bg-muted hover:text-primary`,"aria-label":`Add an entry on ${i}`,title:`Add an entry on this day`,"data-testid":`calendar-planner-add-button`,children:(0,G.jsx)(ut,{className:`size-3`,"aria-hidden":!0})}),e.entries.length>0&&(0,G.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.entries.length})]}),(0,G.jsxs)(`div`,{className:`pointer-events-none relative flex flex-col gap-1`,children:[n.map(e=>(0,G.jsx)(`span`,{className:`pointer-events-auto`,children:(0,G.jsx)(qce,{entry:e})},e.id)),r>0&&(0,G.jsxs)(`span`,{className:`px-1 text-[10px] font-medium text-muted-foreground`,children:[`+`,r,` more`]})]})]})}function $ce({week:e,onCreateOnDay:t}){return(0,G.jsxs)(`div`,{className:`grid grid-cols-[3.5rem_repeat(7,minmax(0,1fr))] border-t border-border/60`,"data-testid":`calendar-planner-week`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col justify-start gap-0.5 p-1.5`,children:[(0,G.jsx)(`span`,{className:`font-mono text-[10px] font-bold text-muted-foreground`,children:e.label}),(0,G.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground/70`,children:e.days.reduce((e,t)=>e+t.entries.length,0)})]}),e.days.map(e=>(0,G.jsx)(Qce,{day:e,onCreateOnDay:t},e.key))]})}function ele({weeks:e,visibleFieldIds:t,onAddToToday:n,onRunStart:r,moveNotebookTargets:i,onMoveNotebook:a,onCreateOnDay:o}){let s=e.filter(e=>e.days.some(e=>e.entries.length>0));return s.length===0?(0,G.jsx)(`p`,{className:`px-4 py-16 text-center text-xs text-muted-foreground`,children:`No dated entries in this month.`}):(0,G.jsx)(`div`,{className:`space-y-3 p-3`,children:s.map(e=>(0,G.jsxs)(`section`,{className:`overflow-hidden rounded-lg border border-border/60 bg-card`,"data-testid":`calendar-planner-week-card`,children:[(0,G.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-border/60 bg-muted/30 px-3 py-1.5`,children:[(0,G.jsx)(jt,{className:`size-3.5 text-muted-foreground`,"aria-hidden":!0}),(0,G.jsxs)(`span`,{className:`font-mono text-[11px] font-bold text-foreground`,children:[`Week of `,e.label]}),(0,G.jsxs)(`span`,{className:`ml-auto font-mono text-[10px] text-muted-foreground`,children:[e.days.reduce((e,t)=>e+t.entries.length,0),` `,e.days.reduce((e,t)=>e+t.entries.length,0)===1?`entry`:`entries`]})]}),e.days.filter(e=>e.entries.length>0).map(e=>(0,G.jsxs)(`div`,{className:`border-b border-border/40 last:border-b-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pt-2`,children:[(0,G.jsxs)(`span`,{className:`font-mono text-[11px] font-bold ${e.isToday?`text-primary`:`text-muted-foreground`}`,children:[Z8[(e.date.getDay()+6)%7],` `,e.dayOfMonth]}),e.isToday&&(0,G.jsx)(`span`,{className:`rounded-full bg-primary/10 px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-wider text-primary`,children:`Today`}),(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5`,children:[e.entries.slice(0,4).map(e=>(0,G.jsx)(`span`,{className:`size-1.5 rounded-full ${Y8(q8(e)).bar}`,title:e.title,"aria-hidden":!0},e.id)),(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(e.key),className:`grid size-7 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-primary`,"aria-label":`Add an entry on ${Z8[(e.date.getDay()+6)%7]} ${e.dayOfMonth}`,title:`Add an entry on this day`,"data-testid":`calendar-planner-add-button`,children:(0,G.jsx)(ut,{className:`size-3.5`,"aria-hidden":!0})})]})]}),(0,G.jsx)(`div`,{className:`divide-y divide-border/30`,children:e.entries.map(o=>(0,G.jsx)(F8,{entry:o,visibleFieldIds:t,tone:e.isToday?`primary`:`secondary`,onAddToToday:n,onRunStart:r,moveNotebookTargets:i,onMoveNotebook:a},o.id))})]},e.key))]},e.label))})}function tle({entries:e,visibleFieldIds:t,onAddToToday:n,onRunStart:r,moveNotebookTargets:i,onMoveNotebook:a,onCreateOnDay:o}){let s=OK(),c=Q8(),l=(0,W.useMemo)(()=>V8(e),[e]),u=(0,W.useMemo)(()=>Hce(c.anchor,l),[c.anchor,l]),d=`${c.anchor.getFullYear()}-${String(c.anchor.getMonth()+1).padStart(2,`0`)}`,f=e.filter(e=>e.date?.startsWith(d)).length;return e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col bg-background`,"data-testid":`calendar-planner-view`,children:[(0,G.jsx)($8,{nav:c}),(0,G.jsx)(`p`,{className:`px-4 py-16 text-center text-xs text-muted-foreground`,children:`No entries match your search.`})]}):(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col bg-background`,"data-testid":`calendar-planner-view`,children:[(0,G.jsx)($8,{nav:c,meta:`${f} dated ${f===1?`entry`:`entries`} in ${c.label}`}),s?(0,G.jsx)(ele,{weeks:u,visibleFieldIds:t,onAddToToday:n,onRunStart:r,moveNotebookTargets:i,onMoveNotebook:a,onCreateOnDay:o??(()=>{})}):(0,G.jsx)(`div`,{className:`flex-1 overflow-x-auto pb-6`,children:(0,G.jsxs)(`div`,{className:`min-w-[52rem]`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-[3.5rem_repeat(7,minmax(0,1fr))] bg-muted/40`,children:[(0,G.jsx)(`div`,{}),Z8.map(e=>(0,G.jsx)(`div`,{className:`border-l border-border/50 px-1.5 py-1 text-[10px] font-bold uppercase tracking-[0.1em] text-muted-foreground first:border-l-0`,children:e},e))]}),u.map(e=>(0,G.jsx)($ce,{week:e,onCreateOnDay:o??(()=>{})},e.label))]})}),(0,G.jsx)(e5,{entries:l.undated})]})}function nle(e,t,n){return{journalDate:n,title:e.title,rawContent:t,sourceId:e.sourceId,type:`journal`}}var rle=/(?:^|\n)```(query[^\n]*)\n([\s\S]*?)\n```|\[([^\]]*)\]\((:[^)]*)\)!/g;function n5(e){let t=e.trim();return DB((()=>{try{return decodeURIComponent(t)}catch{return t}})())}function ile(e){let t=n5(e);return t.startsWith(`:`)&&!Y(t).error}function ale(e){let t=[],n=0;for(let r of e.matchAll(rle)){let i=r[0],a=i.startsWith(`
@@ -1158,4 +1158,4 @@ segmentVolume = reps * resistance (library) when has(reps) and has(resistance)
1158
1158
  `),[i,a]=(0,W.useState)(e),[o,s]=(0,W.useState)([]),[c,l]=(0,W.useState)(),u=(0,W.useMemo)(()=>c9(n,i),[n,i]),d=Lfe(u.defs,n),f=u.diagnostics.every(e=>e.severity!==`error`)&&u.defs.length>0,p=async()=>{s(await j5())};(0,W.useEffect)(()=>{p()},[]),(0,W.useEffect)(()=>{t&&(async()=>{let e=(await j5()).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 Gle({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 Kle(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,G.jsxs)(`div`,{className:`space-y-3`,"data-testid":`calc-authoring-panel`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Scope`}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:Ife.map(e=>(0,G.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,G.jsx)(`div`,{className:`ml-auto flex gap-2`,children:(0,G.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,G.jsx)(bfe,{value:n,onChange:r,scope:i,autoFocus:!0}),(0,G.jsx)(xfe,{analysis:u}),(0,G.jsx)(Ffe,{scope:i,analysis:u}),c&&(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:c}),o.length>0&&(0,G.jsxs)(`div`,{className:`mt-2`,children:[(0,G.jsx)(`div`,{className:`mb-1 text-[11px] uppercase tracking-wide text-muted-foreground`,children:`Saved user calcs`}),(0,G.jsx)(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,children:o.map(e=>(0,G.jsxs)(`li`,{className:`flex items-center justify-between px-3 py-2 text-sm`,children:[(0,G.jsx)(`button`,{onClick:()=>g(e),className:`text-left font-mono text-purple-300 dark:text-purple-400 hover:underline`,children:e.id}),(0,G.jsx)(`button`,{onClick:()=>h(e.id),className:`text-xs text-muted-foreground hover:text-destructive`,children:`delete`})]},e.id))})]})]})}var zfe=new eP;function Bfe(){let e=lt(),[t,n]=(0,W.useState)(!1),[r,i]=(0,W.useState)(null),a=(0,W.useRef)(null),o=async r=>{if(!(!r||t)){n(!0),i(null);try{let t=await WI(r,zfe);Z({title:`Imported ${t.imported} note(s), ${t.sessionsImported??0} session(s)`,description:t.errors.length>0?t.errors.slice(0,2).join(`; `):`Import complete.`}),e(Q.home)}catch(e){i(e instanceof Error?e.message:`That file is not a valid portable bundle (.zip).`)}finally{n(!1)}}};return(0,G.jsxs)(`main`,{"data-agent-status":`ready`,"aria-busy":t,"data-testid":`load-zip-intake`,className:`w-full max-w-xl min-w-0 mx-auto px-4 py-10 sm:px-6 flex flex-col gap-4 overflow-x-hidden`,children:[(0,G.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Import Workout Bundle`}),(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`A portable bundle is the `,(0,G.jsx)(`code`,{className:`font-mono`,children:`.zip`}),` (or`,` `,(0,G.jsx)(`code`,{className:`font-mono`,children:`.md`}),` / `,(0,G.jsx)(`code`,{className:`font-mono`,children:`.jsonl`}),` /`,` `,(0,G.jsx)(`code`,{className:`font-mono`,children:`.csv`}),`) export from Settings → Data, or a`,` `,(0,G.jsx)(`code`,{className:`font-mono`,children:`wod export`}),` archive. Importing never runs the workout.`]}),(0,G.jsxs)(`div`,{className:`rounded-xl border border-dashed border-border bg-card p-5 flex flex-col items-center gap-3 text-center`,children:[(0,G.jsx)(hr,{className:`size-6 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(`input`,{ref:a,type:`file`,accept:`.zip,.md,.markdown,.jsonl,.csv`,"data-testid":`bundle-file-input`,className:`text-xs text-muted-foreground file:mr-3 file:rounded-md file:border-0 file:bg-primary file:px-3 file:py-1.5 file:text-xs file:font-semibold file:text-primary-foreground hover:file:opacity-90 max-w-full`,"aria-label":`Portable bundle file`,disabled:t,onChange:e=>{o(e.target.files?.[0]),e.target.value=``}}),r&&(0,G.jsxs)(`div`,{role:`alert`,"data-testid":`bundle-import-error`,className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:[(0,G.jsx)(Jr,{className:`size-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:r})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[(0,G.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>e(Sz(`data`)),children:`Storage settings`}),(0,G.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>e(`/`),children:`Back to Home`})]})]})}function Vfe(){let[e]=ie(`zip`),[t]=ie(`z`),n=z(),[r]=(0,W.useState)(()=>{let e=new URLSearchParams(n.search||window.location.search);return!!(e.get(`zip`)||e.get(`z`))}),i=new URLSearchParams(n.search);return e||t||i.get(`zip`)||i.get(`z`)||r?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}):(0,G.jsx)(`div`,{className:`flex-1 flex items-start justify-center`,children:(0,G.jsx)(Bfe,{})})}async function C9(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 w9(e={}){let{decodeZip:t=C9,getTodayDateKey:n=Lz,isDateInPast:r=Rz,journalNotes:i=Uz,toast:a=Z}=e,o=lt(),s=z(),{date:c}=yt(),[l]=ie(`zip`),[u,d]=(0,W.useState)({state:`loading`});return(0,W.useEffect)(()=>{if(!(s.pathname===`/load/journal`||s.pathname.startsWith(`/load/journal/`)))return;if(!l){d({state:`missing-zip`});return}let e=!1,u=async()=>{try{d({state:`loading`});let i;try{i=await t(l)}catch(e){console.error(`Failed to decode zip:`,e),d({state:`error`,error:`Failed to decode the journal entry`,onRetry:()=>{u()}}),a({title:`Error`,description:`Failed to decode the journal entry. Please check the link.`,variant:`destructive`});return}if(e)return;let s;if(c){let e=zz(c);if(!e){d({state:`error`,error:`Invalid date format`}),a({title:`Error`,description:`Invalid date format. Expected YYYY-MM-DD.`,variant:`destructive`}),o(Q.journal,{replace:!0});return}s=e.dateKey}else s=n();if(e)return;if(r(s)){d({state:`pending-confirmation`,content:i,dateKey:s,onConfirmBackdate:async()=>{e||await f(i,s)}});return}await f(i,s)}catch(t){console.error(`Unexpected error in journal zip processor:`,t),e||(d({state:`error`,error:`An unexpected error occurred`,onRetry:()=>{u()}}),a({title:`Error`,description:`An unexpected error occurred.`,variant:`destructive`}))}},f=async(t,n)=>{if(!e)try{d({state:`creating`});let r=await i.create({journalDate:n,title:n,rawContent:t});e||(o(rz(r.id),{replace:!0}),d({state:`success`,content:t,dateKey:n}))}catch(r){console.error(`Failed to create journal entry:`,r),e||(d({state:`error`,error:`Failed to create journal entry`,onRetry:()=>{f(t,n)}}),a({title:`Error`,description:`Failed to create journal entry.`,variant:`destructive`}))}};return u(),()=>{e=!0}},[l,c,o,t,n,r,i,a]),u}var Hfe=({selectedDate:e,onImportToday:t,onDateSelect:n,entryDates:r,isLoading:i=!1,className:a})=>{let[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(!1),{triggerRef:u,align:d,recompute:f}=ade(`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?GS(e):`Date`,_=i||c;return(0,G.jsxs)(`div`,{className:K(`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,G.jsxs)(`button`,{type:`button`,title:`Import to today's journal`,onClick:p,disabled:_,className:K(`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,G.jsx)(`span`,{className:`inline-block animate-spin`,children:`⏳`}):(0,G.jsx)(be,{className:`h-4 w-4 shrink-0`}),(0,G.jsx)(`span`,{children:`Import Today`})]}),(0,G.jsx)(`div`,{className:`w-px bg-border/60 self-stretch`}),(0,G.jsxs)(YG,{open:o,onOpenChange:h,children:[(0,G.jsx)(XG,{asChild:!0,children:(0,G.jsxs)(`button`,{ref:e=>{u.current=e},type:`button`,title:`Select a date to plan for the future`,className:K(`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,G.jsx)(It,{className:`h-4 w-4 shrink-0`}),e&&(0,G.jsx)(`span`,{className:`leading-none text-xs`,children:g})]})}),(0,G.jsx)(ZG,{align:d,className:`p-0 w-auto`,children:(0,G.jsx)(l6,{selectedDate:e||null,onDateSelect:m,entryDates:r})})]})]})},Ufe=({dateKey:e,onConfirm:t,onCancel:n,isLoading:r=!1})=>{let[i,a]=W.useState(!1),o=WS(new Date(`${e}T00:00:00`));return(0,G.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,G.jsx)(`div`,{className:`absolute inset-0 bg-black/50 animate-in fade-in`}),(0,G.jsx)(`div`,{className:`relative z-10 w-full max-w-sm mx-auto px-4 animate-in zoom-in-95 fade-in`,children:(0,G.jsxs)(`div`,{className:`bg-background rounded-lg border border-border shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-border`,children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold`,children:`Backdate Journal Entry`}),(0,G.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,G.jsx)(Bn,{className:`h-4 w-4`})})]}),(0,G.jsxs)(`div`,{className:`px-6 py-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The date you selected is in the past.`}),(0,G.jsxs)(`p`,{className:`text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Import to: `}),(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:o})]}),(0,G.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,G.jsxs)(`div`,{className:`px-6 py-4 border-t border-border flex gap-2 justify-end`,children:[(0,G.jsx)(q,{variant:`outline`,onClick:n,disabled:r||i,children:`Cancel`}),(0,G.jsx)(q,{onClick:async()=>{a(!0);try{await t()}finally{a(!1)}},disabled:r||i,className:K(r||i?`opacity-70`:``),children:i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`inline-block animate-spin mr-2`,children:`⏳`}),`Importing...`]}):`Confirm & Import`})]})]})})]})},Wfe=new eP,Gfe={h1:({children:e})=>(0,G.jsx)(`h1`,{className:`text-3xl font-bold mt-8 mb-4 first:mt-0 text-foreground`,children:e}),h2:({children:e})=>(0,G.jsx)(`h2`,{className:`text-2xl font-bold mt-6 mb-3 text-foreground`,children:e}),h3:({children:e})=>(0,G.jsx)(`h3`,{className:`text-xl font-semibold mt-5 mb-2 text-foreground`,children:e}),h4:({children:e})=>(0,G.jsx)(`h4`,{className:`text-lg font-semibold mt-4 mb-2 text-foreground`,children:e}),h5:({children:e})=>(0,G.jsx)(`h5`,{className:`text-base font-semibold mt-3 mb-1 text-foreground`,children:e}),h6:({children:e})=>(0,G.jsx)(`h6`,{className:`text-sm font-semibold mt-2 mb-1 text-muted-foreground`,children:e}),p:({children:e})=>(0,G.jsx)(`p`,{className:`text-sm leading-relaxed mb-4 text-muted-foreground`,children:e}),strong:({children:e})=>(0,G.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e}),em:({children:e})=>(0,G.jsx)(`em`,{className:`italic text-muted-foreground`,children:e}),ul:({children:e})=>(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-1 mb-4 text-sm text-muted-foreground`,children:e}),ol:({children:e})=>(0,G.jsx)(`ol`,{className:`list-decimal list-inside space-y-1 mb-4 text-sm text-muted-foreground`,children:e}),li:({children:e})=>(0,G.jsx)(`li`,{className:`ml-2`,children:e}),code:({children:e,className:t})=>t?null:(0,G.jsx)(`code`,{className:`px-1.5 py-0.5 rounded bg-muted text-primary font-mono text-xs`,children:e}),pre:({children:e})=>(0,G.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,G.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,G.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary hover:underline font-medium`,children:t}),table:({children:e})=>(0,G.jsx)(`div`,{className:`my-4 overflow-x-auto rounded border border-border`,children:(0,G.jsx)(`table`,{className:`w-full text-xs`,children:e})}),thead:({children:e})=>(0,G.jsx)(`thead`,{className:`bg-muted/50`,children:e}),tbody:({children:e})=>(0,G.jsx)(`tbody`,{className:`divide-y divide-border/50`,children:e}),tr:({children:e})=>(0,G.jsx)(`tr`,{className:`hover:bg-muted/20 transition-colors`,children:e}),th:({children:e})=>(0,G.jsx)(`th`,{className:`px-3 py-2 text-left font-semibold text-foreground text-xs`,children:e}),td:({children:e})=>(0,G.jsx)(`td`,{className:`px-3 py-2 text-muted-foreground`,children:e}),hr:()=>(0,G.jsx)(`hr`,{className:`my-6 border-border/50`})};function T9(){let e=lt(),t=w9(),[n,r]=(0,W.useState)(!1),[i,a]=(0,W.useState)(null),{state:o,content:s,dateKey:c,error:l,onConfirmBackdate:u,onRetry:d}=t;return(0,G.jsxs)(`main`,{"data-agent-status":o===`loading`?`loading`:`ready`,"aria-busy":o===`loading`,className:`flex flex-col flex-1 min-h-0 bg-background`,children:[(0,G.jsxs)(`div`,{className:`border-b border-border/50 bg-muted/30 px-6 py-4 flex items-center justify-between gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`button`,{type:`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,G.jsx)(eee,{className:`h-5 w-5`})}),(0,G.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Import Journal Entry`})]}),o===`loading`?(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`inline-block animate-spin`,children:`⏳`}),`Preparing preview...`]}):o===`error`?(0,G.jsx)(q,{variant:`outline`,size:`sm`,onClick:d,children:`Retry`}):o===`pending-confirmation`||o===`creating`||o===`missing-zip`?null:(0,G.jsx)(Hfe,{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:!1})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-6`,children:[o===`missing-zip`&&(0,G.jsx)(Kfe,{}),o===`loading`&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,G.jsx)(`div`,{className:`animate-spin`,children:`⏳`}),(0,G.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Loading preview...`})]}),o===`error`&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,G.jsx)(`div`,{className:`bg-destructive/10 border border-destructive/50 rounded-lg p-4 max-w-md`,children:(0,G.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,G.jsx)(Jr,{className:`h-5 w-5 text-destructive mt-0.5 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Error Loading Preview`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:l||`Failed to decode the zip content`})]})]})}),(0,G.jsx)(q,{onClick:d,variant:`outline`,children:`Try Again`})]}),o===`pending-confirmation`&&(0,G.jsx)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-foreground mb-2`,children:`Backdate Confirmation Required`}),(0,G.jsx)(`p`,{className:`text-muted-foreground text-sm mb-4`,children:`This date is in the past. Please confirm to proceed.`})]})}),o===`creating`&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,G.jsx)(`div`,{className:`animate-spin`,children:`⏳`}),(0,G.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Creating journal entry...`})]}),o===`success`&&(0,G.jsx)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-foreground mb-2`,children:`✓ Entry Created`}),(0,G.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Redirecting...`})]})}),o===`loading`||o===`error`||o===`pending-confirmation`||o===`creating`||o===`success`?null:s?(0,G.jsx)(`article`,{className:`prose prose-sm max-w-2xl mx-auto`,children:(0,G.jsx)(lr,{remarkPlugins:[Wn],components:Gfe,children:s})}):null]}),n&&c&&(0,G.jsx)(Ufe,{dateKey:c,onConfirm:async()=>{u&&(r(!1),await u())},onCancel:()=>r(!1),isLoading:o===`creating`})]})}function Kfe(){let e=lt(),[t,n]=(0,W.useState)(!1),[r,i]=(0,W.useState)(null),a=async r=>{if(!(!r||t)){n(!0),i(null);try{let t=await WI(r,Wfe);Z({title:`Imported ${t.imported} note(s)`,description:t.errors.length>0?t.errors.slice(0,2).join(`; `):`Open the entry from your journal.`}),e(Q.journal)}catch(e){i(e instanceof Error?e.message:`That file is not a valid portable bundle (.zip).`)}finally{n(!1)}}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-4 max-w-md min-w-0 mx-auto text-center`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:`This import link is missing its bundle`}),(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The journal import link carries a compressed bundle in its`,` `,(0,G.jsx)(`code`,{className:`font-mono`,children:`?zip=`}),` parameter. Re-open the original link, or import a portable bundle file directly — entries land in your journal.`]}),(0,G.jsx)(`input`,{type:`file`,accept:`.zip,.md,.markdown,.jsonl,.csv`,"data-testid":`journal-zip-upload`,"aria-label":`Journal bundle file`,disabled:t,className:`text-xs text-muted-foreground file:mr-3 file:rounded-md file:border-0 file:bg-primary file:px-3 file:py-1.5 file:text-xs file:font-semibold file:text-primary-foreground hover:file:opacity-90 max-w-full`,onChange:e=>{a(e.target.files?.[0]),e.target.value=``}}),r&&(0,G.jsxs)(`div`,{role:`alert`,"data-testid":`journal-zip-error`,className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:[(0,G.jsx)(Jr,{className:`size-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:r})]}),(0,G.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>e(Q.journal),children:`Back to Journal`})]})}function qfe(e){if(!e)return null;let t=e.trim();if(!t)return null;let n=vP(t);if(n&&n.id!==`core`)return n;let r=oP(t);return r?SP().find(e=>oP(e.url)===r)??null:null}function Jfe(){let e=z(),t=lt(),n=(0,W.useMemo)(()=>new URLSearchParams(e.search),[e.search]),r=n.get(`source`)??n.get(`feed`),[i,a]=(0,W.useState)(()=>r??``),[o,s]=(0,W.useState)(()=>r),[c,l]=(0,W.useState)(null),u=(0,W.useMemo)(()=>qfe(o),[o]),[d,f]=(0,W.useState)(()=>u?bI(u.id):!1),m=(0,W.useSyncExternalStore)(vI,()=>SP().map(e=>`${e.id}:${pI(e.id)?`1`:`0`}`).join(`,`)),h=(0,W.useMemo)(()=>SP().filter(e=>!pI(e.id)),[m]),g=(0,W.useCallback)(async(e,n)=>{if(c===null){l(e.id);try{if(mI(e.id,!0),xI(e.id,n),await ML(e.id,{force:!0})===`error`){Z({title:`${e.label} sync failed`,description:`Check your connection and try again.`,variant:`destructive`});return}t(`${Q.notebooks}?q=:notebook{feed:${e.id}}`)}finally{l(null)}}},[c,t]);return(0,G.jsxs)(`div`,{className:`min-h-svh flex flex-col bg-background text-foreground overflow-x-hidden`,children:[(0,G.jsxs)(`nav`,{"aria-label":`Subscribe navigation`,className:`flex flex-wrap items-center justify-between gap-3 border-b border-border px-4 py-3 sm:px-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,G.jsx)(p,{className:`size-4 text-primary`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`WOD Wiki Feeds`})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[(0,G.jsx)(ve,{to:Q.feeds,className:`text-muted-foreground hover:text-foreground transition-colors`,children:`Browse Feeds`}),(0,G.jsx)(ve,{to:Q.notebooks,className:`text-muted-foreground hover:text-foreground transition-colors`,children:`Notebooks`}),(0,G.jsx)(ve,{to:Q.settingsSync,className:`text-muted-foreground hover:text-foreground transition-colors`,children:`Sync Settings`})]})]}),(0,G.jsxs)(`main`,{"data-agent-status":c?`loading`:`ready`,"aria-busy":c!==null,"data-testid":$.FEED_SUBSCRIPTION_INTAKE,className:`w-full max-w-2xl min-w-0 mx-auto flex-1 px-4 py-8 sm:px-6 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`h1`,{className:`text-xl font-bold tracking-tight`,children:`Subscribe to a Feed`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Review and approve external workout catalogs before registering or importing them into your library.`})]}),o&&u?(0,G.jsxs)(`section`,{"data-testid":$.REGISTERED_FEED_INTAKE_CARD,className:`rounded-xl border border-border bg-card p-4 sm:p-5 space-y-4`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider text-primary`,children:`Catalog Feed`}),(0,G.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground break-all`,children:u.url})]}),(0,G.jsx)(`h2`,{className:`text-base font-bold text-foreground`,children:u.label}),u.description&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u.description})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border/60 bg-background/50 p-3 text-xs`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),(0,G.jsx)(`span`,{children:`Auto-sync updates`})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,G.jsxs)(ve,{to:sz(u.id),className:`inline-flex items-center gap-1 text-muted-foreground hover:text-foreground`,children:[(0,G.jsx)(`span`,{children:`Preview feed`}),(0,G.jsx)(Nr,{className:`size-3`,"aria-hidden":`true`})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,G.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>t(Q.feeds),disabled:c!==null,children:`Decline`}),(0,G.jsx)(q,{type:`button`,size:`sm`,"data-testid":$.REGISTERED_FEED_SUBSCRIBE_BTN,onClick:()=>void g(u,d),disabled:c!==null,children:c===u.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Sr,{className:`size-3.5 mr-1.5 animate-spin`}),(0,G.jsx)(`span`,{children:`Subscribing…`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Te,{className:`size-3.5 mr-1.5`}),(0,G.jsx)(`span`,{children:`Subscribe`})]})})]})]}):o?(0,G.jsx)(S8,{feedParam:o,onDismiss:()=>t(Q.notebooks),onRegistered:e=>t(`${Q.notebooks}?q=:notebook{feed:${e}}`),onSubscribed:e=>t(`${Q.notebooks}?q=:notebook{feed:${e}}`)}):null,(0,G.jsxs)(`section`,{className:`rounded-xl border border-border bg-card p-4 sm:p-5 space-y-3`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Add by Feed URL`}),(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=i.trim();t&&s(t)},className:`flex flex-col sm:flex-row gap-2`,children:[(0,G.jsx)(WY,{type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://example.com/seed/`,"aria-label":`Feed directory URL`,className:`flex-1 min-w-0 text-xs`}),(0,G.jsx)(q,{type:`submit`,size:`sm`,disabled:!i.trim()||c!==null,children:`Inspect Feed`})]})]}),!o&&h.length>0&&(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Available Community Feeds`}),(0,G.jsx)(`div`,{className:`divide-y divide-border rounded-xl border border-border bg-card`,children:h.map(e=>(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 p-4`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsx)(ve,{to:sz(e.id),className:`text-sm font-semibold text-foreground hover:underline`,children:e.label})}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground break-words`,children:e.description})]}),(0,G.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`subscribe-catalog-${e.id}`,disabled:c!==null,onClick:()=>void g(e,!1),children:c===e.id?`Subscribing…`:`Subscribe`})]},e.id))})]})]})]})}async function Yfe(e,t,n){let r=await X.getNote(e);if(!r)return;let i=Dj(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${Oj(n)}${r.rawContent.slice(a.to)}`;await new eP().updateRecord(r.id,{rawContent:o,expectedSourceRevision:r.sourceRevision})}function Xfe(){let{runtimeId:e}=yt(),[t]=ee(),n=lt(),r=(0,W.useRef)(e?dF.get(e):void 0),i=t.get(`note`),a=t.get(`block`),[o,s]=(0,W.useState)(()=>!r.current&&!!i),[c,l]=(0,W.useState)(void 0),u=(0,W.useRef)(null);(0,W.useEffect)(()=>{if(r.current||!i||!e){s(!1);return}let t=!1;return s(!0),X.getNote(i).then(e=>{if(t)return;if(!e){s(!1);return}let n=Object.values(e.blocks??{}).filter(e=>e.kind===`wod`),i=a?n.find(e=>e.id===a):n[0];if(!i){s(!1);return}let o=e.rawContent.slice(i.from,i.to),c=fo(o,{registeredWidgets:co})[0],u=c?.scriptBlock?.content??o,d=pl().read(u,i.sport).statements??[],f={block:{id:i.id,contentId:c?.scriptBlock?.contentId,dialect:i.dialect??`time`,sport:i.sport,startLine:0,endLine:Math.max(0,o.split(/\r?\n/).length-1),content:u,statements:d,state:`idle`,version:i.version,createdAt:e.createdAt,widgetIds:{}},noteId:e.id};r.current=f,l(f),s(!1)}).catch(()=>{t||s(!1)}),()=>{t=!0}},[i,a,e]);let d=(0,W.useCallback)(async()=>{let t=r.current;if(!t||!e)throw Error(`The pending workout is unavailable.`);return t.captured?(u.current=t.captured,t.captured.block):(u.current||=t.snapshot?await TF(t.snapshot,t.block,e,t.origin):await EF(t.noteId,t.block,e,t.origin),u.current.block)},[e]);(0,W.useEffect)(()=>{e&&dF.delete(e)},[e]);let f=r.current??c,p=(0,W.useRef)(!1),m=(0,W.useCallback)((t,n)=>!n||!e||!f?Promise.reject(Error(`Run cannot be saved — its session data or runtime id is missing.`)):(p.current=n.completed,qN.record({runBlock:f.block,blockId:f.block.id,noteId:f.noteId,resultId:e,data:n,createdAt:n.endTime||Date.now(),...f.origin?{origin:f.origin}:{}}).then(async()=>{if(n.completed)try{await Yfe(f.noteId,f.block.id,e)}catch{}})),[e,f]),h=(0,W.useCallback)(()=>{if(!f){n(`/`);return}if(p.current){n(uz(e),{replace:!0});return}if(f.returnTo){n(f.returnTo,{replace:!0});return}n(_V(gV(f.noteId)),{replace:!0})},[e,f,n]);if(o)return(0,G.jsx)(`main`,{"data-agent-status":`loading`,"aria-busy":!0,role:`status`,className:`flex-1 flex items-center justify-center text-muted-foreground`,children:`Preparing workout timer…`});if(!f)return(0,G.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,G.jsxs)(`nav`,{"aria-label":`Workout runner navigation`,className:`flex items-center gap-5 px-6 py-3 border-b bg-background`,children:[(0,G.jsx)(`span`,{className:`text-sm font-semibold tracking-tight`,children:`WOD Wiki`}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`run-notfound-nav-home`,onClick:()=>n(`/`),className:`text-sm text-muted-foreground hover:text-foreground transition-colors`,children:`Home`}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`run-notfound-nav-journal`,onClick:()=>n(`/journal`),className:`text-sm text-muted-foreground hover:text-foreground transition-colors`,children:`Journal`}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`run-notfound-nav-notebooks`,onClick:()=>n(`/notebooks`),className:`text-sm text-muted-foreground hover:text-foreground transition-colors`,children:`Notebooks`})]}),(0,G.jsxs)(`main`,{"data-agent-status":`ready`,"aria-busy":!1,className:`flex-1 flex flex-col items-center justify-center gap-6 p-8 text-center`,children:[(0,G.jsx)(m1,{}),(0,G.jsx)(`div`,{className:`flex items-center justify-center w-16 h-16 rounded-full bg-muted`,children:(0,G.jsx)(tt,{className:`w-8 h-8 text-muted-foreground`})}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:`Workout session not found`}),(0,G.jsx)(`p`,{className:`text-muted-foreground max-w-sm`,children:`Runtime not found. Please start the workout from the editor.`})]}),(0,G.jsxs)(`button`,{type:`button`,"data-testid":`run-notfound-go-home`,onClick:()=>n(`/`),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,G.jsx)(an,{className:`w-4 h-4`}),`Go home`]})]})]});let g=u.current?.note.rawContent??f.captured?.note.rawContent??f.snapshot?.rawContent;return(0,G.jsx)(`main`,{"data-agent-status":`ready`,"aria-busy":!1,className:`contents`,children:(0,G.jsx)(u2,{block:f.block,noteContent:g,prepareRun:d,onClose:h,onCompleteWorkout:m,resultId:e,noteId:f.noteId,autoStart:!0})})}var E9=null;async function Zfe(e,t,n){(!E9||E9.attempt!==e)&&(E9={attempt:e,promise:t(IY.content)});try{let t=await E9.promise;return!n()&&E9?.attempt===e&&(E9=null),t}catch(t){throw E9?.attempt===e&&(E9=null),t}}var Qfe=()=>CY(IY.content);function $fe({createPage:e=Qfe}={}){let t=lt(),n=(0,W.useRef)(t);(0,W.useLayoutEffect)(()=>{n.current=t},[t]);let[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(0);return(0,W.useEffect)(()=>{let t=!1;return(async()=>{try{let r=await Zfe(a,e,()=>t);t||n.current(ez(r),{replace:!0})}catch{t||i(!0)}})(),()=>{t=!0}},[a,e]),r?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center gap-3 text-zinc-300 px-4 text-center`,children:[(0,G.jsx)(`p`,{role:`alert`,children:`Unable to create a new playground note.`}),(0,G.jsx)(`button`,{type:`button`,className:`rounded border border-zinc-600 px-3 py-1 text-sm hover:bg-zinc-800`,onClick:()=>{i(!1),o(e=>e+1)},children:`Try again`})]}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`})}function epe(e={}){let{decodeZip:t=C9,intake:n=SY,toast:r=Z}=e,i=lt(),a=z(),[o]=ie(`zip`),[s]=ie(`z`),[c]=ie(`by`),[l]=ie(`src`),u=(0,W.useRef)(null);(0,W.useEffect)(()=>{if(a.pathname!==`/load`&&!(a.pathname===`/`&&s))return;if(s){let e=`${s}:${c??``}`;if(u.current===e)return;u.current=e;let a=!1;return(async()=>{try{let e=await t(s);if(e===null)throw Error(`Invalid workout link`);if(a)return;let r=nse(e,c??void 0);if(await n.ensureEntry(r,{reuseKey:`home`,title:`Home playground`}),a)return;rse({content:r,by:c??void 0})}catch(e){console.error(`Failed to decode zip:`,e),a||r({title:`Could not import workout`,description:`The link was invalid or the workout could not be saved.`,variant:`destructive`})}a||i(`/`,{replace:!0})})(),()=>{a=!0}}if(!o)return;let e=!1,d=l&&l.startsWith(`/`)?l:void 0;return(async()=>{try{let r=await t(o);if(r===null)throw Error(`Invalid workout link`);if(e)return;let a=d?await n.createPage(r,{sourcePath:d}):await n.createPage(r);e||i(ez(a),{replace:!0})}catch(t){console.error(`Failed to decode zip:`,t),e||(r({title:`Could not import workout`,description:`The link was invalid or the workout could not be saved.`,variant:`destructive`}),i(Q.home,{replace:!0}))}})(),()=>{e=!0}},[o,s,c,l,i,a.pathname,t,n,r])}var D9=null,tpe=1,O9=new Set;function k9(){for(let e of O9)e()}function A9(e){return D9&&D9.resolve(!1),new Promise(t=>{let n=tpe++;D9={id:n,request:e,resolve:e=>{D9?.id===n&&(D9=null,k9()),t(e)}},k9()})}async function j9(e,t){let n=t&&typeof t==`object`?t:void 0,r=n?.client?.requestUserInteraction??n?.requestUserInteraction;return typeof r==`function`?r(()=>A9(e)):A9(e)}var npe=()=>{let e=(0,W.useSyncExternalStore)(e=>(O9.add(e),()=>O9.delete(e)),()=>D9,()=>null);return e?(0,G.jsx)(y5,{open:!0,onOpenChange:t=>{t||e.resolve(!1)},children:(0,G.jsxs)(x5,{"data-testid":`agent-confirm-dialog`,children:[(0,G.jsxs)(S5,{children:[(0,G.jsxs)(w5,{className:`flex items-center gap-2 text-destructive`,children:[(0,G.jsx)(Bt,{className:`size-5 shrink-0`,"aria-hidden":`true`}),`Confirm Agent Action`]}),(0,G.jsxs)(T5,{children:[`An AI agent requested a destructive operation (`,(0,G.jsx)(`strong`,{children:e.request.action}),`).`]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/40 p-3 text-xs space-y-1`,children:[(0,G.jsx)(`div`,{className:`font-medium text-foreground`,children:e.request.summary}),(0,G.jsxs)(`div`,{className:`font-mono text-muted-foreground`,children:[`Target: `,(0,G.jsx)(`span`,{"data-testid":`agent-confirm-target`,children:e.request.targetId})]})]}),(0,G.jsxs)(C5,{className:`gap-2 sm:gap-0`,children:[(0,G.jsx)(q,{type:`button`,variant:`outline`,"data-testid":`agent-confirm-cancel`,onClick:()=>e.resolve(!1),children:`Deny`}),(0,G.jsx)(q,{type:`button`,variant:`destructive`,"data-testid":`agent-confirm-approve`,onClick:()=>e.resolve(!0),children:`Approve Action`})]})]})}):null};function rpe(e){return JSON.stringify(e).replace(/<\//g,`<\\/`).replace(/<!--/g,`<\\!--`)}var ipe=()=>{let e=z(),t=Wq(),n=Gq(),r=mq(),i=nq(),a=cq(),o=hV(),s=XK(),c=(0,W.useSyncExternalStore)(CQ,SQ,()=>null),l=r||t===`preparing`||n,u=(0,W.useMemo)(()=>{let r=i&&o&&o.pathname===e.pathname?o:null;return rpe({schemaVersion:`1.0`,hydrated:!0,status:l?`loading`:`ready`,feedReadiness:t,importPending:n,route:{pathname:e.pathname,search:e.search,hash:e.hash},stream:i?{route:i.route,query:i.query,defaultQuery:i.defaultQuery,layout:i.layout,availableLayouts:i.availableLayouts,groupBy:i.groupBy??null,loading:i.loading,totalUnbatchedCount:r?r.entries.length:null,sampleEntries:r?r.entries.slice(0,25).map(e=>({id:e.id,title:e.title,date:e.date??null,notebookId:e.notebookId??null})):[]}:null,explorer:a?{draft:a.draft,submitted:a.submitted,weeks:a.weeks,loading:a.loading,saveReady:a.saveReady}:null,editor:s?{noteId:s.noteId??null,readonly:s.readonly,sourceRevision:s.sourceRevision??null,workoutBlockIds:s.getBlocks().map(e=>e.id)}:null,clock:c})},[l,t,n,e.pathname,e.search,e.hash,i,a,o,s,c]);return(0,G.jsx)(`script`,{id:`agent-view-state`,type:`application/json`,dangerouslySetInnerHTML:{__html:u}})},M9=class extends Error{code=`CONFIRMATION_REQUIRED`;targetId;action;constructor(e,t){super(t??`Destructive action '${e.action}' on '${e.targetId}' requires confirmation (${e.summary}).`),this.name=`AgentConfirmationRequiredError`,this.action=e.action,this.targetId=e.targetId}};function N9(e){return e}async function P9(e,t,n){if(n===void 0||n!==t.targetId){if(e.confirmDestructive){if(await e.confirmDestructive(t))return;throw new M9(t,`User declined or did not confirm '${t.action}' on '${t.targetId}'.`)}throw new M9(t,`Destructive action '${t.action}' requires confirmId="${t.targetId}" (or --yes "${t.targetId}" on CLI).`)}}function F9(){if(typeof crypto<`u`&&typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function ape(e){let t=e.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);for(let e of t.split(/\r?\n/)){let t=e.match(/^#\s+(.+)$/);if(t?.[1]?.trim())return t[1].trim()}}function I9(e,t,n){let r=e.trim();if(!r)return n?`# ${n}\n`:``;let i=e.replace(/^(\s*`{3,})(?:wod|whiteboard)(?=(?::[\w-]+)?\s*$)/gim,`$1time`);if(fo(i,{registeredWidgets:co}).some(e=>e.scriptBlock)||/^---\r?\n/.test(i)||/^#\s+/m.test(i))return i.endsWith(`
1159
1159
  `)?i:`${i}\n`;let a=3;for(let e of i.matchAll(/`+/g))a=Math.max(a,e[0].length+1);let o="`".repeat(a);return`${n?`# ${n}\n\n`:``}${o}time${t?`:${t}`:``}\n${r}\n${o}\n`}function L9(e,t=Date.now()){if(!e||e.trim().toLowerCase()===`today`){let e=new Date(t);return`${e.getUTCFullYear()}-${String(e.getUTCMonth()+1).padStart(2,`0`)}-${String(e.getUTCDate()).padStart(2,`0`)}`}let n=e.trim();if(!/^\d{4}-\d{2}-\d{2}$/.test(n))throw Error(`Invalid date '${e}'; expected YYYY-MM-DD or 'today'.`);return n}function ope(e){let t=(e,t)=>typeof IDBKeyRange<`u`?IDBKeyRange.bound(e,t):{lower:e,upper:t},n=e=>t([e,``],[`${e}\uffff`,`￿`]);return{eventStore:{getEventsByTimeRange:async(n,r)=>e.readonly(`events`).getAllFromIndex(`by-timestamp`,t(n,r)),getEventsByResult:async t=>e.readonly(`events`).getAllFromIndex(`by-result-grain`,n(t)),getEventsForNote:async t=>(await e.readonly(`events`).getAll()).filter(e=>e.noteId===t),getEventsByContent:async t=>e.readonly(`events`).getAllFromIndex(`by-content-grain`,n(t)),scanAll:()=>e.readonly(`events`).getAll(),appendEvents:async t=>{t.length>0&&await e.readwrite(`events`).putMany(t)},finalizeSummaries:async(t,n)=>{await e.transaction([`events`],`readwrite`,async e=>{let r=(await e.readonly(`events`).getAll()).filter(e=>e.resultId===t&&e.grain===`summary`&&e.origin!==`user`);for(let t of r)await e.readwrite(`events`).delete(t.id);n.length>0&&await e.readwrite(`events`).putMany(n)})},deleteEvents:async t=>{for(let n of t)await e.readwrite(`events`).delete(n)}},noteStore:{getAllNotes:()=>e.readonly(`notes`).getAll(),getNotesByIds:async t=>(await e.readonly(`notes`).getMany([...t])).filter(e=>e!==void 0),getNoteIdsForTag:async t=>{let n=new Set;for(let r of await e.readonly(`tags`).getAllFromIndex(`by-label`,t))for(let t of await e.readonly(`note_tags`).getAllFromIndex(`by-tag`,r.id))n.add(t.noteId);return n},getNoteTagLabels:async t=>{let n=await e.readonly(`note_tags`).getAllFromIndex(`by-note`,t);return(await e.readonly(`tags`).getMany(n.map(e=>e.tagId))).flatMap(e=>e?[e.label]:[])},queryDomain:async t=>{if(!e.queryDomain)return;let n=await e.queryDomain({...t,plan:`notes`});return n&&n.plan===`notes`?n:void 0}},blockStore:{getAllBlocks:()=>e.readonly(`block_index`).getAll(),queryDomain:async t=>{if(!e.queryDomain)return;let n=await e.queryDomain({...t,plan:`blocks`});return n&&n.plan===`blocks`?n:void 0}},effortStore:{getAllEfforts:async()=>{let t=await e.readonly(`efforts`).getAll(),n=new Map;for(let e of ru)n.set(e.slug,e);for(let e of t)n.set(e.slug,e);return[...n.values()]}},blockEffortsStore:{getAllFromIndex:(t,n)=>e.readonly(`block_efforts`).getAllFromIndex(t,n)},blockEquipmentStore:{getAllFromIndex:(t,n)=>e.readonly(`block_equipment`).getAllFromIndex(t,n)},tagsStore:{getAllFromIndex:(t,n)=>e.readonly(`tags`).getAllFromIndex(t,n),getAll:()=>e.readonly(`tags`).getAll()},noteTagsStore:{getAllFromIndex:(t,n)=>e.readonly(`note_tags`).getAllFromIndex(t,n)},pageStore:{getNotePages:t=>e.readonly(`page_notes`).getAllFromIndex(`by-note`,t),getPage:t=>e.readonly(`page`).get(t),getAllPages:()=>e.readonly(`page`).getAll(),getAllLinks:()=>e.readonly(`page_notes`).getAll()},relationStore:{getBatches:async t=>{let n=new Map;for(let r of t){let t=await e.readonly(`page_notes`).getAllFromIndex(`by-note`,r),i=await e.readonly(`note_tags`).getAllFromIndex(`by-note`,r),a=await e.readonly(`tags`).getMany(i.map(e=>e.tagId)),o=await e.readonly(`page`).getMany([...new Set(t.map(e=>e.pageId))]);n.set(r,{tags:a.flatMap(e=>e?[{label:e.label,...e.type?{type:e.type}:{}}]:[]),links:t,pages:o.filter(e=>e!==void 0)})}return n}},feedCatalogStore:{getAllFeeds:async()=>{let t=[];for(let n of await e.readonly(`meta`).getAll()){let e=n.key;if(typeof e!=`string`||!e.startsWith(`seed:`)||e===ix(`user`))continue;let r=e.slice(5);t.push({id:r,label:r,url:`https://${r}.example/feed/`,tier:`imported`,subscribed:!0,installed:!0,notebookCount:0,itemCount:0})}return t},getAllNotebooks:async()=>{let t=await e.readonly(`notebook_links`).getAll().catch(()=>[]),n=await e.readonly(`notes`).getAll(),r=new Map;for(let e of t)e.targetKind===`note`&&r.set(e.notebookId,(r.get(e.notebookId)??0)+1);let i=[];for(let[e,t]of r){let r=e.startsWith(`notebook/`)?e.slice(9):e,a=n.find(t=>t.id===e),o=a?.feedSourceId;i.push({id:e,feedId:o??`local`,feedLabel:o??`Yours (Local)`,chunkId:`notebook.${r}`,slug:r,label:a?.title??r,count:t,subscribed:o!==void 0,installed:!0,origin:o?`feed`:`user`,...a?.public===void 0?{}:{public:a.public}})}return i}}}}function spe(e){return new Fy(ope(e))}async function R9(e,t,n,r){let i=new Set(r.map(e=>e.id));for(let r of n)i.has(r.id)||await e.readwrite(t).delete(r.id);let a=new Map(n.map(e=>[e.id,e]));for(let n of r)Tx(a.get(n.id),n)||(t===`block_index`&&`blockVersion`in n&&await e.readwrite(`block_index`).put(n),t===`block_efforts`&&`effortSlug`in n&&await e.readwrite(`block_efforts`).put(n),t===`block_equipment`&&`equipmentSlug`in n&&await e.readwrite(`block_equipment`).put(n))}async function z9(e,t){let n=t.now??Date.now(),r=Tb(t.rawContent),i=t.noteId??r?.noteId??F9(),a=t.tags??Fb(t.rawContent);return e.transaction([`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`,`efforts`,`equipment`,`tags`,`note_tags`,`page`,`page_notes`,`notebook_links`],`readwrite`,async e=>{let o=await e.readonly(`notes`).get(i);if(o){let e=Qv(o),t=Zv(o);if(!(o.seedOrigin!==`seed`&&o.feedOrigin!==`feed`&&oo(o,e,t)))throw Error(`Note '${i}' is read-only (seed/feed). Clone it first with wod_note_clone before editing.`)}if(t.expectedSourceRevision!==void 0&&(o?.sourceRevision??0)!==t.expectedSourceRevision)throw Error(`CONFLICT: Stale sourceRevision on note '${i}': expected ${t.expectedSourceRevision}, actual ${o?.sourceRevision??0}.`);let s=o&&o.rawContent===t.rawContent?o.sourceRevision:(o?.sourceRevision??0)+1,c=await e.readonly(`block_revisions`).getAllFromIndex(`by-note`,i),l=new Map;for(let e of c)(l.get(e.blockId)?.version??0)<e.version&&l.set(e.blockId,e);let u=0,d=mo(t.rawContent,{sourceRevision:s,blocks:o?.blocks,registeredWidgets:co,createId:()=>{for(;;){let e=`blk-${i.slice(0,8)}-${u++}`;if(!l.has(e))return e}}});ho(t.rawContent,d,s,{registeredWidgets:co});let f=[];for(let e of Object.values(d)){let r=l.get(e.id),a=t.rawContent.slice(e.from,e.to),o=r&&r.rawContent===a&&r.kind===e.kind&&r.dialect===e.dialect&&r.sport===e.sport;e.version=o?r.version:(r?.version??0)+1,o||f.push({noteId:i,blockId:e.id,version:e.version,kind:e.kind,rawContent:a,savedAt:n,...e.dialect?{dialect:e.dialect}:{},...e.sport?{sport:e.sport}:{}})}if(o?.rawContent===t.rawContent&&!Tx(o.blocks,d)){s+=1;for(let e of Object.values(d))e.sourceRevision=s}let p=t.title??r?.title??ape(t.rawContent)??o?.title??`Untitled Workout`,m=t.notebookId?ao(t.notebookId):o?.notebookId,h=Array.from(new Set([`notebook/journal`,...o?.notebookIds??[],...m?[m]:[]])),g=t.journalDate?Date.parse(`${L9(t.journalDate,n)}T12:00:00Z`):o?.date??n,_={...o??{},id:i,title:p,rawContent:t.rawContent,sourceRevision:s,blocks:d,type:t.type??o?.type??(t.journalDate?`journal`:`note`),date:g,createdAt:o?.createdAt??n,notebookIds:h,...m&&m!==`notebook/journal`?{notebookId:m}:{},tags:a.map(e=>e.label),seedOrigin:`user`},v=await e.readonly(`efforts`).getAll(),y=new Map;for(let e of ru)y.set(e.slug,e);for(let e of v)y.set(e.slug,e);let b=fu({efforts:[...y.values()],equipment:await e.readonly(`equipment`).getAll()}),x=await e.readonly(`block_index`).getAllFromIndex(`by-note`,i),S=await e.readonly(`block_efforts`).getAllFromIndex(`by-note`,i),C=await e.readonly(`block_equipment`).getAllFromIndex(`by-note`,i),w=new Map(x.map(e=>[e.id,e])),T=[],E=[],D=[],O=new Set,k=new Set;for(let[e,r]of Object.values(d).sort((e,t)=>e.from-t.from).entries()){let a=`${i}:${r.id}`,o=w.get(a),c=t.rawContent.slice(r.from,r.to),l=fo(c,{registeredWidgets:co})[0]?.displayContent??c,u=r.kind===`wod`?Ga(l):void 0;if(T.push({...o??{},id:a,noteId:i,blockId:r.id,blockVersion:r.version,dataType:r.kind,sourceRevision:s,from:r.from,to:r.to,position:e,rawContent:c,noteTitle:_.title,createdAt:o?.createdAt??n,...u?{blockContentId:u}:{},..._.notebookId?{notebookId:_.notebookId}:{}}),r.kind===`wod`){let e=dl(l,{...r.sport?{sport:r.sport}:{},references:b}),t=pu(e.statements),a=new Set(t.efforts);if(a.size===0)for(let t of e.statements){let e=t.metrics?.getMetric?.(J.Effort),n=(typeof e?.value==`string`?e.value:``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);n&&![`rest`,`amrap`,`emom`,`tabata`,`for-time`].includes(n)&&a.add(n)}for(let e of a){O.add(e);let t=`${i}:${r.id}:${e}`,a=S.find(e=>e.id===t);E.push({...a??{},id:t,noteId:i,blockId:r.id,...u?{blockContentId:u}:{},effortSlug:e,createdAt:a?.createdAt??n})}for(let e of t.equipment){k.add(e);let t=`${i}:${r.id}:${e}`,a=C.find(e=>e.id===t);D.push({...a??{},id:t,noteId:i,blockId:r.id,...u?{blockContentId:u}:{},equipmentSlug:e,createdAt:a?.createdAt??n})}}}Tx(o,_)||await e.readwrite(`notes`).put(_),f.length>0&&await e.readwrite(`block_revisions`).putMany(f),await R9(e,`block_index`,x,T),await R9(e,`block_efforts`,S,E),await R9(e,`block_equipment`,C,D);let A=await e.readonly(`note_tags`).getAllFromIndex(`by-note`,i),j=new Map;for(let t of a){let r=t.label.trim();if(!r)continue;let a=(await e.readonly(`tags`).getAllFromIndex(`by-label`,r))[0],o=a?{...a,...!a.type&&t.type?{type:t.type}:{}}:{id:F9(),label:r,...t.type?{type:t.type}:{},createdAt:n};Tx(a,o)||await e.readwrite(`tags`).put(o);let s=A.find(e=>e.tagId===o.id)?.id??`${i}:${o.id}`;j.set(s,{id:s,noteId:i,tagId:o.id})}for(let t of A)j.has(t.id)||await e.readwrite(`note_tags`).delete(t.id);for(let t of j.values())await e.readwrite(`note_tags`).put(t);let M=h.map(e=>({id:gS(ao(e),`note`,i),notebookId:ao(e),targetKind:`note`,targetId:i,noteId:i,createdAt:n}));if(M.length>0&&await e.readwrite(`notebook_links`).putMany(M),t.journalDate){let r=L9(t.journalDate,n),a;try{a=await e.readonly(`page`).getAllFromIndex(`by-date`,r)}catch{a=(await e.readonly(`page`).getAll()).filter(e=>e.date===r)}let o=a[0];o||(o={id:F9(),date:r,title:r,createdAt:n},await e.readwrite(`page`).put(o));let s=await e.readonly(`page_notes`).getAllFromIndex(`by-page`,o.id);if(!s.some(e=>e.noteId===i)){let t=s.reduce((e,t)=>typeof t.position==`number`&&t.position>e?t.position:e,-1);await e.readwrite(`page_notes`).put({id:F9(),pageId:o.id,noteId:i,position:t+1,createdAt:n})}}return{note:_,created:!o,blockCount:T.length,effortSlugs:[...O],equipmentSlugs:[...k],tagLabels:a.map(e=>e.label)}})}async function B9(e,t){return e.transaction([`notes`,`attachments`,`note_tags`,`block_index`,`block_efforts`,`block_equipment`,`page_notes`,`notebook_links`,`meta`],`readwrite`,async e=>{let n=await e.readonly(`notes`).get(t);if(!n)return!1;await e.readwrite(`notes`).delete(t);for(let n of await e.readonly(`attachments`).getAllFromIndex(`by-note`,t))await e.readwrite(`attachments`).delete(n.id);for(let n of await e.readonly(`note_tags`).getAllFromIndex(`by-note`,t))await e.readwrite(`note_tags`).delete(n.id);for(let n of await e.readonly(`block_index`).getAllFromIndex(`by-note`,t))await e.readwrite(`block_index`).delete(n.id);for(let n of await e.readonly(`block_efforts`).getAllFromIndex(`by-note`,t))await e.readwrite(`block_efforts`).delete(n.id);for(let n of await e.readonly(`block_equipment`).getAllFromIndex(`by-note`,t))await e.readwrite(`block_equipment`).delete(n.id);for(let n of await e.readonly(`page_notes`).getAllFromIndex(`by-note`,t))await e.readwrite(`page_notes`).delete(n.id);try{for(let n of await e.readonly(`notebook_links`).getAllFromIndex(`by-note`,t))await e.readwrite(`notebook_links`).delete(n.id)}catch{}return(n.seedOrigin===`seed`||n.seedChunkId!==void 0||n.sourcePath!==void 0)&&await e.readwrite(`meta`).put({key:Mx(t),value:Date.now()}),!0})}async function cpe(e,t){return e.transaction([`sessions`,`events`,`notebook_links`],`readwrite`,async e=>{if(!await e.readonly(`sessions`).get(t))return!1;await e.readwrite(`sessions`).delete(t);let n=await e.readonly(`events`).getAll();for(let r of n)r.resultId===t&&await e.readwrite(`events`).delete(r.id);try{let n=await e.readonly(`notebook_links`).getAll();for(let r of n)r.targetKind===`session`&&r.targetId===t&&await e.readwrite(`notebook_links`).delete(r.id)}catch{}return!0})}function V9(e,t=``){return`${t.replace(/\/+$/,``)}/note/${encodeURIComponent(e.id)}`}var lpe=N9({name:`wod_catalog_lookup`,title:`Lookup Efforts, Equipment & Tags`,description:"Search or inspect the Effort movement registry, Equipment catalog, Tags, and Tag Categories with Notebook-scoped override precedence (`notebook/defaults` -> Feed/Notebook -> `notebook/custom`).",tier:0,domain:`catalog`,annotations:{title:`Lookup Catalog`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({kind:wt([`effort`,`equipment`,`tag`,`tag-type`]).describe(`Catalog family to search or inspect.`),search:ur().optional().describe(`Case-insensitive slug, label, or alias filter.`),slug:ur().optional().describe(`Exact canonical slug/name to look up.`),notebookId:ur().optional().describe(`Optional Notebook scope for property inheritance resolution.`),limit:sn().int().min(1).max(250).optional().describe(`Max entries to return (default 50).`)}),cliEquivalent:`wod catalog <efforts|equipment|tags> --json`,async execute(e,t){let n=await qx(t.storage,{...e.notebookId?{notebookId:e.notebookId}:{},mode:`custom-runtime`}),r=e.limit??50,i=e.search?.trim().toLowerCase(),a=e.slug?.trim().toLowerCase();if(e.kind===`effort`){let e=new Map;for(let t of ru)e.set(t.slug,t);for(let t of n.efforts)e.set(t.slug,t);let t=[...e.values()].filter(e=>a?e.slug.toLowerCase()===a:!i||e.slug.toLowerCase().includes(i)||e.label.toLowerCase().includes(i)||(e.aliases??[]).some(e=>e.toLowerCase().includes(i)));return{kind:`effort`,totalCount:t.length,items:t.slice(0,r).map(e=>({slug:e.slug,label:e.label,aliases:e.aliases??[],met:e.baseAttributes?.met,scope:n.originByKey.get(`effort:${e.slug}`)??`notebook/defaults`,...a?{markdown:Ib(e)}:{}}))}}if(e.kind===`equipment`){let e=n.equipment.filter(e=>a?e.slug.toLowerCase()===a:!i||e.slug.toLowerCase().includes(i)||e.label.toLowerCase().includes(i)||(e.aliases??[]).some(e=>e.toLowerCase().includes(i)));return{kind:`equipment`,totalCount:e.length,items:e.slice(0,r).map(e=>({slug:e.slug,label:e.label,aliases:e.aliases??[],scope:n.originByKey.get(`equipment:${e.slug}`)??`notebook/defaults`,...a?{markdown:Lb(e)}:{}}))}}if(e.kind===`tag`){let e=n.tags.filter(e=>a?e.label.toLowerCase()===a:!i||e.label.toLowerCase().includes(i)||(e.type??``).toLowerCase().includes(i));return{kind:`tag`,totalCount:e.length,items:e.slice(0,r).map(e=>({id:e.id,label:e.label,type:e.type??`general`,contributions:e.contributions??[],scope:n.originByKey.get(`tag:${e.label}`)??`notebook/defaults`}))}}let o=n.tagTypes.filter(e=>a?e.name.toLowerCase()===a:!i||e.name.toLowerCase().includes(i)||e.label.toLowerCase().includes(i));return{kind:`tag-type`,totalCount:o.length,items:o.slice(0,r)}}}),upe=yr({kind:wt([`effort`,`equipment`,`tag`,`tag-type`]).describe(`Property definition family to create or override.`),slug:ur().min(1).describe(`Canonical kebab-case slug (e.g. "kettlebell-swing", "barbell").`),label:ur().optional().describe(`Human-readable display label.`),targetNotebookId:ur().optional().describe(`Target Notebook scope: defaults to "notebook/custom" (personal runtime) or a writable user Notebook.`),markdown:ur().optional().describe(`Full Property Note Markdown with YAML frontmatter. If omitted, synthesized from structured fields below.`),met:sn().positive().optional().describe(`MET metabolic equivalent (for kind="effort", default 5.0).`),aliases:Pt(ur()).optional().describe(`Optional movement/equipment aliases.`),category:ur().optional().describe(`Tag category when kind="tag" (e.g. "equipment", "quality", "format").`),color:ur().optional().describe(`Hex color when kind="tag-type" (e.g. "#10b981").`)});function dpe(e){if(e.markdown?.trim())return e.markdown;let t=e.slug.trim().toLowerCase(),n=e.label?.trim()||t,r=e.aliases&&e.aliases.length>0?`\naliases:\n${e.aliases.map(e=>` - ${JSON.stringify(e)}`).join(`
1160
1160
  `)}`:``;if(e.kind===`effort`){let i=e.met??5;return`---\nid: effort-${t}\nslug: ${t}\nlabel: ${JSON.stringify(n)}${r}\nbaseAttributes:\n met: ${i}\n---\n\n# ${n}\n`}if(e.kind===`equipment`)return`---\ntype: equipment\nid: equipment-${t}\nslug: ${t}\nlabel: ${JSON.stringify(n)}${r}\n---\n\n# ${n}\n`;if(e.kind===`tag`){let r=e.category??`general`;return`---\ntype: tag\nid: tag-${t}\nslug: ${t}\nlabel: ${JSON.stringify(n)}\ncategory: ${r}\n---\n\n# ${n}\n`}let i=e.color??`#6366f1`;return`---\ntype: tag-type\nid: type-${t}\nslug: ${t}\nlabel: ${JSON.stringify(n)}\ncolor: ${JSON.stringify(i)}\n---\n\n# ${n}\n`}var fpe=[lpe,N9({name:`wod_catalog_upsert`,title:`Save Effort, Equipment, or Tag Property Note`,description:"Create or update a Scoped Property Override (`effort`, `equipment`, `tag`, or `tag-type`) in `notebook/custom` or a shared user Notebook.",tier:1,domain:`catalog`,annotations:{title:`Save Catalog Property`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:upe,cliEquivalent:`wod catalog save <kind> <file|-> --json`,async execute(e,t){let n=dpe(e),r=await Gx(t.storage,{targetNotebookId:e.targetNotebookId??`notebook/custom`,kind:e.kind,slug:e.slug,rawContent:n,title:e.label,category:e.category});return await t.onMutated?.([`notes`,`block_revisions`,`property_overrides`,`efforts`,`equipment`,`tags`,`tag_types`]),{id:r.id,kind:r.kind,slug:r.slug,label:r.label,notebookId:r.notebookId,ownerNoteId:r.ownerNoteId}}})],ppe=[N9({name:`wod_feed_manage`,title:`Manage Feeds & Portability`,description:"Inspect installed Seed/Feed sources (`list`), check unpublished public Notebook changes (`status`), compile and publish public Notebooks (`publish`), or import portable Markdown + JSONL/CSV files (`import-bundle`).",tier:1,domain:`feed`,annotations:{title:`Manage Feeds`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({action:wt([`list`,`status`,`publish`,`import-bundle`]).describe(`Feed or portability operation to run.`),notebookSlug:ur().optional().describe(`Optional Notebook slug filter when publishing.`),name:ur().optional().describe(`Optional Feed display name when publishing.`),description:ur().optional().describe(`Optional Feed description when publishing.`),files:Pt(yr({path:ur().min(1),content:ur()})).optional().describe('Portable `.md` / `.jsonl` / `.csv` files when action="import-bundle".')}),cliEquivalent:`wod feed <list|status|publish> --json`,async execute(e,t){if(e.action===`list`){let e=await t.storage.readonly(`meta`).getAll(),n=[];for(let t of e){let e=t;typeof e.key==`string`&&e.key.startsWith(`seed:`)&&e.key!==ix(`user`)&&n.push({sourceId:e.key.slice(5),seedVersion:e.seedVersion,builtAt:e.builtAt,importedAt:e.importedAt,chunkCount:Object.keys(e.chunks??{}).length})}return{action:`list`,installedCount:n.length,feeds:n}}if(e.action===`status`)return{action:`status`,...await hS(t.storage,t.feedTree)};if(e.action===`publish`){let n=t.feedTree??new cS,r=await mS(t.storage,n,{layout:`feed`,notebookSlug:e.notebookSlug,name:e.name,description:e.description});return await t.onMutated?.([`meta`,`property_overrides`]),{action:`publish`,notebooks:r.notebooks,totalNotes:r.totalNotes,totalPublicSessions:r.totalPublicSessions,manifestVersion:r.manifest.version,manifestSha256:r.manifestSha256}}if(!e.files||e.files.length===0)throw Error('Provide non-empty `files` array when action="import-bundle".');let n=await NS(t.storage,e.files,{defaultNotebookId:e.notebookSlug});return await t.onMutated?.([`notes`,`block_revisions`,`block_index`,`tags`,`note_tags`,`sessions`,`events`]),{action:`import-bundle`,...n}}}),N9({name:`wod_export_bundle`,title:`Export Portable Markdown & Telemetry Bundle`,description:"Export user Notes and attached Session telemetry directly as structured `{ path, content }` strings (Markdown + JSONL/CSV) without triggering synthetic browser file downloads.",tier:0,domain:`feed`,annotations:{title:`Export Portable Bundle`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({noteIds:Pt(ur()).optional().describe(`Optional Note IDs to export (defaults to all user-owned Notes).`),telemetryFormat:wt([`jsonl`,`csv`,`both`]).optional().describe(`Format for companion Session/Event telemetry files (default "jsonl").`)}),cliEquivalent:`wod export note <id> -o -`,async execute(e,t){let n=await MS(t.storage,{noteIds:e.noteIds,telemetryFormat:e.telemetryFormat??`jsonl`});return{fileCount:n.length,files:n}}}),N9({name:`wod_reset_storage`,title:`Wipe Storage Data`,description:`Wipe user Notes, Sessions, Events, and Notebook data from the active storage backend (Tier 2 destructive — requires explicit user confirmation).`,tier:2,domain:`system`,annotations:{title:`Wipe Storage Data`,readOnlyHint:!1,destructiveHint:!0,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({confirmToken:ur().optional().describe(`For non-interactive MCP/CLI calls, pass confirmToken="WIPE_STORAGE" to confirm wiping user storage.`)}),cliEquivalent:`wod reset --yes WIPE_STORAGE --json`,async execute(e,t){return await P9(t,{action:`wod_reset_storage`,targetId:`WIPE_STORAGE`,summary:`Wipe all user Notes, Sessions, and telemetry from WOD Wiki storage`},e.confirmToken),await t.storage.wipe(),await t.onMutated?.([`notes`,`sessions`,`events`,`page`,`page_notes`,`notebook_links`]),{wiped:!0}}})],mpe=[N9({name:`wod_journal_day`,title:`Get Journal Day`,description:"Fetch all scheduled/authored workout Notes and recorded Sessions for a specific Journal calendar day (`YYYY-MM-DD` or `today`).",tier:0,domain:`journal`,annotations:{title:`Get Journal Day`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({date:ur().optional().describe(`Calendar date in YYYY-MM-DD format, or "today" (defaults to "today").`)}),cliEquivalent:`wod journal [today|YYYY-MM-DD] --json`,async execute(e,t){let n=L9(e.date),r=Date.parse(`${n}T00:00:00Z`),i=Date.parse(`${n}T23:59:59.999Z`),a;try{a=await t.storage.readonly(`page`).getAllFromIndex(`by-date`,n)}catch{a=(await t.storage.readonly(`page`).getAll()).filter(e=>e.date===n)}let o=a[0],s=[];if(o){let e=qa(await t.storage.readonly(`page_notes`).getAllFromIndex(`by-page`,o.id));for(let t of e)s.includes(t.noteId)||s.push(t.noteId)}let[c,l]=await Promise.all([t.storage.readonly(`notes`).getAll(),t.storage.readonly(`sessions`).getAll()]),u=new Map(c.map(e=>[e.id,e])),d=[],f=new Set;for(let e of s){let t=u.get(e);t&&(d.push(t),f.add(t.id))}for(let e of c){if(f.has(e.id)||e.seedOrigin===`seed`||e.feedOrigin===`feed`||e.id.startsWith(`notebook/`)&&e.notebookId===e.id)continue;let t=e.date??e.createdAt;t>=r&&t<=i&&(d.push(e),f.add(e.id))}let p=l.filter(e=>o&&e.pageId===o.id||f.has(e.noteId)&&e.startTime>=r&&e.startTime<=i?!0:e.startTime>=r&&e.startTime<=i).sort((e,t)=>e.startTime-t.startTime);return{date:n,url:`${(t.baseUrl??``).replace(/\/+$/,``)}/journal/${n}`,pageId:o?.id??null,noteCount:d.length,notes:d.map(e=>({id:e.id,title:e.title,sourceRevision:e.sourceRevision,rawContent:e.rawContent,tags:e.tags??[],wodBlockIds:Object.values(e.blocks??{}).filter(e=>e.kind===`wod`).map(e=>e.id),url:V9(e,t.baseUrl)})),sessionCount:p.length,sessions:p.map(e=>({id:e.id,noteId:e.noteId,blockId:e.blockId,status:e.status,completed:e.completed,duration:e.duration,startTime:e.startTime}))}}}),N9({name:`wod_journal_add`,title:`Add Workout to Journal Day`,description:"Create a new workout Note in `notebook/journal` and place it onto the specified calendar day (`YYYY-MM-DD` or `today`).",tier:1,domain:`journal`,annotations:{title:`Add Workout to Journal Day`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},inputSchema:yr({date:ur().optional().describe(`Target Journal date in YYYY-MM-DD format or "today" (defaults to "today").`),title:ur().optional().describe(`Workout title (defaults to # H1 heading or date).`),content:ur().min(1).describe(`Markdown workout note or bare Whiteboard Script to schedule onto the Journal day.`),sport:ur().optional().describe(`Optional sport fence tag when passing bare Whiteboard Script.`),notebookId:ur().optional().describe(`Optional additional user Notebook to promote this Journal Note into.`)}),cliEquivalent:`wod journal add <file|-> --date YYYY-MM-DD --json`,async execute(e,t){let n=L9(e.date),r=e.title??`Workout ${n}`,i=I9(e.content,e.sport,e.title),a=await z9(t.storage,{title:r,rawContent:i,journalDate:n,notebookId:e.notebookId,type:`journal`});await t.onMutated?.([`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`,`page`,`page_notes`,`notebook_links`]);let o=(t.baseUrl??``).replace(/\/+$/,``);return{date:n,noteId:a.note.id,journalUrl:`${o}/journal/${n}`,note:{id:a.note.id,title:a.note.title,sourceRevision:a.note.sourceRevision,blockCount:a.blockCount,effortSlugs:a.effortSlugs,url:V9(a.note,t.baseUrl)}}}})];function H9(e){return e.id.startsWith(`notebook/`)&&e.notebookId===e.id}var U9=new Set(so.map(e=>e.slug)),hpe=[N9({name:`wod_notebook_list`,title:`List Notebooks`,description:`List built-in, user-created, and feed-subscribed Notebooks along with member Note counts and publication status.`,tier:0,domain:`notebook`,annotations:{title:`List Notebooks`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({origin:wt([`all`,`default`,`user`,`feed`]).optional().describe(`Filter notebooks by origin (default "all").`)}),cliEquivalent:`wod notebook list --json`,async execute(e,t){let[n,r]=await Promise.all([t.storage.readonly(`notes`).getAll(),t.storage.readonly(`notebook_links`).getAll().catch(()=>[])]),i=new Map,a=new Set,o=(e,t)=>{let n=`${e}\u0000${t}`;a.has(n)||(a.add(n),i.set(e,(i.get(e)??0)+1))};for(let e of r)e.targetKind===`note`&&o(ao(e.notebookId),e.noteId);for(let e of n)if(!H9(e))for(let t of Xv(e))o(ao(t),e.id);let s=new Map;for(let e of so)s.set(e.notebookId,{notebookId:e.notebookId,slug:e.slug,name:e.name,description:e.description,icon:e.icon,origin:`default`,writable:!no(e.notebookId),public:!1,noteCount:i.get(e.notebookId)??0});for(let e of n){if(!H9(e))continue;let t=io(e.id),n=Nb(e.rawContent),r=typeof n.description==`string`?n.description.replace(/^"|"$/g,``):``,a=typeof n.icon==`string`?n.icon.replace(/^"|"$/g,``):`📓`,o=e.feedOrigin===`feed`||e.seedOrigin===`seed`,c=s.get(e.id);s.set(e.id,{notebookId:e.id,slug:t,name:e.title||c?.name||t,description:r||c?.description||``,icon:a||c?.icon||`📓`,origin:c?.origin??(o?`feed`:`user`),writable:!no(e.id)&&!o,public:e.public===!0,noteCount:i.get(e.id)??0})}let c=e.origin??`all`,l=(t.baseUrl??``).replace(/\/+$/,``),u=[...s.values()].filter(e=>c===`all`||e.origin===c).map(e=>({id:e.notebookId,...e,url:`${l}/notebooks/${encodeURIComponent(e.slug)}`}));return{totalCount:u.length,notebooks:u}}}),N9({name:`wod_notebook_save`,title:`Create, Update, or Promote Notebook`,description:"Create or update a user-owned Notebook, promote/detach a Note across Notebooks (`notebook/journal` permanence preserved), or toggle Notebook publication visibility.",tier:1,domain:`notebook`,annotations:{title:`Save or Promote Notebook`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({action:wt([`create`,`update`,`promote`,`detach`,`set-public`]).describe(`Operation to perform on a user Notebook.`),notebookId:ur().optional().describe(`Target Notebook slug or ID (required for update, promote, detach, set-public).`),name:ur().optional().describe(`Display name when creating or renaming a Notebook.`),description:ur().optional().describe(`Notebook description.`),icon:ur().optional().describe(`Notebook icon/emoji.`),noteId:ur().optional().describe(`Note ID to promote into or detach from the Notebook.`),sessionIds:Pt(ur()).optional().describe("Optional Session IDs on `noteId` to promote alongside the Note."),public:Ue().optional().describe(`Visibility flag when action="set-public" or promoting sessions.`)}),cliEquivalent:`wod notebook <create|update|promote> --json`,async execute(e,t){if(e.action===`create`){let n=e.name?.trim()||e.notebookId?.trim();if(!n)throw Error('`name` is required when action="create".');let r=await xS(t.storage,n);if(e.description!==void 0||e.icon!==void 0){let i=`---\ndescription: ${JSON.stringify(e.description??``)}\nicon: ${JSON.stringify(e.icon??`📓`)}\n---\n\n# ${n}\n`,a=await z9(t.storage,{noteId:r,title:n,rawContent:i});await t.storage.readwrite(`notes`).put({...a.note,notebookId:r})}return e.public!==void 0&&await OS(t.storage,r,e.public),await t.onMutated?.([`notes`,`block_revisions`,`notebook_links`]),{action:`create`,notebookId:r,slug:io(r),name:n}}if(!e.notebookId)throw Error(`'notebookId' is required for action="${e.action}".`);let n=ao(e.notebookId),r=io(n);if(e.action===`update`){if(U9.has(r))throw Error(`Built-in Notebook '${n}' cannot be modified.`);let i=await t.storage.readonly(`notes`).get(n);if(!i)throw Error(`Notebook not found: ${n}`);let a=Nb(i.rawContent),o=e.name??i.title??r,s=e.description??(typeof a.description==`string`?a.description.replace(/^"|"$/g,``):``),c=e.icon??(typeof a.icon==`string`?a.icon.replace(/^"|"$/g,``):`📓`),l=`---\ndescription: ${JSON.stringify(s)}\nicon: ${JSON.stringify(c)}\n---\n\n# ${o}\n`,u=await z9(t.storage,{noteId:n,title:o,rawContent:l});return await t.storage.readwrite(`notes`).put({...u.note,notebookId:n,...i.public===void 0?{}:{public:i.public}}),await t.onMutated?.([`notes`,`block_revisions`]),{action:`update`,notebookId:n,slug:r,name:o}}if(e.action===`promote`){if(!e.noteId)throw Error('`noteId` is required when action="promote".');let r=await SS(t.storage,{noteId:e.noteId,notebookIds:[n],sessionIds:e.sessionIds,shareSessionsPublicly:e.public});return await t.onMutated?.([`notes`,`sessions`,`notebook_links`]),{action:`promote`,noteId:e.noteId,notebookIds:r.notebookIds,promotedSessionIds:r.promotedSessionIds}}if(e.action===`detach`){if(!e.noteId)throw Error('`noteId` is required when action="detach".');let r=await wS(t.storage,e.noteId,n);return await t.onMutated?.([`notes`,`notebook_links`]),{action:`detach`,noteId:e.noteId,notebookIds:r}}if(ro(n))throw Error(`Notebook '${n}' is private/system and cannot be published.`);let i=await OS(t.storage,n,e.public??!0);return await t.onMutated?.([`notes`]),{action:`set-public`,notebookId:n,public:i.public===!0}}}),N9({name:`wod_notebook_delete`,title:`Delete User Notebook`,description:"Delete a user-created Notebook landing note and detach member links while keeping all member Notes safely in `notebook/journal` (Tier 2 destructive).",tier:2,domain:`notebook`,annotations:{title:`Delete User Notebook`,readOnlyHint:!1,destructiveHint:!0,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({notebookId:ur().min(1).describe(`User Notebook ID or slug to delete (member Notes stay safe in notebook/journal).`),confirmId:ur().optional().describe(`For non-interactive MCP/CLI calls, repeat the exact notebookId or slug to confirm deletion.`)}),cliEquivalent:`wod notebook delete <slug> --yes <slug> --json`,async execute(e,t){let n=ao(e.notebookId),r=io(n);if(U9.has(r))throw Error(`Built-in Notebook '${n}' cannot be deleted.`);let i=e.confirmId===n||e.confirmId===r?n:void 0;await P9(t,{action:`wod_notebook_delete`,targetId:n,summary:`Delete user Notebook "${r}" (${n}); member Notes remain in notebook/journal`},i);let a=await t.storage.readonly(`notes`).getAll();for(let e of a)if(!H9(e)&&(e.notebookId===n||(e.notebookIds??[]).includes(n))){let r=(e.notebookIds??[`notebook/journal`]).map(e=>ao(e)).filter(e=>e!==n),i=r.find(e=>e!==`notebook/journal`&&e!==`notebook/playground`),{notebookId:a,...o}=e;await t.storage.readwrite(`notes`).put({...o,notebookIds:r.length>0?r:[`notebook/journal`],...i?{notebookId:i}:{}})}try{let e=await t.storage.readonly(`notebook_links`).getAllFromIndex(`by-notebook`,n);for(let n of e)await t.storage.readwrite(`notebook_links`).delete(n.id)}catch{}let o=await B9(t.storage,n);return await t.onMutated?.([`notes`,`notebook_links`]),{deleted:o,notebookId:n,slug:r}}})];function gpe(e){return e.id.startsWith(`notebook/`)&&e.notebookId===e.id}var _pe=[N9({name:`wod_note_list`,title:`List Notes`,description:`List workout and reference Notes with optional filtering by Notebook, search query, tag, and origin.`,tier:0,domain:`note`,annotations:{title:`List Notes`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({notebookId:ur().optional().describe(`Filter by notebook ID or slug (e.g. "journal", "custom", "guides", "notebook/strength").`),search:ur().optional().describe(`Case-insensitive substring filter over title and Markdown content.`),tag:ur().optional().describe(`Filter to Notes carrying this tag label.`),includeSeed:Ue().optional().describe(`Include read-only Seed/Feed notes (default true when notebookId is specified, false otherwise).`),limit:sn().int().min(1).max(200).optional().describe(`Max notes to return (default 50).`)}),cliEquivalent:`wod note list --json`,async execute(e,t){let n=await t.storage.readonly(`notes`).getAll(),r=e.notebookId?ao(e.notebookId):void 0,i=e.includeSeed??!!r,a=e.search?.trim().toLowerCase(),o=e.tag?.trim().toLowerCase(),s=e.limit??50,c;if(r)try{let e=await t.storage.readonly(`notebook_links`).getAllFromIndex(`by-notebook`,r);c=new Set(e.filter(e=>e.targetKind===`note`).map(e=>e.noteId))}catch{c=new Set}let l=n.filter(e=>!(gpe(e)||!i&&(e.seedOrigin===`seed`||e.feedOrigin===`feed`)||r&&!(c?.has(e.id)||e.notebookId===r||(e.notebookIds??[]).includes(r)||Xv(e).includes(r))||o&&!(e.tags??[]).some(e=>e.toLowerCase()===o)||a&&!e.title.toLowerCase().includes(a)&&!e.rawContent.toLowerCase().includes(a))).sort((e,t)=>(t.date??t.createdAt)-(e.date??e.createdAt));return{totalCount:l.length,notes:l.slice(0,s).map(e=>{let n=Qv(e),r=Zv(e);return{id:e.id,title:e.title,sourceRevision:e.sourceRevision,date:e.date,createdAt:e.createdAt,editable:oo(e,n,r),notebooks:Xv(e),tags:e.tags??[],wodBlockCount:Object.values(e.blocks??{}).filter(e=>e.kind===`wod`).length,url:V9(e,t.baseUrl)}})}}}),N9({name:`wod_note_get`,title:`Get Note Details`,description:"Read a full Note by ID including authored Markdown, `sourceRevision`, parsed workout blocks, attached Session count, upstream provenance, and publication visibility.",tier:0,domain:`note`,annotations:{title:`Get Note Details`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({noteId:ur().min(1).describe(`Unique Note ID (UUID or seed route ID).`)}),cliEquivalent:`wod note get <noteId> --json`,async execute(e,t){let n=await t.storage.readonly(`notes`).get(e.noteId);if(!n)throw Error(`Note not found: ${e.noteId}`);let r=oo(n,Qv(n),Zv(n)),[i,a,o,s]=await Promise.all([TS(t.storage,n.id),RS(t.storage,n),DS(t.storage,n.id),t.storage.readonly(`sessions`).getAllFromIndex(`by-note`,n.id).catch(async()=>(await t.storage.readonly(`sessions`).getAll()).filter(e=>e.noteId===n.id))]),c=fo(n.rawContent,{registeredWidgets:co}),l=Object.values(n.blocks??{}).sort((e,t)=>e.from-t.from).map(e=>{let t=c.find(t=>t.from===e.from&&t.to===e.to);return{id:e.id,kind:e.kind,version:e.version,...e.dialect?{dialect:e.dialect}:{},...e.sport?{sport:e.sport}:{},content:t?.scriptBlock?.content??n.rawContent.slice(e.from,e.to)}});return{id:n.id,title:n.title,rawContent:n.rawContent,portableMarkdown:Ab(n),sourceRevision:n.sourceRevision,editable:r,date:n.date,createdAt:n.createdAt,tags:n.tags??[],notebooks:i,blocks:l,sessionCount:s.length,recentSessions:s.sort((e,t)=>t.startTime-e.startTime).slice(0,10).map(e=>({id:e.id,blockId:e.blockId,status:e.status,completed:e.completed,duration:e.duration,startTime:e.startTime,public:e.public===!0})),...a?{provenance:a}:{},visibility:o,url:V9(n,t.baseUrl)}}}),N9({name:`wod_note_upsert`,title:`Create or Update Note`,description:"Create a new workout/reference Note or update an existing editable Note with full block-revision pinning, effort/equipment indexing, and optimistic concurrency (`expectedSourceRevision`).",tier:1,domain:`note`,annotations:{title:`Create or Update Note`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({noteId:ur().optional().describe(`Existing Note ID to update, or omit to create a new Note.`),title:ur().optional().describe(`Note title (defaults to # H1 heading in content).`),content:ur().min(1).describe(`Full Markdown document or Whiteboard Script body.`),sport:ur().optional().describe(`Optional sport fence tag when passing bare Whiteboard Script.`),expectedSourceRevision:sn().int().min(0).optional().describe(`Optimistic concurrency guard: pass the current sourceRevision from wod_note_get when updating.`),notebookId:ur().optional().describe(`Optional user Notebook ID/slug to link this Note into (always stays anchored in notebook/journal).`),journalDate:ur().optional().describe(`Optional YYYY-MM-DD or "today" to place the Note on that Journal calendar day.`)}),cliEquivalent:`wod note save <file|-> --json`,async execute(e,t){let n=I9(e.content,e.sport,e.title),r=await z9(t.storage,{noteId:e.noteId,title:e.title,rawContent:n,expectedSourceRevision:e.expectedSourceRevision,notebookId:e.notebookId,journalDate:e.journalDate});return await t.onMutated?.([`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`,`tags`,`note_tags`,`page`,`page_notes`,`notebook_links`]),{id:r.note.id,noteId:r.note.id,title:r.note.title,created:r.created,sourceRevision:r.note.sourceRevision,blockCount:r.blockCount,effortSlugs:r.effortSlugs,equipmentSlugs:r.equipmentSlugs,tags:r.tagLabels,url:V9(r.note,t.baseUrl)}}}),N9({name:`wod_note_clone`,title:`Clone Note with Provenance`,description:"Clone any Note (especially read-only Seed or Feed workouts) into a writable user Notebook or Journal day while recording structured upstream `NoteProvenance`.",tier:1,domain:`note`,annotations:{title:`Clone Note`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},inputSchema:yr({sourceNoteId:ur().min(1).describe(`Source Note ID (including read-only Seed/Feed Notes) to clone.`),targetNotebookId:ur().optional().describe(`Target writable user Notebook ID/slug (defaults to "notebook/journal").`),title:ur().optional().describe(`Optional title override for the cloned Note.`),journalDate:ur().optional().describe(`Optional YYYY-MM-DD or "today" to pin the clone onto a Journal day.`)}),cliEquivalent:`wod note clone <sourceNoteId> --notebook <slug> --json`,async execute(e,t){let n=await t.storage.readonly(`notes`).get(e.sourceNoteId);if(!n)throw Error(`Source Note not found: ${e.sourceNoteId}`);let r=ao(e.targetNotebookId??`notebook/journal`);if(no(r))throw Error(`Target Notebook '${r}' is read-only.`);let i=Date.now(),a=F9(),o=Xv(n)[0],s=zS(n,o,i),c={...(await z9(t.storage,{noteId:a,title:e.title??n.title,rawContent:n.rawContent,notebookId:r,journalDate:e.journalDate,tags:(n.tags??[]).map(e=>({label:e})),now:i})).note,sourceId:n.id,provenance:s};return await t.storage.readwrite(`notes`).put(c),r!==`notebook/journal`&&await SS(t.storage,{noteId:a,notebookIds:[r]}),await t.onMutated?.([`notes`,`block_revisions`,`block_index`,`notebook_links`,`page`,`page_notes`]),{id:c.id,noteId:c.id,title:c.title,sourceRevision:c.sourceRevision,targetNotebookId:r,provenance:s,url:V9(c,t.baseUrl)}}}),N9({name:`wod_note_delete`,title:`Delete Note`,description:`Permanently delete a Note and detach its projections, tag links, and calendar placements (Tier 2 destructive — requires user confirmation or matching confirmId).`,tier:2,domain:`note`,annotations:{title:`Delete Note`,readOnlyHint:!1,destructiveHint:!0,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({noteId:ur().min(1).describe(`ID of the Note to delete.`),confirmId:ur().optional().describe(`For non-interactive MCP/CLI calls, repeat the exact noteId to confirm deletion.`)}),cliEquivalent:`wod note delete <noteId> --yes <noteId> --json`,async execute(e,t){let n=await t.storage.readonly(`notes`).get(e.noteId);if(!n)return{deleted:!1,noteId:e.noteId,reason:`not_found`};await P9(t,{action:`wod_note_delete`,targetId:e.noteId,summary:`Delete Note "${n.title||e.noteId}" (${e.noteId})`},e.confirmId);let r=await B9(t.storage,e.noteId);return r&&await t.onMutated?.([`notes`,`block_index`,`block_efforts`,`block_equipment`,`note_tags`,`page_notes`,`notebook_links`,`meta`]),{deleted:r,noteId:e.noteId,title:n.title}}})];function W9(e,t=[]){for(let n of e.metrics??[])(n.value===`?`||n.origin===`collectible`)&&t.push({...e.id===void 0?{}:{id:e.id},text:e.raw??``,metricType:n.type});for(let n of e.children??[])W9(n,t);return t}var vpe=[N9({name:`wod_parse_script`,title:`Parse Whiteboard Script`,description:"Validate Whiteboard Script syntax, inspect parsed statements, typed metrics, unresolved choices, and collectible `?` placeholders. Defaults to dry-run (`save: false`); pass `save: true` to persist as a Note.",tier:0,domain:`script`,annotations:{title:`Parse Whiteboard Script`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({source:ur().min(1).describe("Whiteboard Script body OR full Markdown document containing ```time / ```wod blocks."),sport:ur().optional().describe(`Optional sport fence dialect override (e.g. "crossfit", "climbing", "running").`),save:Ue().optional().describe(`Default false (dry-run syntax & metric inspection). Set true to persist as a Note.`),noteId:ur().optional().describe(`Optional target Note ID when save=true.`),title:ur().optional().describe(`Optional Note title when save=true.`),notebookId:ur().optional().describe(`Optional user Notebook slug/ID when save=true.`)}),cliEquivalent:`wod parse - --no-save --json`,async execute(e,t){let n=await qx(t.storage,{...e.notebookId?{notebookId:e.notebookId}:{}}).catch(()=>void 0),r=fo(e.source,{registeredWidgets:co}).filter(e=>e.scriptBlock),i=pl({...n?{references:n.referenceIndex,tags:n.tagIndex}:{}}),a=(r.length>0?r.map((t,n)=>({index:n,sport:e.sport??t.scriptBlock?.sport,dialect:t.scriptBlock?.dialect??`time`,body:t.scriptBlock.content})):[{index:0,sport:e.sport,dialect:`time`,body:e.source}]).map(e=>{let t=i.read(e.body,e.sport),n=bb(t),r=Hp(t.statements).map(e=>({statementIndex:e.statementIndex,statementId:e.statementId,choice:e.choice})),a=W9(n);return{index:e.index,dialect:e.dialect,...e.sport?{sport:e.sport}:{},valid:(t.errors?.length??0)===0,errors:t.errors??[],statementCount:t.statements.length,tree:n,unresolvedChoices:r,collectibles:a}}),o=a.every(e=>e.valid),s;if(e.save&&o){let n=I9(e.source,e.sport,e.title),r=await z9(t.storage,{noteId:e.noteId,title:e.title,rawContent:n,notebookId:e.notebookId});await t.onMutated?.([`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`]),s={noteId:r.note.id,title:r.note.title,sourceRevision:r.note.sourceRevision,created:r.created}}return{valid:o,blockCount:a.length,blocks:a,...s?{savedNote:s}:{}}}})];function ype(e,t){if(!t||Object.keys(t).length===0)return e;let n=Object.entries(t),r=e;for(let[e,t]of n){let n=String(t);if(e===`?`||e==="default")r=r.replace(/\?/g,n);else{let t=RegExp(`\\?\\s*${e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}\\b`,`gi`);r=t.test(r)?r.replace(t,`${n} ${e}`):r.replace(/\?/,n)}}return r}var bpe=[N9({name:`wod_session_run_headless`,title:`Run Workout Session Headlessly`,description:"Execute a workout block through the headless JIT compiler and runtime state machine, recording a pinned `Session` and derived `EventRecord`s in storage. Automatically clones read-only Seed/Feed Notes into `notebook/journal`.",tier:1,domain:`session`,annotations:{title:`Run Workout Headlessly`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},inputSchema:yr({noteId:ur().optional().describe(`Existing Note ID to execute (read-only Seed/Feed Notes are automatically cloned to notebook/journal).`),blockId:ur().optional().describe("Optional workout block ID on `noteId` (defaults to first wod block)."),source:ur().optional().describe("Inline Whiteboard Script or Markdown to persist & run when `noteId` is not supplied."),title:ur().optional().describe("Optional Note title when running inline `source`."),sport:ur().optional().describe(`Optional sport dialect override.`),journalDate:ur().optional().describe(`Optional YYYY-MM-DD or "today" Journal calendar date.`),collectibles:Gn(ur(),Dn([ur(),sn()])).optional().describe('Optional values for collectible `?` metrics (e.g. `{ "lb": 185, "reps": 12 }`).'),stepAdvanceMs:sn().int().min(100).max(36e5).optional().describe(`Simulated clock advance per step in milliseconds (default 10000).`),maxSteps:sn().int().min(1).max(5e3).optional().describe(`Safety cap on execution steps (default 500).`),public:Ue().optional().describe(`Mark the recorded Session public for Feed publication.`)}),cliEquivalent:`wod run <file|--note id> --json`,async execute(e,t){let n=e.noteId;if(!n){if(!e.source?.trim())throw Error("Provide either `noteId` or inline `source` to execute a workout session.");let r=I9(e.source,e.sport,e.title);n=(await z9(t.storage,{title:e.title,rawContent:r,journalDate:e.journalDate,type:`journal`})).note.id}let r=Date.now(),i=await LS(t.storage,{noteId:n,blockId:e.blockId,journalDate:e.journalDate,startedAt:r}),a=ype(fo(i.revision.rawContent,{registeredWidgets:co}).find(e=>e.scriptBlock)?.scriptBlock?.content??i.revision.rawContent,e.collectibles),o=await qx(t.storage,{note:i.note}).catch(()=>void 0),s=e.sport??i.revision.sport,c=pl({...o?{references:o.referenceIndex,tags:o.tagIndex}:{}}).read(a,s);if(c.errors&&c.errors.length>0)throw Error(`Whiteboard Script syntax error: ${c.errors.map(e=>e.message).join(`; `)}`);let l=xu(new Date(r)),u=new Zu,d=new yp,f=_u(new Date(r)),p=new Hu(c,qp(),{stack:u,clock:l,eventBus:d},{},f),{engine:m,analyticsContext:h}=Vp({id:i.session.blockId,content:a,statements:c.statements,sport:s,version:i.session.blockVersion,startLine:0,endLine:0,dialect:i.revision.dialect??`time`,state:`idle`,createdAt:r});p.analyticsContext=h,p.setAnalyticsEngine(m);let g=[];p.subscribeToOutput(e=>{g.push(e)}),p.do(new xp);let _=e.stepAdvanceMs??1e4,v=e.maxSteps??500,y=0;for(;u.count>0&&y<v;)l.advance(_),p.handle(new Gp(void 0,{nowMs:()=>l.currentDate.getTime(),now:()=>l.currentDate})),y+=1;let b=u.count===0,x=l.currentDate.getTime();p.dispose();let S=g.map(Tm),C={noteId:i.session.noteId,resultId:i.session.id,blockId:i.session.blockId,blockVersion:i.session.blockVersion,...i.session.blockContentId?{blockContentId:i.session.blockContentId}:{},...i.session.pageId?{pageId:i.session.pageId}:{},origin:i.session.origin,workoutTimestamp:x},w=Rv(S,C),T=zv(S,C),E=[...w,...T],D={...i.session,status:b?`completed`:`in-progress`,endTime:x,duration:Math.max(0,x-r),completed:b,...e.public===void 0?{}:{public:e.public}};return await t.storage.transaction([`sessions`,`events`],`readwrite`,async e=>{await e.readwrite(`sessions`).put(D),E.length>0&&await e.readwrite(`events`).putMany(E)}),e.public!==void 0&&await kS(t.storage,D.id,e.public),await t.onMutated?.([`notes`,`block_revisions`,`block_index`,`sessions`,`events`,`page`,`page_notes`,`notebook_links`]),{sessionId:D.id,noteId:D.noteId,blockId:D.blockId,blockVersion:D.blockVersion,clonedFromReadOnly:i.clonedFromReadOnly,...i.upstreamNoteId?{upstreamNoteId:i.upstreamNoteId}:{},completed:b,stepsExecuted:y,durationMs:D.duration,eventCount:w.length,summaryCount:T.length}}}),N9({name:`wod_session_list`,title:`List Recorded Sessions`,description:`List recorded workout Sessions ordered newest-first, optionally filtered by Note ID.`,tier:0,domain:`session`,annotations:{title:`List Sessions`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({noteId:ur().optional().describe(`Filter Sessions by owning Note ID.`),completedOnly:Ue().optional().describe(`Filter to completed Sessions only.`),limit:sn().int().min(1).max(200).optional().describe(`Max Sessions to return (default 50).`)}),cliEquivalent:`wod session list --json`,async execute(e,t){let n=e.limit??50,r;if(e.noteId)try{r=await t.storage.readonly(`sessions`).getAllFromIndex(`by-note`,e.noteId)}catch{r=(await t.storage.readonly(`sessions`).getAll()).filter(t=>t.noteId===e.noteId)}else r=await t.storage.readonly(`sessions`).getAll();e.completedOnly&&(r=r.filter(e=>e.completed)),r.sort((e,t)=>t.startTime-e.startTime);let i=[...new Set(r.slice(0,n).map(e=>e.noteId))],a=await t.storage.readonly(`notes`).getMany(i),o=new Map;return a.forEach((e,t)=>{e&&o.set(i[t],e.title)}),{totalCount:r.length,sessions:r.slice(0,n).map(e=>({id:e.id,noteId:e.noteId,noteTitle:o.get(e.noteId)??e.noteId,blockId:e.blockId,blockVersion:e.blockVersion,status:e.status,completed:e.completed,duration:e.duration,startTime:e.startTime,endTime:e.endTime,public:e.public===!0}))}}}),N9({name:`wod_session_get`,title:`Get Session Telemetry`,description:"Read a recorded workout Session along with its pinned `BlockRevision` and derived event/summary telemetry rows.",tier:0,domain:`session`,annotations:{title:`Get Session Telemetry`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({sessionId:ur().min(1).describe(`Session ID to inspect.`)}),cliEquivalent:`wod session get <sessionId> --json`,async execute(e,t){let n=await t.storage.readonly(`sessions`).get(e.sessionId);if(!n)throw Error(`Session not found: ${e.sessionId}`);let[r,i,a]=await Promise.all([t.storage.readonly(`notes`).get(n.noteId),t.storage.readonly(`block_revisions`).get([n.noteId,n.blockId,n.blockVersion]),t.storage.readonly(`events`).getAll()]),o=a.filter(e=>e.resultId===n.id).sort((e,t)=>e.timestamp-t.timestamp);return{session:n,noteTitle:r?.title,pinnedRevision:i??null,eventCount:o.filter(e=>e.grain===`event`).length,summaryCount:o.filter(e=>e.grain===`summary`).length,events:o}}}),N9({name:`wod_session_delete`,title:`Delete Recorded Session`,description:`Permanently delete a recorded workout Session and its telemetry events (Tier 2 destructive — requires confirmation).`,tier:2,domain:`session`,annotations:{title:`Delete Session`,readOnlyHint:!1,destructiveHint:!0,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({sessionId:ur().min(1).describe(`Session ID to delete.`),confirmId:ur().optional().describe(`For non-interactive MCP/CLI calls, repeat the exact sessionId to confirm deletion.`)}),cliEquivalent:`wod session delete <sessionId> --yes <sessionId> --json`,async execute(e,t){let n=await t.storage.readonly(`sessions`).get(e.sessionId);if(!n)return{deleted:!1,sessionId:e.sessionId,reason:`not_found`};await P9(t,{action:`wod_session_delete`,targetId:e.sessionId,summary:`Delete workout Session ${e.sessionId} on Note ${n.noteId}`},e.confirmId);let r=await cpe(t.storage,e.sessionId);return r&&await t.onMutated?.([`sessions`,`events`,`notebook_links`]),{deleted:r,sessionId:e.sessionId}}})],xpe=N9({name:`wod_validate_wql`,title:`Validate & Inspect WQL Query`,description:"Parse a WQL string without executing it. Returns syntax validity, query family (find, aggregate, pipeline), normalized WQL string, and the allowed filter keys and `by {}` grouping dimensions for that plane.",tier:0,domain:`wql`,annotations:{title:`Validate WQL Query`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({query:ur().describe(`WQL query string to validate and inspect (e.g. ":note{notebook:journal} last 7d" or "sum:volume by {effort}").`),targetHint:ur().optional().describe(`Optional target plane to list valid filter keys & grouping dimensions for (note, session, effort, equipment, tag, feed, block, event).`)}),cliEquivalent:`wod query "<wql>" --format json`,async execute(e){let t=Y(e.query),n=!t.error,r=Dh(t)?`pipeline`:Th(t)?`find`:`aggregate`,i=e.targetHint??(Th(t)?t.target:Eh(t)?`event`:`note`),a=r===`find`?`find`:`aggregate`;return{valid:n,...t.error?{error:t.error}:{},family:r,target:i,normalized:n?Vh(e.query):e.query,allowedTargets:[...Lm],allowedAggregators:[...Om],allowedRollupPeriods:[...Jm],validFilterKeys:[...ch(i,a)],validGroupingDimensions:[...lh(i,a)]}}}),Spe=[N9({name:`wod_query_wql`,title:`Execute WQL Query`,description:"Run any WQL find (`:note`, `:session`, `:effort`, `:equipment`, `:tag`, `:feed`, `:block`), aggregate (`sum:volume`, `max:weight`, `count:sessions`), or pipeline query against the active WOD Wiki storage.",tier:0,domain:`wql`,annotations:{title:`Execute WQL Query`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},inputSchema:yr({query:ur().min(1).describe(`WQL query expression (e.g. ":note{notebook:journal}", ":session last 30d", "sum:volume by {week}").`),preferredUnit:ur().optional().describe(`Optional display unit conversion preference (e.g. "lb", "kg", "m", "mi").`),limit:sn().int().min(1).max(500).optional().describe(`Maximum rows/items to return in the response payload (default 100).`)}),cliEquivalent:`wod query '<wql>' --format json`,async execute(e,t){let n=Y(e.query);if(n.error)throw Error(`WQL Syntax Error in "${e.query}": ${n.error}. Call wod_validate_wql to inspect valid targets and filter keys.`);let r=spe(t.storage),i=e.limit??100;if(Dh(n)){let t=await r.runPipeline(e.query,{preferredUnit:e.preferredUnit});return{kind:`pipeline-result`,query:e.query,result:t}}if(Th(n)){let t=await r.runFind(n);return Array.isArray(t.runs)?{kind:`rows-result`,target:n.target,query:e.query,totalRuns:t.runs.length,totalCount:t.runs.length,runs:t.runs.slice(0,i),truncated:t.runs.length>i}:Array.isArray(t.efforts)?{kind:`find-result`,target:n.target,query:e.query,totalCount:t.efforts.length,items:t.efforts.slice(0,i),truncated:t.efforts.length>i}:t.table?{kind:`find-result`,target:n.target,query:e.query,columns:t.table.columns,totalCount:t.table.rows.length,items:t.table.rows.slice(0,i),truncated:t.table.rows.length>i}:n.target===`block`?{kind:`find-result`,target:n.target,query:e.query,totalCount:t.blocks.length,items:t.blocks.slice(0,i),truncated:t.blocks.length>i}:{kind:`find-result`,target:n.target,query:e.query,totalCount:t.notes.length,items:t.notes.slice(0,i),truncated:t.notes.length>i}}let a=await r.runQuery(e.query,{preferredUnit:e.preferredUnit});return{kind:`query-result`,query:e.query,result:a}}}),xpe],G9=[...vpe,...Spe,..._pe,...mpe,...hpe,...bpe,...fpe,...ppe];new Map(G9.map(e=>[e.name,e]));async function K9(){if(typeof window>`u`||typeof window.requestAnimationFrame!=`function`){await new Promise(e=>setTimeout(e,0));return}await new Promise(e=>{window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>e())})})}async function q9(e=2e3){let t=Date.now()+e;for(await new Promise(e=>setTimeout(e,200));fq()&&Date.now()<t;)await new Promise(e=>setTimeout(e,25));await K9()}var Cpe=yr({includeSampleEntries:Ue().optional().describe(`Include up to 50 unbatched stream entries when on a stream route (default true).`)}),wpe=yr({path:ur().min(1).describe(`Internal app path (with optional ?query and #hash) to navigate to, e.g. "/journal", "/day/2026-11-11", "/note/<id>", "/notebooks", "/dashboards".`),replace:Ue().optional().describe(`Replace current history entry instead of pushing.`)}),Tpe=yr({action:wt([`status`,`disconnect`]).describe(`Inspect active Chromecast/receiver session status or disconnect an active session.`)}),Epe=yr({query:ur().optional().describe(`WQL query string to apply to the mounted stream view (e.g. ":note{tags:benchmark}").`),layout:wt([`cards`,`rows`,`feed`,`agenda`,`planner`]).optional().describe(`Switch stream layout mode and sync ?layout= in URL.`),groupBy:ur().nullable().optional().describe(`Grouping dimension (e.g. "date", "week", "notebook") or null to clear.`),resetToDefault:Ue().optional().describe(`Undo custom stream filter and restore the route default WQL query.`)}),Dpe=yr({operation:wt([`read`,`replace`,`append`,`undo`]).describe(`Read live editor buffer, replace document content, append Markdown/workout block, or undo last edit.`),content:ur().optional().describe(`Markdown or Whiteboard Script content for replace / append operations.`),save:Ue().optional().describe(`Flush and persist the draft to storage immediately after applying the edit (default false).`)}),Ope=yr({blockId:ur().optional().describe("Optional workout block ID in the active Note editor (defaults to first ```time block)."),autoStart:Ue().optional().describe(`Automatically start the timer after mounting the workout clock (default true).`)}),kpe=yr({command:wt([`next`,`playback`,`stop-request`,`stop-confirm`,`stop-cancel`,`values-open`,`entry-cancel`,`entry-save`,`entry-skip`,`reps-adjust`,`reps-set`,`reps-select`,`choice-select`,`ready-start`,`dismiss`,`status`]).describe(`Live workout clock command to dispatch (or "status" to read current ClockSnapshot).`),fieldId:ur().optional().describe(`Target fieldId for entry-save, entry-skip, or choice-select.`),value:sn().optional().describe(`Numeric value for entry-save or reps-set.`),occurrenceId:ur().optional().describe(`Rep occurrenceId for reps-adjust, reps-set, or reps-select.`),delta:Dn([r(1),r(-1)]).optional().describe(`+1 or -1 delta for reps-adjust.`),index:sn().int().min(0).optional().describe(`Zero-based alternative index for choice-select.`)}),Ape=yr({action:wt([`get`,`set`]).describe(`Read current Playground UI preferences ("get") or update preferences ("set").`),theme:wt([`light`,`dark`,`system`]).optional().describe("Color theme preference (`light`, `dark`, or `system`)."),audioEnabled:Ue().optional().describe(`Enable or mute workout timer audio cues.`),debugMode:Ue().optional().describe(`Enable or disable global runtime debug mode.`),analyticsUnit:wt([`kg`,`lb`]).optional().describe("Preferred display unit for analytics charts (`kg` or `lb`)."),leftDrawerOpen:Ue().optional().describe(`Open or close the primary navigation drawer on mobile/tablet.`),rightDrawerOpen:Ue().optional().describe(`Open or close the secondary L3 context drawer on mobile/tablet.`)}),jpe=yr({query:ur().optional().describe('WQL aggregate or find query string to set on the Metric Explorer (`/dashboards`), e.g. "sum:totalVolume{} by {week}".'),submit:Ue().optional().describe("Execute/submit the query immediately (default true when `query` is provided)."),weeks:Dn([r(4),r(8),r(16)]).optional().describe("Analytics lookback range in weeks (`4`, `8`, or `16`)."),openSaveDialog:Ue().optional().describe(`Open the "Save to dashboard" dialog for the active query.`),openQuerySettings:Ue().optional().describe("Open the surface query settings dialog on `/dashboards`.")}),Mpe=()=>((0,W.useEffect)(()=>{let e=l7({name:`ui_editor_draft`,title:`Read, Edit, or Undo Live Note Editor Buffer`,description:`Inspect or modify the live CodeMirror 6 Note buffer.`,tier:1,scope:`editor-ui`}),t=l7({name:`ui_start_live_workout`,title:`Start Live Interactive Workout Timer`,description:`Start the live interactive workout clock from the active Note editor.`,tier:1,scope:`editor-ui`});return()=>{e(),t()}},[]),vr({name:`ui_editor_draft`,title:`Read, Edit, or Undo Live Note Editor Buffer`,description:"Inspect or modify the live CodeMirror 6 Note buffer (`read`, `replace`, `append`, `undo`) with full undo support and optional immediate save (`save: true`).",inputSchema:Dpe,annotations:{title:`Edit Live Note Draft`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},async execute(e){let t=performance.now();try{let n=JK();if(!n)throw Error(`No Note editor is currently mounted.`);if(e.operation===`read`){let e=n.getValue();return{operation:`read`,noteId:n.noteId??null,readonly:n.readonly,sourceRevision:n.sourceRevision??null,content:e,workoutBlockIds:n.getBlocks().map(e=>e.id)}}if(e.operation===`undo`){let e=n.undoEdit();return await K9(),{operation:`undo`,undone:e,content:n.getValue()}}if(!e.content)throw Error(`'content' is required when operation="${e.operation}".`);let r=n.getValue(),i=e.operation===`replace`?I9(e.content):`${r.trimEnd()}\n\n${I9(e.content)}`;await n.applyEdit(i,e.save===!0),await K9();let a=JK()??n,o={operation:e.operation,saved:e.save===!0,noteId:a.noteId??null,sourceRevision:a.sourceRevision??null,workoutBlockIds:a.getBlocks().map(e=>e.id),length:a.getValue().length};return u7({toolName:`ui_editor_draft`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!0,argsPreview:JSON.stringify({operation:e.operation,save:e.save}).slice(0,120)}),o}catch(n){throw u7({toolName:`ui_editor_draft`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!1,argsPreview:JSON.stringify({operation:e.operation}).slice(0,120),error:n instanceof Error?n.message:String(n)}),n}}}),vr({name:`ui_start_live_workout`,title:`Start Live Interactive Workout Timer`,description:"Launch the live interactive workout clock on screen from a workout block in the active Note editor so the human athlete and agent can co-drive the session via `ui_clock_control`.",inputSchema:Ope,annotations:{title:`Start Live Workout Timer`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},async execute(e){let t=performance.now();try{let n=JK();if(!n)throw Error(`No Note editor is currently mounted.`);let r=await n.startLiveWorkout(e.blockId,e.autoStart??!0);if(!r.started)throw Error(r.error??`Failed to start workout timer.`);let i=Date.now()+1500;for(;!SQ()&&Date.now()<i;)await new Promise(e=>setTimeout(e,25));await K9();let a={started:!0,blockId:r.blockId??null,clock:SQ()};return u7({toolName:`ui_start_live_workout`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!0,argsPreview:JSON.stringify(e).slice(0,120)}),a}catch(n){throw u7({toolName:`ui_start_live_workout`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!1,argsPreview:JSON.stringify(e).slice(0,120),error:n instanceof Error?n.message:String(n)}),n}}}),null),Npe=()=>((0,W.useEffect)(()=>l7({name:`ui_set_explorer_query`,title:`Set or Run Analytics Explorer WQL Query`,description:`Update or run WQL queries, week windows, or dialogs on the Metric Explorer (/dashboards).`,tier:1,scope:`explorer-ui`}),[]),vr({name:`ui_set_explorer_query`,title:`Set or Run Analytics Explorer WQL Query`,description:"Set or execute an aggregate or find WQL query on the Metric Explorer (`/dashboards`), change the week window (`4`, `8`, `16`), or open the Save-to-Dashboard / Query Settings dialogs.",inputSchema:jpe,annotations:{title:`Set Analytics Explorer Query`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async execute(e){let t=performance.now();try{let n=oq();if(!n)throw Error(`Metric Explorer (/dashboards) is not currently mounted.`);e.weeks!==void 0&&n.setWeeks(e.weeks),e.query===void 0?e.submit===!0&&n.submit():(n.setDraft(e.query),e.submit!==!1&&n.submit(e.query)),e.openSaveDialog&&n.openSaveDialog(),e.openQuerySettings&&n.openQuerySettings(),await q9();let r=oq()??n,i={draft:r.draft,submitted:r.submitted,weeks:r.weeks,saveReady:r.saveReady,loading:r.loading};return u7({toolName:`ui_set_explorer_query`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!0,argsPreview:JSON.stringify(e).slice(0,120)}),i}catch(n){throw u7({toolName:`ui_set_explorer_query`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!1,argsPreview:JSON.stringify(e).slice(0,120),error:n instanceof Error?n.message:String(n)}),n}}}),null),Ppe=()=>((0,W.useEffect)(()=>l7({name:`ui_clock_control`,title:`Control Live Workout Clock`,description:`Dispatch live clock commands to the active workout timer.`,tier:1,scope:`clock-ui`}),[]),vr({name:`ui_clock_control`,title:`Control Live Workout Clock`,description:"Inspect or dispatch commands (`next`, `playback`, `ready-start`, `entry-save`, `entry-skip`, `reps-adjust`, `reps-set`, `choice-select`, `stop-request`, `stop-confirm`, `dismiss`) to the active on-screen workout clock.",inputSchema:kpe,annotations:{title:`Control Live Workout Clock`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},async execute(e,t){let n=performance.now();try{let r=SQ();if(!r)throw Error(`No live workout clock is currently mounted.`);if(e.command===`status`)return{accepted:!0,snapshot:r};if(e.command===`stop-confirm`){if(!await j9({action:`ui_clock_control:stop-confirm`,targetId:r.runId,summary:`Stop and end the active live workout timer early`},t))throw Error(`User declined early termination of the active workout timer.`);r.stopRequested||(wQ(r.runId,{kind:`stop-request`}),await K9())}let i;switch(e.command){case`entry-save`:{let t=e.fieldId??r.entry?.fieldId;if(!t||typeof e.value!=`number`)throw Error("`entry-save` requires `value` (number) and an active or explicit `fieldId`.");i={kind:`entry-save`,fieldId:t,value:e.value};break}case`entry-skip`:{let t=e.fieldId??r.entry?.fieldId;if(!t)throw Error("`entry-skip` requires `fieldId`.");i={kind:`entry-skip`,fieldId:t};break}case`reps-adjust`:{let t=e.occurrenceId??r.selectedOccurrenceId??r.reps[0]?.occurrenceId;if(!t||e.delta!==1&&e.delta!==-1)throw Error("`reps-adjust` requires `occurrenceId` and `delta` (+1 or -1).");i={kind:`reps-adjust`,occurrenceId:t,delta:e.delta};break}case`reps-set`:{let t=e.occurrenceId??r.selectedOccurrenceId??r.reps[0]?.occurrenceId;if(!t||typeof e.value!=`number`)throw Error("`reps-set` requires `occurrenceId` and integer `value`.");i={kind:`reps-set`,occurrenceId:t,value:e.value};break}case`reps-select`:if(!e.occurrenceId)throw Error("`reps-select` requires `occurrenceId`.");i={kind:`reps-select`,occurrenceId:e.occurrenceId};break;case`choice-select`:{let t=e.fieldId??r.entry?.fieldId;if(!t||typeof e.index!=`number`)throw Error("`choice-select` requires `fieldId` and `index`.");i={kind:`choice-select`,fieldId:t,index:e.index};break}default:i={kind:e.command}}let a=wQ((SQ()??r).runId,i);await K9();let o={accepted:a,command:e.command,snapshot:SQ()};return u7({toolName:`ui_clock_control`,timestamp:Date.now(),durationMs:Math.round(performance.now()-n),ok:!0,argsPreview:JSON.stringify(e).slice(0,120)}),o}catch(t){throw u7({toolName:`ui_clock_control`,timestamp:Date.now(),durationMs:Math.round(performance.now()-n),ok:!1,argsPreview:JSON.stringify(e).slice(0,120),error:t instanceof Error?t.message:String(t)}),t}}}),null),Fpe=()=>((0,W.useEffect)(()=>l7({name:`ui_set_stream_query`,title:`Set Live Stream WQL Query or Layout`,description:`Update live WQL query, layout, or grouping on the mounted stream view.`,tier:1,scope:`stream-ui`}),[]),vr({name:`ui_set_stream_query`,title:`Set Live Stream WQL Query or Layout`,description:"Update the live WQL query, layout (`cards`, `rows`, `feed`, `agenda`, `planner`), or grouping on the currently mounted stream view, or pass `resetToDefault: true` to restore the route default query.",inputSchema:Epe,annotations:{title:`Set Live Stream Query`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async execute(e){let t=performance.now();try{let n=eq();if(!n)throw Error(`No stream view is currently mounted.`);e.resetToDefault?n.setQuery(n.defaultQuery):e.query!==void 0&&n.setQuery(e.query),e.layout!==void 0&&n.setLayout(e.layout),e.groupBy!==void 0&&n.setGroupBy(e.groupBy===null?void 0:e.groupBy),await q9();let r=eq()??n,i=document.getElementById(`agent-view-state`)?.textContent,a=i?JSON.parse(i):null,o={route:r.route,query:r.query,layout:r.layout,groupBy:r.groupBy??null,totalUnbatchedCount:a?.stream?.totalUnbatchedCount??null};return u7({toolName:`ui_set_stream_query`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!0,argsPreview:JSON.stringify(e).slice(0,120)}),o}catch(n){throw u7({toolName:`ui_set_stream_query`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!1,argsPreview:JSON.stringify(e).slice(0,120),error:n instanceof Error?n.message:String(n)}),n}}}),null),J9=Symbol(`wodWrappedExecuteTool`);function Y9(e){return typeof e!=`object`||!e?!1:`name`in e&&typeof e.name==`string`&&`origin`in e&&typeof e.origin==`string`&&`window`in e&&typeof e.window==`object`}function Ipe(e){return typeof e==`object`&&!!e&&`name`in e}function Lpe(e){let t=e.arguments??e.input??e.params??e.args;if(typeof t==`string`)try{return JSON.parse(t)}catch{return{}}return t??{}}function X9(e,t){let n=t??{};if(e===`ui_navigate`&&typeof n.path!=`string`&&typeof n.href==`string`){let e=n.href.trim();if(/^https?:\/\//i.test(e))try{let t=new URL(e);e=`${t.pathname}${t.search}${t.hash}`||`/`}catch{}return{...n,path:e}}return n}async function Z9(e,t,n){if(typeof t==`string`){let n=(await e()).find(e=>Y9(e)&&e.name===t);if(n)return n}if(Y9(n))return n;throw Error(typeof t==`string`?`executeTool: no registered tool named "${t}"`:`executeTool: expected a registered tool descriptor or a { name, arguments } envelope`)}function Q9(e){if(typeof e!=`object`||!e)return;let t=e,n=t.executeTool;if(typeof n!=`function`||n[J9])return;let r=async()=>typeof t.getTools==`function`?t.getTools():typeof t.listTools==`function`?t.listTools():[],i=async(...e)=>{let[i,a]=e;if(e.length>=2&&Y9(i))return n.call(t,i,X9(i.name,a),e[2]);if(typeof i==`string`){let o=await Z9(r,i,void 0);return n.call(t,o,X9(i,a??{}),e[2])}if(Ipe(i)){let e=X9(i.name,Lpe(i)),a=await Z9(r,i.name,i);return n.call(t,a,e)}return n.apply(t,e)};i[J9]=!0,Object.defineProperty(t,"executeTool",{configurable:!0,writable:!0,value:i})}var Rpe=({spec:e})=>((0,W.useEffect)(()=>l7({name:e.name,title:e.title,description:e.description,tier:e.tier,scope:`domain`}),[e]),vr({name:e.name,title:e.title,description:e.description,inputSchema:e.inputSchema,annotations:e.annotations,async execute(t,n){let r=performance.now(),i={storage:X.storage,baseUrl:typeof window<`u`?window.location.origin:``,confirmDestructive:e=>j9(e,n),onMutated:async()=>{$M(),await TW().catch(()=>{})}};try{let n=await e.execute(t,i);return await K9(),u7({toolName:e.name,timestamp:Date.now(),durationMs:Math.round(performance.now()-r),ok:!0,argsPreview:JSON.stringify(t??{}).slice(0,120)}),n}catch(n){throw u7({toolName:e.name,timestamp:Date.now(),durationMs:Math.round(performance.now()-r),ok:!1,argsPreview:JSON.stringify(t??{}).slice(0,120),error:n instanceof Error?n.message:String(n)}),n}}}),null),zpe=()=>{let e=lt(),t=z(),n=Wq(),r=Gq(),i=mq(),a=nq(),o=cq(),s=hV(),c=XK(),l=(0,W.useSyncExternalStore)(CQ,SQ,()=>null),{theme:u,setTheme:d}=ia(),f=Eae(),{isDebugMode:p,toggleDebugMode:m}=VS(),{unit:h,setUnit:g}=RT(typeof window<`u`?window.localStorage:void 0),{navState:_,dispatch:v}=SR();return(0,W.useEffect)(()=>{if(typeof navigator<`u`&&typeof document<`u`){let e=document,t=navigator;if(e.modelContext&&!t.modelContext)try{Object.defineProperty(navigator,"modelContext",{configurable:!0,enumerable:!0,get:()=>e.modelContext})}catch{}let n=e.modelContext,r=t.modelContext;Q9(n),r!==n&&Q9(r)}},[]),(0,W.useEffect)(()=>{let e=l7({name:`ui_get_view_context`,title:`Get Active UI View Context`,description:`Read current browser route, readiness, stream results, editor, and clock.`,tier:0,scope:`global-ui`}),t=l7({name:`ui_navigate`,title:`Navigate Playground Route`,description:`Navigate the SPA router to any internal WOD Wiki path.`,tier:1,scope:`global-ui`}),n=l7({name:`ui_cast_control`,title:`Inspect or Disconnect Cast Session`,description:`Inspect or disconnect Chromecast / receiver display session.`,tier:1,scope:`global-ui`}),r=l7({name:`ui_preferences`,title:`Get or Set Playground UI Preferences`,description:`Read or update theme, audio cues, debug mode, analytics units, and mobile drawers.`,tier:1,scope:`global-ui`});return()=>{e(),t(),n(),r()}},[]),vr({name:`ui_get_view_context`,title:`Get Active UI View Context`,description:`Read the current browser route, hydration/loading state, unbatched stream results, active editor metadata, and live workout clock snapshot.`,inputSchema:Cpe,annotations:{title:`Get Active UI View Context`,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async execute(e){let d=performance.now(),m=e.includeSampleEntries!==!1,g=a&&s&&s.pathname===t.pathname?s:null,v={hydrated:document.body.dataset.appHydrated===`true`,status:i||n===`preparing`||r?`loading`:`ready`,feedReadiness:n,importPending:r,route:{pathname:t.pathname,search:t.search,hash:t.hash,href:window.location.href},stream:a?{route:a.route,query:a.query,defaultQuery:a.defaultQuery,layout:a.layout,availableLayouts:a.availableLayouts,groupBy:a.groupBy??null,loading:a.loading,totalUnbatchedCount:g?g.entries.length:null,...m&&g?{entries:g.entries.slice(0,50).map(e=>({id:e.id,title:e.title,date:e.date??null,notebookId:e.notebookId??null}))}:{}}:null,editor:c?{noteId:c.noteId??null,readonly:c.readonly,sourceRevision:c.sourceRevision??null,workoutBlockIds:c.getBlocks().map(e=>e.id)}:null,explorer:o?{draft:o.draft,submitted:o.submitted,weeks:o.weeks,loading:o.loading,saveReady:o.saveReady}:null,preferences:{theme:u,audioEnabled:f?.isEnabled??!1,debugMode:p,analyticsUnit:h,leftDrawerOpen:_.leftDrawerOpen,rightDrawerOpen:_.rightDrawerOpen},clock:l};return u7({toolName:`ui_get_view_context`,timestamp:Date.now(),durationMs:Math.round(performance.now()-d),ok:!0,argsPreview:JSON.stringify(e).slice(0,120)}),v}}),vr({name:`ui_navigate`,title:`Navigate Playground Route`,description:"Navigate the React Router SPA to any WOD Wiki route (`/journal`, `/day/:date`, `/note/:id`, `/notebooks`, `/dashboards`, `/run/:id?note=:noteId`) and wait for UI commit.",inputSchema:wpe,annotations:{title:`Navigate Route`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async execute(t){let n=performance.now(),r=t.path.startsWith(`/`)?t.path:`/${t.path}`;e(r,{replace:t.replace===!0}),await K9();let i={navigatedTo:r,href:window.location.href};return u7({toolName:`ui_navigate`,timestamp:Date.now(),durationMs:Math.round(performance.now()-n),ok:!0,argsPreview:JSON.stringify(t).slice(0,120)}),i}}),vr({name:`ui_cast_control`,title:`Inspect or Disconnect Cast Session`,description:`Check active Chromecast / receiver display session state or cleanly disconnect an active Cast session.`,inputSchema:Tpe,annotations:{title:`Cast Session Control`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async execute(e){let t=performance.now(),n=qZ(),r=iQ.getActiveHandle();e.action===`disconnect`&&r&&(iQ.dispose(!0),VF(null),await K9());let i={action:e.action,backendState:n.state,connected:!!iQ.getActiveHandle()};return u7({toolName:`ui_cast_control`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!0,argsPreview:JSON.stringify(e).slice(0,120)}),i}}),vr({name:`ui_preferences`,title:`Get or Set Playground UI Preferences`,description:"Read or update global Playground UI preferences (`theme`, `audioEnabled`, `debugMode`, `analyticsUnit`, and mobile navigation drawers).",inputSchema:Ape,annotations:{title:`Playground UI Preferences`,readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async execute(e){let t=performance.now(),n=u,r=f?.isEnabled??!1,i=p,a=h,o=_.leftDrawerOpen,s=_.rightDrawerOpen;e.action===`set`&&(e.theme!==void 0&&e.theme!==u&&(d(e.theme),n=e.theme),e.audioEnabled!==void 0&&f&&e.audioEnabled!==f.isEnabled&&(f.toggleAudio(),r=e.audioEnabled),e.debugMode!==void 0&&e.debugMode!==p&&(m(),i=e.debugMode),e.analyticsUnit!==void 0&&e.analyticsUnit!==h&&(g(e.analyticsUnit),a=e.analyticsUnit),e.leftDrawerOpen!==void 0&&(v({type:`SET_LEFT_DRAWER`,open:e.leftDrawerOpen}),o=e.leftDrawerOpen),e.rightDrawerOpen!==void 0&&(v({type:`SET_RIGHT_DRAWER`,open:e.rightDrawerOpen}),s=e.rightDrawerOpen),await K9());let c={theme:n,audioEnabled:r,debugMode:i,analyticsUnit:a,leftDrawerOpen:o,rightDrawerOpen:s};return u7({toolName:`ui_preferences`,timestamp:Date.now(),durationMs:Math.round(performance.now()-t),ok:!0,argsPreview:JSON.stringify(e).slice(0,120)}),c}}),(0,G.jsxs)(G.Fragment,{children:[G9.map(e=>(0,G.jsx)(Rpe,{spec:e},e.name)),a&&(0,G.jsx)(Fpe,{stream:a}),o&&(0,G.jsx)(Npe,{explorer:o}),c&&(0,G.jsx)(Mpe,{editor:c}),l&&(0,G.jsx)(Ppe,{clock:l})]})};function Bpe(){let{pathname:e,hash:t}=z(),{scrollToSection:n}=SR();return(0,W.useEffect)(()=>{if($H(e),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 Vpe(){return epe(),w9(),(0,W.useEffect)(()=>{mN.current().catch(console.error),iN(),Jq(),cF().catch(()=>{}),V5().catch(()=>{})},[]),null}function $9({settling:e}){let t=Kq();if(e){let e=gq(t);return(0,G.jsxs)(`div`,{role:`status`,className:`flex min-h-dvh flex-col items-center justify-center gap-2 text-muted-foreground`,children:[(0,G.jsx)(`span`,{children:t?hq(t):`Loading library…`}),e&&(0,G.jsx)(`span`,{className:`text-xs`,"data-testid":`boot-progress-detail`,children:e})]})}return(0,G.jsxs)(`div`,{role:`alert`,className:`flex min-h-dvh flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,G.jsx)(`p`,{className:`text-sm font-semibold`,children:`The library's routed content failed to load.`}),(0,G.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,G.jsx)(q,{variant:`outline`,size:`sm`,"data-testid":`root-refeed`,onClick:()=>{kL().then(()=>$M())},children:`Re-import library`})]})}function Hpe(){let e=(0,W.useRef)(()=>{}),t=nW(),n=Wq(),r=(0,W.useMemo)(()=>TU(()=>e.current(),t),[t]);return(0,G.jsx)(ra,{defaultTheme:`system`,storageKey:`wod-wiki-playground-theme`,children:(0,G.jsx)(Tre,{children:(0,G.jsx)(GL,{children:(0,G.jsx)(YL,{children:(0,G.jsx)(Tae,{children:(0,G.jsx)(ae,{children:(0,G.jsxs)(M,{children:[(0,G.jsx)(Vpe,{}),(0,G.jsx)(_R,{}),(0,G.jsxs)(wR,{tree:r,children:[(0,G.jsx)(Bpe,{}),(0,G.jsx)(zpe,{}),(0,G.jsx)(npe,{}),(0,G.jsx)(ipe,{}),(0,G.jsxs)(f,{children:[(0,G.jsx)(Kr,{path:Q.home,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:`*`,element:t.length===0?(0,G.jsx)($9,{settling:n===`preparing`||uL()&&n!==`error`}):(0,G.jsx)(Pde,{})}),(0,G.jsx)(Kr,{path:`/proto/calc-authoring`,element:(0,G.jsx)(Kde,{})}),(0,G.jsx)(Kr,{path:`/proto/query-block-composer`,element:(0,G.jsx)(nfe,{})}),(0,G.jsx)(Kr,{path:`/settings`,element:(0,G.jsx)(Je,{to:`/settings/appearance`,replace:!0})}),(0,G.jsx)(Kr,{path:`/settings/appearance`,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.settingsProfile,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.settingsData,element:(0,G.jsx)(Je,{to:Q.settingsStorage,replace:!0})}),(0,G.jsx)(Kr,{path:Q.settingsDatabase,element:(0,G.jsx)(Je,{to:Q.settingsStorage,replace:!0})}),(0,G.jsx)(Kr,{path:Q.settingsStorage,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.settingsSync,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:`/settings/system`,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.settingsQueries,element:(0,G.jsx)(Je,{to:Q.journal,replace:!0})}),(0,G.jsx)(Kr,{path:Q.settingsTags,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.settingsSoundProfiles,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:`/settings/library/calcs`,element:(0,G.jsx)(`div`,{className:`p-6`,children:(0,G.jsx)(Rfe,{})})}),(0,G.jsx)(Kr,{path:`/legacy`,element:(0,G.jsx)(bde,{})}),(0,G.jsx)(Kr,{path:`/syntax`,element:(0,G.jsx)(Nde,{})}),(0,G.jsx)(Kr,{path:Q.plan,element:(0,G.jsx)(fde,{})}),(0,G.jsx)(Kr,{path:Q.feeds,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.feed,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.notebooks,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.notebook,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.notebookTarget,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.notebookItem,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.subscribe,element:(0,G.jsx)(Jfe,{})}),(0,G.jsx)(Kr,{path:Q.pages,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.page,element:t.length===0&&(n===`preparing`||uL()&&n!==`error`)?(0,G.jsx)($9,{settling:!0}):(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.load,element:(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,G.jsx)(Vfe,{})})}),(0,G.jsx)(Kr,{path:Q.loadJournal,element:(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,G.jsx)(T9,{})})}),(0,G.jsx)(Kr,{path:Q.loadJournalDate,element:(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,G.jsx)(T9,{})})}),(0,G.jsx)(Kr,{path:Q.playgroundRoot,element:(0,G.jsx)($fe,{})}),(0,G.jsx)(Kr,{path:Q.playground,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.playgrounds,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.notes,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.note,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.journal,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.day,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.run,element:(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,G.jsx)(Xfe,{})})}),(0,G.jsx)(Kr,{path:Q.tracker,element:(0,G.jsx)(dde,{})}),(0,G.jsx)(Kr,{path:`/results/segments`,element:(0,G.jsx)(ude,{})}),(0,G.jsx)(Kr,{path:Q.sessionDetail,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.sessions,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.sessionDate,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:`/review/:runtimeId`,element:(0,G.jsx)(x7,{})}),(0,G.jsx)(Kr,{path:`/note/:noteId/review`,element:(0,G.jsx)(x7,{})}),(0,G.jsx)(Kr,{path:`/note/:noteId/review/:sectionId`,element:(0,G.jsx)(x7,{})}),(0,G.jsx)(Kr,{path:`/note/:noteId/review/:sectionId/:resultId`,element:(0,G.jsx)(x7,{})}),(0,G.jsx)(Kr,{path:Q.efforts,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.effort,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.equipment,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.equipmentSlug,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.tags,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.tagCategory,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.tag,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.dashboards,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),(0,G.jsx)(Kr,{path:Q.dashboardView,element:(0,G.jsx)(b7,{searchHandlerRef:e})}),t.map(({route:t})=>(0,G.jsx)(Kr,{path:t,element:(0,G.jsx)(b7,{searchHandlerRef:e})},t))]}),(0,G.jsx)(pde,{})]})]})})})})})})})}function Upe({error:e,onRetry:t}){let n=e instanceof Error?e.message:String(e);return dN(),(0,G.jsxs)(`div`,{role:`alert`,className:`flex min-h-dvh flex-col items-center justify-center gap-4 p-6 text-center`,children:[(0,G.jsx)(`p`,{className:`text-sm font-semibold`,children:`The API data store could not be opened.`}),(0,G.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground font-mono break-all`,"data-testid":`boot-recovery-error`,children:n}),(0,G.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.`,!1]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,G.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`}),!1]}),!1]})}function Wpe(){let e=(0,W.useSyncExternalStore)(Aw,kw),t=e.phase===`updating`;return(0,G.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,G.jsx)(`p`,{className:`text-sm font-semibold`,children:t?`Updating local database…`:`Checking for storage updates…`}),t&&e.fromVersion!==null&&(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Schema v`,e.fromVersion,` → v`,e.toVersion]}),e.message&&(0,G.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:e.message})]})}var Gpe=(0,ta.createRoot)(document.getElementById(`root`));function Kpe(){let[e,t]=(0,W.useState)(!1),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(0),o=(0,W.useSyncExternalStore)(Aw,kw);return(0,W.useEffect)(()=>{let e=!1,n;return bN().then(()=>FP?Xie():void 0).then(()=>PP.ensureNotebooks().catch(e=>HN(`NotebookService`,`ensureNotebooks failed`,e))).then(()=>{e||(n=CN(),t(!0))}).catch(t=>{e||r(t)}),()=>{e=!0,n?.()}},[i]),(0,W.useEffect)(()=>{if(!e){delete document.body.dataset.appHydrated;return}return document.body.dataset.appHydrated=`true`,()=>{delete document.body.dataset.appHydrated}},[e]),n?(0,G.jsx)(Upe,{error:n,onRetry:()=>{r(null),a(e=>e+1)}}):o.phase===`checking`||o.phase===`updating`?(0,G.jsx)(Wpe,{}):e?(0,G.jsx)(Hpe,{}):(0,G.jsx)(`div`,{role:`status`,className:`flex min-h-dvh items-center justify-center text-muted-foreground`,children:`Opening local library…`})}Gpe.render((0,G.jsx)(W.StrictMode,{children:(0,G.jsx)(Kpe,{})}));export{FJ as t};
1161
- //# sourceMappingURL=main-BwcFpdxj.js.map
1161
+ //# sourceMappingURL=main-B434yd-K.js.map