@wix/himalaya-cli 0.1749.0 → 0.1751.0

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 (324) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +3 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/himi-package.d.ts +478 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/host-compatibility.d.ts +56 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/icon-catalog.generated.d.ts +1 -1
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +4 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-shell.d.ts +156 -8
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/validator.d.ts +3 -0
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/index.d.ts +2 -0
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/podcast-service.d.ts +105 -0
  10. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/podcast.d.ts +116 -0
  11. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +326 -13
  12. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +730 -81
  13. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +155 -0
  14. package/dist/browser-plane/assets.json +5 -5
  15. package/dist/browser-plane/preview-deferred/{b40ea5d0d6251898ff5617139fde8be008dd11e99a70b14c1052093685401700.bin → 21f35a12bd94f4ab97a9a75453c4adcadc438daf024a4b1950d5c356c123bd01.bin} +1 -1
  16. package/dist/browser-plane/sw.js +7 -7
  17. package/dist/cli.mjs +44618 -35753
  18. package/dist/preview-assets.generated.bin +0 -0
  19. package/guides/component-reference.json +1 -1
  20. package/guides/component-reference.md +4 -0
  21. package/guides/designing-himi-screens.md +7 -0
  22. package/guides/getting-started.md +5 -1
  23. package/guides/headless-loop.md +1 -1
  24. package/guides/himi-json-output.md +54 -1
  25. package/guides/himi-skill.md +5 -1
  26. package/guides/index.json +6 -0
  27. package/guides/one-app-to-himi-app.md +31 -8
  28. package/guides/qa-builds.md +12 -1
  29. package/guides/recipe-podcast.md +149 -0
  30. package/guides/skill.md +3 -1
  31. package/guides/store-submission.md +149 -34
  32. package/guides/tier-5-add-a-screen.md +16 -2
  33. package/guides/wix-business-context.md +43 -0
  34. package/guides/wix-platform-usage.md +7 -2
  35. package/package.json +10 -10
  36. package/template-icons/fitness-gym.png +0 -0
  37. package/template-icons/personal-fitness-trainer.png +0 -0
  38. package/templates/beauty-salon/config.ts +12 -0
  39. package/templates/beauty-salon/dev/index.ts +1 -1
  40. package/templates/beauty-salon/l10n/en.json +1 -1
  41. package/templates/beauty-salon/tier5-src/_shared/booking-session.ts +3 -1
  42. package/templates/beauty-salon/tier5-src/_shared/business-chat-transport.ts +148 -0
  43. package/templates/beauty-salon/tier5-src/_shared/header-badges.ts +113 -0
  44. package/templates/beauty-salon/tier5-src/_shared/location-pin.ts +97 -0
  45. package/templates/beauty-salon/tier5-src/_shared/member-access.ts +17 -6
  46. package/templates/beauty-salon/tier5-src/_shared/program-fields.ts +16 -0
  47. package/templates/beauty-salon/tier5-src/_shared/programs-section.ts +5 -8
  48. package/templates/beauty-salon/tier5-src/_shared/source-badges.ts +72 -0
  49. package/templates/beauty-salon/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  50. package/templates/beauty-salon/tier5-src/himi-branded-lite-nav/index.ts +152 -0
  51. package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +13 -4
  52. package/templates/beauty-salon/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  53. package/templates/branded-lite/config.ts +12 -0
  54. package/templates/branded-lite/dev/index.ts +101 -1
  55. package/templates/branded-lite/l10n/en.json +22 -1
  56. package/templates/branded-lite/l10n/es.json +22 -0
  57. package/templates/branded-lite/l10n/fr.json +23 -0
  58. package/templates/branded-lite/l10n/he.json +19 -0
  59. package/templates/branded-lite/tier5-src/_shared/booking-session.ts +3 -1
  60. package/templates/branded-lite/tier5-src/_shared/location-pin.ts +97 -0
  61. package/templates/branded-lite/tier5-src/_shared/member-access.ts +17 -6
  62. package/templates/branded-lite/tier5-src/_shared/program-fields.ts +16 -0
  63. package/templates/branded-lite/tier5-src/_shared/programs-section.ts +5 -8
  64. package/templates/branded-lite/tier5-src/himi-branded-lite-access-nav/index.ts +10 -5
  65. package/templates/branded-lite/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  66. package/templates/branded-lite/tier5-src/himi-branded-lite-nav/index.ts +152 -0
  67. package/templates/branded-lite/tier5-src/himi-branded-lite-podcasts/index.ts +14 -234
  68. package/templates/branded-lite/tier5-src/himi-branded-lite-video/index.ts +12 -1
  69. package/templates/branded-lite/tier5-src/himi-store-account/index.ts +13 -4
  70. package/templates/branded-lite/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  71. package/templates/brandy/README.md +33 -0
  72. package/templates/brandy/config.ts +51 -7
  73. package/templates/brandy/dev/index.ts +23 -9
  74. package/templates/community-club/l10n/en.json +1 -1
  75. package/templates/community-club/tier5-src/_shared/member-access.ts +17 -6
  76. package/templates/community-club/tier5-src/_shared/program-fields.ts +16 -0
  77. package/templates/community-club/tier5-src/_shared/programs-section.ts +5 -8
  78. package/templates/community-club/tier5-src/himi-store-account/index.ts +13 -4
  79. package/templates/community-club/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  80. package/templates/conference/tier5-src/_shared/member-access.ts +17 -6
  81. package/templates/conference/tier5-src/himi-store-account/index.ts +13 -4
  82. package/templates/events-meetups/l10n/en.json +1 -1
  83. package/templates/events-meetups/tier5-src/_shared/member-access.ts +17 -6
  84. package/templates/events-meetups/tier5-src/_shared/program-fields.ts +16 -0
  85. package/templates/events-meetups/tier5-src/_shared/programs-section.ts +5 -8
  86. package/templates/events-meetups/tier5-src/himi-store-account/index.ts +13 -4
  87. package/templates/events-meetups/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  88. package/templates/fitness-gym/README.md +53 -0
  89. package/templates/fitness-gym/config.ts +560 -0
  90. package/templates/fitness-gym/dev/index.ts +25787 -0
  91. package/templates/fitness-gym/himalaya.content.json +64 -0
  92. package/templates/fitness-gym/himalaya.template.json +15 -0
  93. package/templates/fitness-gym/icon.png +0 -0
  94. package/templates/fitness-gym/platforms.json +1 -0
  95. package/templates/fitness-gym/tier5-src/_shared/app-locale.ts +61 -0
  96. package/templates/fitness-gym/tier5-src/_shared/booking-location.ts +147 -0
  97. package/templates/fitness-gym/tier5-src/_shared/booking-session.ts +224 -0
  98. package/templates/fitness-gym/tier5-src/_shared/branded-lite-hosted.ts +280 -0
  99. package/templates/fitness-gym/tier5-src/_shared/branded-load-state.ts +109 -0
  100. package/templates/fitness-gym/tier5-src/_shared/business-chat-copy.ts +40 -0
  101. package/templates/fitness-gym/tier5-src/_shared/business-chat-history.ts +51 -0
  102. package/templates/fitness-gym/tier5-src/_shared/business-chat-message-model.ts +177 -0
  103. package/templates/fitness-gym/tier5-src/_shared/business-chat-model.ts +56 -0
  104. package/templates/fitness-gym/tier5-src/_shared/business-chat-presenter.ts +576 -0
  105. package/templates/fitness-gym/tier5-src/_shared/business-chat-transport.ts +148 -0
  106. package/templates/fitness-gym/tier5-src/_shared/collection-contract.ts +228 -0
  107. package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +193 -0
  108. package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +400 -0
  109. package/templates/fitness-gym/tier5-src/_shared/detail-presence.ts +51 -0
  110. package/templates/fitness-gym/tier5-src/_shared/engine-intl.ts +523 -0
  111. package/templates/fitness-gym/tier5-src/_shared/himi-account.ts +194 -0
  112. package/templates/fitness-gym/tier5-src/_shared/himi-booking-saved.ts +88 -0
  113. package/templates/fitness-gym/tier5-src/_shared/himi-bookings.ts +318 -0
  114. package/templates/fitness-gym/tier5-src/_shared/himi-copy.ts +116 -0
  115. package/templates/fitness-gym/tier5-src/_shared/himi-media.ts +29 -0
  116. package/templates/fitness-gym/tier5-src/_shared/himi-store.ts +7 -0
  117. package/templates/fitness-gym/tier5-src/_shared/himi-text.ts +24 -0
  118. package/templates/fitness-gym/tier5-src/_shared/host-events.ts +66 -0
  119. package/templates/fitness-gym/tier5-src/_shared/hosted-checkout.ts +70 -0
  120. package/templates/fitness-gym/tier5-src/_shared/iap-attendance-form.ts +106 -0
  121. package/templates/fitness-gym/tier5-src/_shared/iap-attendance-purchase.ts +216 -0
  122. package/templates/fitness-gym/tier5-src/_shared/iap-attendance.ts +38 -0
  123. package/templates/fitness-gym/tier5-src/_shared/iap-worker.ts +127 -0
  124. package/templates/fitness-gym/tier5-src/_shared/inbox-rooms.ts +68 -0
  125. package/templates/fitness-gym/tier5-src/_shared/local-preferences.ts +38 -0
  126. package/templates/fitness-gym/tier5-src/_shared/member-access.ts +63 -0
  127. package/templates/fitness-gym/tier5-src/_shared/member-account-routes.ts +52 -0
  128. package/templates/fitness-gym/tier5-src/_shared/member-bookings.ts +107 -0
  129. package/templates/fitness-gym/tier5-src/_shared/member-screen.ts +99 -0
  130. package/templates/fitness-gym/tier5-src/_shared/notification-target.ts +141 -0
  131. package/templates/fitness-gym/tier5-src/_shared/offset-page.ts +10 -0
  132. package/templates/fitness-gym/tier5-src/_shared/online-actions.ts +76 -0
  133. package/templates/fitness-gym/tier5-src/_shared/owner-load-error.ts +348 -0
  134. package/templates/fitness-gym/tier5-src/_shared/payment-setup.ts +6 -0
  135. package/templates/fitness-gym/tier5-src/_shared/pricing-plan-display.ts +64 -0
  136. package/templates/fitness-gym/tier5-src/_shared/program-description.ts +11 -0
  137. package/templates/fitness-gym/tier5-src/_shared/program-fields.ts +16 -0
  138. package/templates/fitness-gym/tier5-src/_shared/program-standing.ts +46 -0
  139. package/templates/fitness-gym/tier5-src/_shared/rich-body.ts +78 -0
  140. package/templates/fitness-gym/tier5-src/_shared/rich-content-link.ts +34 -0
  141. package/templates/fitness-gym/tier5-src/_shared/sign-in-sheet.ts +18 -0
  142. package/templates/fitness-gym/tier5-src/_shared/staff-name.ts +18 -0
  143. package/templates/fitness-gym/tier5-src/_shared/weekly-goal.ts +107 -0
  144. package/templates/fitness-gym/tier5-src/_shared/wix-bi.ts +85 -0
  145. package/templates/fitness-gym/tier5-src/_shared/wix-member-links.ts +114 -0
  146. package/templates/fitness-gym/tier5-src/_shared/wix-service-price.ts +146 -0
  147. package/templates/fitness-gym/tier5-src/business-chat/index.ts +732 -0
  148. package/templates/fitness-gym/tier5-src/business-contact/index.ts +6 -0
  149. package/templates/fitness-gym/tier5-src/himi-booking-account/index.ts +267 -0
  150. package/templates/fitness-gym/tier5-src/himi-booking-bookings/index.ts +468 -0
  151. package/templates/fitness-gym/tier5-src/himi-booking-service/index.ts +1190 -0
  152. package/templates/fitness-gym/tier5-src/himi-booking-services/index.ts +791 -0
  153. package/templates/fitness-gym/tier5-src/himi-booking-time/index.ts +1729 -0
  154. package/templates/fitness-gym/tier5-src/himi-branded-lite-agenda/index.ts +988 -0
  155. package/templates/fitness-gym/tier5-src/himi-branded-lite-member-programs/index.ts +656 -0
  156. package/templates/fitness-gym/tier5-src/himi-branded-lite-notifications/index.ts +256 -0
  157. package/templates/fitness-gym/tier5-src/himi-branded-lite-plans/index.ts +495 -0
  158. package/templates/fitness-gym/tier5-src/himi-branded-lite-program/facts.ts +52 -0
  159. package/templates/fitness-gym/tier5-src/himi-branded-lite-program/index.ts +845 -0
  160. package/templates/fitness-gym/tier5-src/himi-fitcoach-goal/index.ts +191 -0
  161. package/templates/fitness-gym/tier5-src/himi-fitcoach-home/index.ts +619 -0
  162. package/templates/fitness-gym/tier5-src/himi-store-account/index.ts +1007 -0
  163. package/templates/fitness-gym/tier5-src/wix-spaces-my-subscriptions/index.ts +84 -0
  164. package/templates/fitness-gym/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
  165. package/templates/fitness-gym/tokens.json +414 -0
  166. package/templates/gym-fitness/config.ts +12 -0
  167. package/templates/gym-fitness/dev/index.ts +1 -1
  168. package/templates/gym-fitness/l10n/en.json +1 -1
  169. package/templates/gym-fitness/tier5-src/_shared/booking-session.ts +3 -1
  170. package/templates/gym-fitness/tier5-src/_shared/business-chat-transport.ts +148 -0
  171. package/templates/gym-fitness/tier5-src/_shared/header-badges.ts +113 -0
  172. package/templates/gym-fitness/tier5-src/_shared/location-pin.ts +97 -0
  173. package/templates/gym-fitness/tier5-src/_shared/member-access.ts +17 -6
  174. package/templates/gym-fitness/tier5-src/_shared/program-fields.ts +16 -0
  175. package/templates/gym-fitness/tier5-src/_shared/programs-section.ts +5 -8
  176. package/templates/gym-fitness/tier5-src/_shared/source-badges.ts +72 -0
  177. package/templates/gym-fitness/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  178. package/templates/gym-fitness/tier5-src/himi-branded-lite-nav/index.ts +152 -0
  179. package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +13 -4
  180. package/templates/gym-fitness/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  181. package/templates/medical-services/dev/index.ts +2 -1
  182. package/templates/medical-services/tier5-src/_shared/booking-session.ts +3 -1
  183. package/templates/medical-services/tier5-src/_shared/member-access.ts +17 -6
  184. package/templates/medical-services/tier5-src/himi-booking-account/index.ts +16 -1
  185. package/templates/medical-services/tier5-src/himi-store-account/index.ts +13 -4
  186. package/templates/nonprofit-cause/l10n/en.json +1 -1
  187. package/templates/nonprofit-cause/tier5-src/_shared/member-access.ts +17 -6
  188. package/templates/nonprofit-cause/tier5-src/_shared/program-fields.ts +16 -0
  189. package/templates/nonprofit-cause/tier5-src/_shared/programs-section.ts +5 -8
  190. package/templates/nonprofit-cause/tier5-src/himi-store-account/index.ts +13 -4
  191. package/templates/nonprofit-cause/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  192. package/templates/personal-fitness-trainer/README.md +51 -0
  193. package/templates/personal-fitness-trainer/config.ts +343 -0
  194. package/templates/personal-fitness-trainer/dev/index.ts +24813 -0
  195. package/templates/personal-fitness-trainer/himalaya.content.json +79 -0
  196. package/templates/personal-fitness-trainer/himalaya.template.json +14 -0
  197. package/templates/personal-fitness-trainer/icon.png +0 -0
  198. package/templates/personal-fitness-trainer/platforms.json +3 -0
  199. package/templates/personal-fitness-trainer/splash.json +3 -0
  200. package/templates/personal-fitness-trainer/tier5-src/_shared/app-locale.ts +61 -0
  201. package/templates/personal-fitness-trainer/tier5-src/_shared/booking-location.ts +147 -0
  202. package/templates/personal-fitness-trainer/tier5-src/_shared/booking-session.ts +224 -0
  203. package/templates/personal-fitness-trainer/tier5-src/_shared/branded-lite-hosted.ts +280 -0
  204. package/templates/personal-fitness-trainer/tier5-src/_shared/branded-load-state.ts +109 -0
  205. package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-copy.ts +40 -0
  206. package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-history.ts +51 -0
  207. package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-message-model.ts +177 -0
  208. package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-model.ts +56 -0
  209. package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-presenter.ts +576 -0
  210. package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-transport.ts +148 -0
  211. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-contract.ts +228 -0
  212. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +193 -0
  213. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +400 -0
  214. package/templates/personal-fitness-trainer/tier5-src/_shared/detail-presence.ts +51 -0
  215. package/templates/personal-fitness-trainer/tier5-src/_shared/empty-flags.ts +33 -0
  216. package/templates/personal-fitness-trainer/tier5-src/_shared/engine-intl.ts +523 -0
  217. package/templates/personal-fitness-trainer/tier5-src/_shared/himi-account.ts +194 -0
  218. package/templates/personal-fitness-trainer/tier5-src/_shared/himi-booking-saved.ts +88 -0
  219. package/templates/personal-fitness-trainer/tier5-src/_shared/himi-bookings.ts +318 -0
  220. package/templates/personal-fitness-trainer/tier5-src/_shared/himi-copy.ts +116 -0
  221. package/templates/personal-fitness-trainer/tier5-src/_shared/himi-layouts.ts +142 -0
  222. package/templates/personal-fitness-trainer/tier5-src/_shared/himi-store.ts +7 -0
  223. package/templates/personal-fitness-trainer/tier5-src/_shared/himi-text.ts +24 -0
  224. package/templates/personal-fitness-trainer/tier5-src/_shared/host-events.ts +66 -0
  225. package/templates/personal-fitness-trainer/tier5-src/_shared/hosted-checkout.ts +70 -0
  226. package/templates/personal-fitness-trainer/tier5-src/_shared/iap-attendance-form.ts +106 -0
  227. package/templates/personal-fitness-trainer/tier5-src/_shared/iap-attendance-purchase.ts +216 -0
  228. package/templates/personal-fitness-trainer/tier5-src/_shared/iap-attendance.ts +38 -0
  229. package/templates/personal-fitness-trainer/tier5-src/_shared/iap-worker.ts +127 -0
  230. package/templates/personal-fitness-trainer/tier5-src/_shared/inbox-rooms.ts +68 -0
  231. package/templates/personal-fitness-trainer/tier5-src/_shared/local-preferences.ts +38 -0
  232. package/templates/personal-fitness-trainer/tier5-src/_shared/member-access.ts +63 -0
  233. package/templates/personal-fitness-trainer/tier5-src/_shared/member-account-routes.ts +52 -0
  234. package/templates/personal-fitness-trainer/tier5-src/_shared/member-bookings.ts +107 -0
  235. package/templates/personal-fitness-trainer/tier5-src/_shared/member-screen.ts +99 -0
  236. package/templates/personal-fitness-trainer/tier5-src/_shared/offset-page.ts +10 -0
  237. package/templates/personal-fitness-trainer/tier5-src/_shared/online-actions.ts +76 -0
  238. package/templates/personal-fitness-trainer/tier5-src/_shared/owner-load-error.ts +348 -0
  239. package/templates/personal-fitness-trainer/tier5-src/_shared/payment-setup.ts +6 -0
  240. package/templates/personal-fitness-trainer/tier5-src/_shared/pricing-plan-display.ts +64 -0
  241. package/templates/personal-fitness-trainer/tier5-src/_shared/rich-body.ts +78 -0
  242. package/templates/personal-fitness-trainer/tier5-src/_shared/rich-content-link.ts +34 -0
  243. package/templates/personal-fitness-trainer/tier5-src/_shared/sign-in-sheet.ts +18 -0
  244. package/templates/personal-fitness-trainer/tier5-src/_shared/staff-name.ts +18 -0
  245. package/templates/personal-fitness-trainer/tier5-src/_shared/video-caption.ts +21 -0
  246. package/templates/personal-fitness-trainer/tier5-src/_shared/weekly-goal.ts +107 -0
  247. package/templates/personal-fitness-trainer/tier5-src/_shared/wix-bi.ts +85 -0
  248. package/templates/personal-fitness-trainer/tier5-src/_shared/wix-service-price.ts +146 -0
  249. package/templates/personal-fitness-trainer/tier5-src/business-chat/index.ts +732 -0
  250. package/templates/personal-fitness-trainer/tier5-src/business-contact/index.ts +6 -0
  251. package/templates/personal-fitness-trainer/tier5-src/himi-booking-bookings/index.ts +468 -0
  252. package/templates/personal-fitness-trainer/tier5-src/himi-booking-service/index.ts +1190 -0
  253. package/templates/personal-fitness-trainer/tier5-src/himi-booking-services/index.ts +791 -0
  254. package/templates/personal-fitness-trainer/tier5-src/himi-booking-time/index.ts +1729 -0
  255. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +242 -0
  256. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-account-settings/index.ts +1094 -0
  257. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-agenda/index.ts +988 -0
  258. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-appearance/index.ts +94 -0
  259. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-notifsettings/index.ts +173 -0
  260. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-plans/index.ts +495 -0
  261. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-splash/index.ts +35 -0
  262. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-video/index.ts +226 -0
  263. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-videos/index.ts +145 -0
  264. package/templates/personal-fitness-trainer/tier5-src/himi-fitness-trainer-home/index.ts +70 -0
  265. package/templates/personal-fitness-trainer/tier5-src/himi-fitness-trainer-profile/index.ts +53 -0
  266. package/templates/personal-fitness-trainer/tier5-src/himi-store-account/index.ts +1007 -0
  267. package/templates/personal-fitness-trainer/tier5-src/wix-spaces-app-language/index.ts +73 -0
  268. package/templates/personal-fitness-trainer/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  269. package/templates/personal-fitness-trainer/tier5-src/wix-spaces-my-subscriptions/index.ts +84 -0
  270. package/templates/personal-fitness-trainer/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
  271. package/templates/personal-fitness-trainer/tier5-src/wix-spaces-view-profile/index.ts +119 -0
  272. package/templates/personal-fitness-trainer/tokens.json +381 -0
  273. package/templates/podcast-creator/dev/index.ts +100 -0
  274. package/templates/podcast-creator/l10n/en.json +22 -1
  275. package/templates/podcast-creator/l10n/es.json +22 -0
  276. package/templates/podcast-creator/l10n/fr.json +18 -0
  277. package/templates/podcast-creator/l10n/he.json +15 -0
  278. package/templates/podcast-creator/tier5-src/_shared/member-access.ts +17 -6
  279. package/templates/podcast-creator/tier5-src/_shared/program-fields.ts +16 -0
  280. package/templates/podcast-creator/tier5-src/_shared/programs-section.ts +5 -8
  281. package/templates/podcast-creator/tier5-src/himi-branded-lite-podcasts/index.ts +14 -234
  282. package/templates/podcast-creator/tier5-src/himi-store-account/index.ts +13 -4
  283. package/templates/podcast-creator/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  284. package/templates/portfolio-creative/l10n/en.json +1 -1
  285. package/templates/portfolio-creative/tier5-src/_shared/member-access.ts +17 -6
  286. package/templates/portfolio-creative/tier5-src/_shared/program-fields.ts +16 -0
  287. package/templates/portfolio-creative/tier5-src/_shared/programs-section.ts +5 -8
  288. package/templates/portfolio-creative/tier5-src/himi-store-account/index.ts +13 -4
  289. package/templates/portfolio-creative/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  290. package/templates/restaurant/l10n/en.json +1 -1
  291. package/templates/restaurant/tier5-src/_shared/member-access.ts +17 -6
  292. package/templates/restaurant/tier5-src/_shared/program-fields.ts +16 -0
  293. package/templates/restaurant/tier5-src/_shared/programs-section.ts +5 -8
  294. package/templates/restaurant/tier5-src/himi-store-account/index.ts +13 -4
  295. package/templates/restaurant/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  296. package/templates/retail-store/l10n/en.json +1 -1
  297. package/templates/retail-store/tier5-src/_shared/member-access.ts +17 -6
  298. package/templates/retail-store/tier5-src/_shared/program-fields.ts +16 -0
  299. package/templates/retail-store/tier5-src/_shared/programs-section.ts +5 -8
  300. package/templates/retail-store/tier5-src/himi-store-account/index.ts +13 -4
  301. package/templates/retail-store/tier5-src/wix-spaces-view-profile/index.ts +68 -55
  302. package/templates/salon-spa/dev/index.ts +1 -1
  303. package/templates/salon-spa/tier5-src/_shared/booking-session.ts +3 -1
  304. package/templates/salon-spa/tier5-src/_shared/member-access.ts +17 -6
  305. package/templates/salon-spa/tier5-src/himi-booking-account/index.ts +16 -1
  306. package/templates/salon-spa/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  307. package/templates/salon-spa/tier5-src/himi-store-account/index.ts +13 -4
  308. package/templates/wholesale-store/tier5-src/_shared/member-access.ts +17 -6
  309. package/templates/wholesale-store/tier5-src/himi-store-account/index.ts +13 -4
  310. package/templates/yoga-studio/config.ts +12 -0
  311. package/templates/yoga-studio/dev/index.ts +1 -1
  312. package/templates/yoga-studio/l10n/en.json +1 -1
  313. package/templates/yoga-studio/tier5-src/_shared/booking-session.ts +3 -1
  314. package/templates/yoga-studio/tier5-src/_shared/business-chat-transport.ts +148 -0
  315. package/templates/yoga-studio/tier5-src/_shared/header-badges.ts +113 -0
  316. package/templates/yoga-studio/tier5-src/_shared/location-pin.ts +97 -0
  317. package/templates/yoga-studio/tier5-src/_shared/member-access.ts +17 -6
  318. package/templates/yoga-studio/tier5-src/_shared/program-fields.ts +16 -0
  319. package/templates/yoga-studio/tier5-src/_shared/programs-section.ts +5 -8
  320. package/templates/yoga-studio/tier5-src/_shared/source-badges.ts +72 -0
  321. package/templates/yoga-studio/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  322. package/templates/yoga-studio/tier5-src/himi-branded-lite-nav/index.ts +152 -0
  323. package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +13 -4
  324. package/templates/yoga-studio/tier5-src/wix-spaces-view-profile/index.ts +68 -55
@@ -0,0 +1,988 @@
1
+ // himi-branded-lite-agenda — the Bookings Agenda: every upcoming CLASS and COURSE session of the
2
+ // site, under a collapsible week/month calendar.
3
+ //
4
+ // Everyone sees the whole schedule. A signed-in member also sees their own place in it: a
5
+ // session they booked reads "Booked", one they wait for reads "On waitlist", and each opens
6
+ // a sheet to add it to the calendar, view the class, or cancel / leave. A full session with
7
+ // waitlist room offers "Join Waitlist"; a full one without, or one outside the booking window,
8
+ // says so ("Full", "Not open yet", "Closed") instead of offering a Book that would fail.
9
+ //
10
+ // Appointment services are left out on purpose: their availability is every free slot of
11
+ // the day, which is a booking grid, not an agenda of things that happen. Course sessions are
12
+ // listed, tagged "Course", but a course is booked as a whole on its service screen, never one
13
+ // session: its row offers "View Course", and shows no spots (a session's open spots do not say
14
+ // whether the course has room).
15
+ //
16
+ // Action results (joined, cancelled, left, added to the calendar, or a failure) show in a
17
+ // non-modal sheet above the tab bar, so a member scrolled far down the list still sees them.
18
+ //
19
+ // The calendar marks every day with a session (one dot) and today (its own ring). The list
20
+ // starts at the selected day, so a day with nothing on it shows the next sessions instead
21
+ // of an empty page — the agenda answers "what is on from here".
22
+ import { defineService, navigate } from "@himalaya/state";
23
+ import { addDays, dayKey, dayLabel, timeLabel, toDate, weekOf, type DayDecoration, type Weekday } from "@himalaya/time";
24
+ import { createEvent, getPermissionStatus, requestPermission } from "@himalaya/calendar";
25
+ import { open } from "@himalaya/open-url";
26
+ import {
27
+ cancelBookingAsMember, isBookingPolicyViolation, leaveWaitlist, listWaitlists, queryBookings, queryServiceAvailability,
28
+ queryServices, registerToWaitlist, type WixAvailabilityEntry, type WixBooking, type WixService,
29
+ } from "@himalaya/wix-bookings";
30
+ import { getMyMember } from "@himalaya/wix-members";
31
+ import { signInPageStyle, signInSheetStyle } from "../_shared/sign-in-sheet.js";
32
+ import { LOADING, loadFailed, type LoadFlags } from "../_shared/branded-load-state.js";
33
+ import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
34
+ import { slotStartInstant } from "../_shared/himi-bookings.js";
35
+ import { formatServicePrice } from "../_shared/wix-service-price.js";
36
+ import { compareText } from "../_shared/engine-intl.js";
37
+ import { assertMemberAccess, memberAccess, memberAccessChanged, type MemberAccess } from "../_shared/member-access.js";
38
+ import { atLeast } from "../_shared/member-account-routes.js";
39
+ import { get as getAppInfo } from "@himalaya/app-info";
40
+ import {
41
+ distinctChoices, effectiveLocation, locationMenu, readSharedLocation, serviceLocationChoices, writeSharedLocation,
42
+ type LocationChoice, type LocationOptionRow,
43
+ } from "../_shared/booking-location.js";
44
+ import {
45
+ bySession, markWaitlisted, placesIn, placesOf, sessionControl, sessionKey, sessionOf, spotsLabel,
46
+ type MemberPlace, type Place, type Session,
47
+ } from "../_shared/booking-session.js";
48
+
49
+ // The session model is shared with the service screen opened from a row; re-exported for the tests.
50
+ export { bySession, markWaitlisted, placesOf, sessionKey, sessionOf };
51
+ export type { MemberPlace, Place, Session };
52
+
53
+ /** How far past the selected day the list reaches. */
54
+ export const AGENDA_DAYS = 28;
55
+ /** Services whose sessions are fixed events: a class's are each booked on their own, a course's
56
+ * are listed but the course is booked as a whole (on its service screen). */
57
+ const SESSION_TYPES = new Set(["CLASS", "COURSE"]);
58
+ /** The `Agenda` wire shape: declared fields plus a flat string `extra` map for the row. */
59
+ export interface AgendaEvent {
60
+ id: string;
61
+ title: string;
62
+ start: string;
63
+ end: string;
64
+ extra: Record<string, string>;
65
+ }
66
+
67
+ interface S extends LoadFlags {
68
+ firstWeekday: number;
69
+ today: string;
70
+ selectedDate: string;
71
+ rangeStart: string;
72
+ rangeEnd: string;
73
+ decorations: DayDecoration[];
74
+ events: AgendaEvent[];
75
+ scrollTo: string;
76
+ signedIn: boolean;
77
+ /** An older Android binary: its Agenda drops each row's fields, so the list is replaced by a
78
+ * line asking to update. */
79
+ updateRequired: boolean;
80
+ /** The update-required line — a state of the screen, not an action's result. */
81
+ updateMessage: string;
82
+ /** The list is hidden while loading or failed, when an update is required, and when it is empty. */
83
+ listHidden: boolean;
84
+ /** Loaded, and the site has no class or course at all. */
85
+ noClasses: boolean;
86
+ /** Loaded, the site has classes, but none from the selected day to the end of the loaded days. */
87
+ nothingAhead: boolean;
88
+ /** The negations a `hiddenPath` reads: each empty state shows only when its own flag is set. */
89
+ notNoClasses: boolean;
90
+ notNothingAhead: boolean;
91
+ // The result sheet: one action's outcome, non-modal, above the tab bar. Two slots that take turns
92
+ // (A = resultOpen, B = resultOpenB): each new result presents in the other one, so it gets its own
93
+ // eight-second countdown rather than the rest of the previous result's.
94
+ resultOpen: boolean;
95
+ resultOpenB: boolean;
96
+ resultText: string;
97
+ /** It went through (a check) … */
98
+ resultOk: boolean;
99
+ /** … or it did not, or needs the member (an info mark). Exactly one is false while open. */
100
+ resultInfo: boolean;
101
+ // The session sheet (Booked / On waitlist).
102
+ sheetOpen: boolean;
103
+ sheetTitle: string;
104
+ sheetWhen: string;
105
+ sheetMeta: string;
106
+ /** Add to Calendar is for a booked session only. */
107
+ sheetHideCalendar: boolean;
108
+ sheetHideCancel: boolean;
109
+ sheetHideLeave: boolean;
110
+ sheetBusy: boolean;
111
+ /** The sheet session's service: View class reads its declared route (`nav`) from it. "" with no sheet. */
112
+ sheetServiceId: string;
113
+ /** …and its session (id and start), so the service screen opens on it. */
114
+ sheetSessionId: string;
115
+ sheetStart: string;
116
+ // The location picker (two or more locations only): `locationMenu()` in booking-location.ts.
117
+ locationOptions: LocationOptionRow[];
118
+ locationLabel: string;
119
+ locationA11y: string;
120
+ hasLocationMenu: boolean;
121
+ noLocationMenu: boolean;
122
+ /** A location is chosen: the pin turns accent and the line under the title names it. */
123
+ locationActive: boolean;
124
+ noLocationActive: boolean;
125
+ locationSheetOpen: boolean;
126
+ /** A location is chosen and has no session in the loaded days: its own empty state. */
127
+ locationEmpty: boolean;
128
+ notLocationEmpty: boolean;
129
+ /** The optional "All · Booked" filter, for an app that asks for it (`load` param `filters: "1"`):
130
+ * "booked" lists only the member's own sessions (booked or on the waitlist). Off by default, so
131
+ * an app that does not bind it lists every session, as before. */
132
+ filter?: "all" | "booked";
133
+ hideFilter?: boolean;
134
+ /** The booked filter is on and the member has no session in the loaded days. */
135
+ bookedEmpty?: boolean;
136
+ notBookedEmpty?: boolean;
137
+ }
138
+
139
+ const flag = (on: boolean): string => (on ? "true" : "");
140
+
141
+ /** "1 hr", "45 min", "1 hr 30 min" — the length under the time. */
142
+ export function lengthLabel(start: string, end: string): string {
143
+ const mins = Math.round((Date.parse(end) - Date.parse(start)) / 60_000);
144
+ if (!Number.isFinite(mins) || mins <= 0) return "";
145
+ const h = Math.floor(mins / 60), m = mins % 60;
146
+ return h && m
147
+ ? copyTemplate("agenda.lengthHoursMinutes", "{h} hr {m} min", { h, m })
148
+ : h ? copyTemplate("agenda.lengthHours", "{h} hr", { h }) : copyTemplate("agenda.lengthMinutes", "{m} min", { m });
149
+ }
150
+
151
+ /** The parts that are known, joined by a middle dot: "Omer Levi · Studio Zen". */
152
+ const joined = (...parts: string[]): string => parts.filter(Boolean).join(" · ");
153
+
154
+ /** One session → one Agenda row. Exactly one of the trailing controls is visible. `lastOfDay`: the
155
+ * day's last row draws no divider — the next day's header band starts right under it. */
156
+ export function eventOf(s: Session, place: MemberPlace | undefined, lastOfDay = false): AgendaEvent {
157
+ const { control, closedLabel } = sessionControl(s, place);
158
+ const course = s.kind === "course";
159
+ const time = timeLabel(s.start);
160
+ return {
161
+ id: s.key,
162
+ title: s.title,
163
+ start: s.start,
164
+ end: s.end,
165
+ extra: {
166
+ serviceId: s.serviceId,
167
+ // Choose Time opens on THIS session: two of a class can start at the same time.
168
+ sessionId: s.sessionId,
169
+ time,
170
+ length: lengthLabel(s.start, s.end),
171
+ meta: joined(s.staff, s.location),
172
+ availability: joined(s.price, spotsLabel(s)),
173
+ isCourse: flag(course),
174
+ notCourse: flag(!course),
175
+ detailsA11y: s.staff
176
+ ? copyTemplate("agenda.detailsA11y", "{title}, {time}, with {staff}", { title: s.title, time, staff: s.staff })
177
+ : [s.title, time].filter(Boolean).join(", "),
178
+ bookA11y: copyTemplate("agenda.bookA11y", "Book {title}, {time}", { title: s.title, time }),
179
+ hideBook: flag(control !== "book"),
180
+ hideWaitlist: flag(control !== "waitlist"),
181
+ hideCourse: flag(control !== "course"),
182
+ hideBooked: flag(control !== "booked"),
183
+ hideOnWaitlist: flag(control !== "waitlisted"),
184
+ hideClosed: flag(control !== "closed"),
185
+ closedLabel,
186
+ lastOfDay: flag(lastOfDay),
187
+ },
188
+ };
189
+ }
190
+
191
+ /** The first and last cell any month grid of `day`'s month can have, padding included. */
192
+ function monthGrid(day: string): { start: string; end: string } {
193
+ const d = toDate(day);
194
+ if (!d) return { start: day, end: day };
195
+ return { start: dayKey(new Date(d.getFullYear(), d.getMonth(), 1 - 6)), end: dayKey(new Date(d.getFullYear(), d.getMonth() + 1, 6)) };
196
+ }
197
+
198
+ /** One dot per day that has a session — "something is on", not how much — and the visible
199
+ * days before today dimmed and unselectable: the agenda is what is still to come. */
200
+ export function decorationsOf(sessions: Session[], today: string, rangeStart: string, rangeEnd: string): DayDecoration[] {
201
+ const out: DayDecoration[] = [];
202
+ const dimmed = new Set<string>();
203
+ const dim = (from: string, to: string) => {
204
+ for (let day = from; day && day < today && day <= to; day = dayKey(addDays(day, 1))) {
205
+ if (!dimmed.has(day)) { dimmed.add(day); out.push({ date: day, disabled: true }); }
206
+ }
207
+ };
208
+ // Bounded by the visible days: a page a year back dims its 7-42 cells, not a year.
209
+ dim(rangeStart, rangeEnd);
210
+ // And this month's grid: an older binary (no week mode) draws it on first open, while it
211
+ // reports nothing until the member pages.
212
+ dim(monthGrid(today).start, today);
213
+ for (const date of [...new Set(sessions.filter((s) => s.day >= today).map((s) => s.day))].sort()) out.push({ date, dotCount: 1 });
214
+ return out;
215
+ }
216
+
217
+ /** The days to load: the visible days (never before today) through AGENDA_DAYS past the
218
+ * selected day, so the list under the calendar always has its full reach. */
219
+ export function windowFor(today: string, rangeStart: string, rangeEnd: string, selected: string): { start: string; end: string } {
220
+ const start = rangeStart > today ? rangeStart : today;
221
+ const from = selected > today ? selected : today;
222
+ // Through the last cell of the selected day's month grid as well, which is what an older
223
+ // binary draws before it has reported any page: every dot on it is then real.
224
+ const end = [rangeEnd, dayKey(addDays(from, AGENDA_DAYS)), monthGrid(from).end].reduce((a, b) => (b > a ? b : a));
225
+ return { start, end };
226
+ }
227
+
228
+ /** Where the selection goes when the calendar pages away from it: the first day of the
229
+ * page (the 1st of the titled month in month view — the grid's first cell is padding),
230
+ * or today when that is on the page. A page wholly before today has no day to select (past
231
+ * days are disabled), so `current` stays selected and the list keeps showing from it. */
232
+ export function selectionForRange(today: string, rangeStart: string, rangeEnd: string, current = today): string {
233
+ const { first, last } = titledDays(rangeStart, rangeEnd);
234
+ if (today >= first && today <= last) return today;
235
+ return last < today ? current : first;
236
+ }
237
+
238
+ /** The days a page is about: the whole week, or a month grid's TITLED month — its padding cells
239
+ * belong to the neighbouring months. */
240
+ export function titledDays(rangeStart: string, rangeEnd: string): { first: string; last: string } {
241
+ let first = rangeStart;
242
+ let last = rangeEnd;
243
+ const span = Math.round((Date.parse(rangeEnd) - Date.parse(rangeStart)) / 86_400_000);
244
+ if (span > 7) {
245
+ // A month grid: its padding cells belong to the neighbouring months. Today counts only when
246
+ // it is in the TITLED month — a today in the trailing padding would move the selection, and
247
+ // with it the grid, a month forward.
248
+ const d = toDate(rangeStart);
249
+ if (d) {
250
+ const month = rangeStart.endsWith("-01") ? d : new Date(d.getFullYear(), d.getMonth() + 1, 1);
251
+ first = dayKey(month);
252
+ last = dayKey(new Date(month.getFullYear(), month.getMonth() + 1, 0));
253
+ }
254
+ }
255
+ return { first, last };
256
+ }
257
+
258
+ /** The month grid (whole weeks) of `day`'s month, as a calendar draws it. */
259
+ function monthGridOf(day: string, firstWeekday: number): { start: string; end: string } | undefined {
260
+ const d = toDate(day);
261
+ if (!d) return undefined;
262
+ const fw = (((firstWeekday % 7) + 7) % 7) as Weekday;
263
+ const start = weekOf(new Date(d.getFullYear(), d.getMonth(), 1), fw)[0];
264
+ const end = weekOf(new Date(d.getFullYear(), d.getMonth() + 1, 0), fw)[6];
265
+ return start && end ? { start, end } : undefined;
266
+ }
267
+
268
+ /** Does the selection survive a page change? Inside the page's TITLED days, yes — a selection in a
269
+ * month grid's padding belongs to the neighbouring month. Today stays selected on any page that
270
+ * shows it: opening a week that straddles two months into the month holding most of it must not
271
+ * move the agenda off today. */
272
+ export function keepsSelection(cur: { today: string; selectedDate: string }, start: string, end: string): boolean {
273
+ const page = titledDays(start, end);
274
+ if (cur.selectedDate >= page.first && cur.selectedDate <= page.last) return true;
275
+ return !!cur.today && cur.selectedDate === cur.today && cur.today >= start && cur.today <= end;
276
+ }
277
+
278
+ function calendarStamp(ms: number): string {
279
+ return new Date(ms).toISOString().replace(/[-:]/g, "").replace(/\.\d{3}Z$/, "Z");
280
+ }
281
+
282
+ /** The Google Calendar template page for a session — the fallback when the device calendar is
283
+ * refused or creates nothing. `encodeURIComponent`, never URLSearchParams: the iOS / macOS
284
+ * worker engine (JavaScriptCore) does not provide it (see himi-events-detail). */
285
+ export function calendarFallbackUrl(session: Pick<Session, "title" | "location" | "staff">, start: number, end: number): string {
286
+ const parts = ["action=TEMPLATE", `text=${encodeURIComponent(session.title)}`, `dates=${calendarStamp(start)}/${calendarStamp(end)}`];
287
+ if (session.location) parts.push(`location=${encodeURIComponent(session.location)}`);
288
+ if (session.staff) parts.push(`details=${encodeURIComponent(session.staff)}`);
289
+ return `https://calendar.google.com/calendar/render?${parts.join("&")}`;
290
+ }
291
+
292
+ // ── loading ──────────────────────────────────────────────────────────────────
293
+
294
+ let services: WixService[] | null = null;
295
+ let sessions: Session[] = [];
296
+ let places = new Map<string, MemberPlace>();
297
+ let loadedWindow = { start: "", end: "" };
298
+ let member: MemberAccess | undefined;
299
+ let sheetKey = "";
300
+ /** The location the member chose (here, on Services or on Choose Time): "" is every location. */
301
+ let chosenLocation = { id: "", label: "" };
302
+ let locationSheet = false;
303
+ /** Until when a scroll report is ignored: a tap's (or a page's) jump is still settling, and a
304
+ * report the list sent before it must not move the selection back. */
305
+ let quietUntil = 0;
306
+ /** Bumped by a location change: the list's target becomes "day|n", so the renderer applies it again
307
+ * even when the day is the same one — rows above it came or went, and the offset no longer shows
308
+ * it. Cleared by the list's own scroll and a calendar tap, whose plain day the renderer compares
309
+ * with what it reported (an echo of the member's own scroll never moves the list). */
310
+ let scrollNonce = 0;
311
+ /** The "All · Booked" filter: offered when the screen's load asks for it, and the member's choice. */
312
+ let filtersOn = false;
313
+ /** The member the "Booked" choice was made by: another member (or a sign-out) opens on "All". */
314
+ let bookedFilterFor = "";
315
+ let busy = false;
316
+ /** An Add to Calendar flow is running (a permission prompt, a save, the calendar page). Its own
317
+ * flag, not `busy`: the session sheet must still close while it runs. */
318
+ let calendarBusy = false;
319
+
320
+ async function sessionServices(): Promise<WixService[]> {
321
+ if (services) return services;
322
+ // Every page, not the first 100: a class past the first page would silently be missing. Bounded,
323
+ // so a misbehaving paging answer cannot loop forever.
324
+ const all: WixService[] = [];
325
+ for (let page = 0; page < 10; page++) {
326
+ const res = await queryServices({ query: { paging: { limit: 100, offset: page * 100 } } } as never);
327
+ const batch = res.services ?? [];
328
+ all.push(...batch);
329
+ if (batch.length < 100) break;
330
+ }
331
+ services = all.filter((svc) => {
332
+ const raw = svc as WixService & { type?: string; hidden?: boolean };
333
+ return !!svc.id && SESSION_TYPES.has((raw.type ?? "").toUpperCase()) && raw.hidden !== true;
334
+ });
335
+ return services;
336
+ }
337
+
338
+ /** Every session of every class service in [start, end]. Each service is its own
339
+ * call — the proven single-service availability query — so one service failing (a draft,
340
+ * a removed schedule) costs its own rows, never the whole agenda. */
341
+ async function sessionsIn(start: string, end: string): Promise<Session[]> {
342
+ const list = await sessionServices();
343
+ const from = new Date(`${start}T00:00:00`).toISOString();
344
+ const to = new Date(`${dayKey(addDays(end, 1))}T00:00:00`).toISOString();
345
+ const settled = await Promise.allSettled(list.map((svc) => queryServiceAvailability(svc.id, from, to, { bookable: false })));
346
+ const failures = settled.filter((r) => r.status === "rejected").length;
347
+ if (list.length && failures === list.length) throw (settled[0] as PromiseRejectedResult).reason;
348
+ const out: Session[] = [];
349
+ settled.forEach((r, i) => {
350
+ if (r.status !== "fulfilled") return;
351
+ for (const entry of r.value.availabilityEntries ?? []) {
352
+ const session = sessionOf(entry, list[i]);
353
+ if (session) out.push(session);
354
+ }
355
+ });
356
+ return ordered(out);
357
+ }
358
+
359
+ /** Sessions once each, by start then title — the list's order. */
360
+ function ordered(list: Session[]): Session[] {
361
+ const seen = new Set<string>();
362
+ return list
363
+ .filter((s) => (seen.has(s.key) ? false : (seen.add(s.key), true)))
364
+ .sort((a, b) => Date.parse(a.start) - Date.parse(b.start) || compareText(a.title, b.title));
365
+ }
366
+
367
+ /** Is `owner` — the member a place was loaded for — still the one signed in, to the same account
368
+ * and business? Asked right before a write, so a sign-out or a switch since the load never
369
+ * writes for the wrong person. */
370
+ async function sameMember(owner: MemberAccess | undefined): Promise<boolean> {
371
+ if (!owner?.email) return false;
372
+ return assertMemberAccess(owner).then(() => true, () => false);
373
+ }
374
+
375
+ /** The member's name for a waitlist registration, when their member record has one. The
376
+ * email alone registers; the name is what the business sees on its waitlist. */
377
+ async function memberName(): Promise<{ firstName?: string; lastName?: string }> {
378
+ // A failed profile read registers by email alone rather than failing the join.
379
+ const res = await getMyMember({ fieldsets: ["FULL"] }).catch(() => undefined);
380
+ const contact = res?.member?.contact as { firstName?: string; lastName?: string } | undefined;
381
+ return { firstName: contact?.firstName || undefined, lastName: contact?.lastName || undefined };
382
+ }
383
+
384
+ type ResultFields = Pick<S, "resultOpen" | "resultOpenB" | "resultText" | "resultOk" | "resultInfo">;
385
+ /** The result sheet fields as the actions last SET them — not as the service last committed them:
386
+ * an action's result counts from the moment it is made, before the action's own state commits, so
387
+ * a read landing in between cannot copy the older fields over it. */
388
+ let lastResult: ResultFields = { resultOpen: false, resultOpenB: false, resultText: "", resultOk: false, resultInfo: false };
389
+
390
+ /** `next`, with the result sheet fields as they are NOW: a read that ran while a result was closed
391
+ * (or a newer one opened) must not commit the older result fields it started from. */
392
+ function keepResult(next: S | undefined): S | undefined {
393
+ if (!next) return next;
394
+ return { ...next, ...lastResult };
395
+ }
396
+
397
+ /** Which result slot presented last: the next result takes the other one. */
398
+ let resultSeq = 0;
399
+
400
+ /** One action's outcome, for the result sheet: `ok` when it went through. */
401
+ function result(text: string, ok: boolean): ResultFields {
402
+ const b = ++resultSeq % 2 === 0;
403
+ lastResult = { resultOpen: !b, resultOpenB: b, resultText: text, resultOk: ok, resultInfo: !ok };
404
+ return lastResult;
405
+ }
406
+ const NO_RESULT = { resultOpen: false, resultOpenB: false } as const;
407
+ /** A view action (load, a day or page change, opening the session sheet) closes any result on
408
+ * screen. A write still in flight still says its outcome when it lands: the member started it, and
409
+ * its row may not be on the page they moved to, so the sheet is their only confirmation. */
410
+ function newView(s: S): S {
411
+ lastResult = { ...lastResult, ...NO_RESULT };
412
+ return { ...s, ...NO_RESULT };
413
+ }
414
+
415
+ const emptyFlags = (noClasses: boolean, nothingAhead: boolean) =>
416
+ ({ noClasses, nothingAhead, notNoClasses: !noClasses, notNothingAhead: !nothingAhead });
417
+
418
+ /** The locations the member can choose from: every class and course service's own locations, then
419
+ * any the loaded sessions name that no service lists, and the location chosen on another screen
420
+ * (Services, Choose Time) even when nothing here is at it — so the choice is kept, and its empty
421
+ * state says so, rather than silently showing everything. */
422
+ export function agendaLocations(list: readonly WixService[], inWindow: readonly Session[], chosen: { id: string; label: string }): LocationChoice[] {
423
+ return distinctChoices([
424
+ ...list.flatMap((svc) => serviceLocationChoices(svc.locations)),
425
+ ...inWindow.map((x) => ({ key: x.locationKey, label: x.location, sub: x.locationSub })),
426
+ ...(chosen.id && chosen.label ? [{ key: chosen.id, label: chosen.label, sub: "" }] : []),
427
+ ]);
428
+ }
429
+
430
+ /** The day the list scrolls to for `selected`: that day, else the next one with a session, else the
431
+ * last one (a day after every loaded session still shows the list's end, not an empty page). */
432
+ export function scrollDayFor(days: readonly string[], selected: string): string {
433
+ return days.find((d) => d >= selected) ?? days[days.length - 1] ?? "";
434
+ }
435
+
436
+ /** Rebuild everything the screen reads from the module state. */
437
+ function derive(s: S): S {
438
+ const choices = agendaLocations(services ?? [], sessions, chosenLocation);
439
+ const locationKey = effectiveLocation(choices, chosenLocation.id);
440
+ // From today on (the loaded days never start before it), at the chosen location. The list is
441
+ // one run of days: a tap on the calendar SCROLLS it to a day, and scrolling it moves the
442
+ // selection, so it never starts at the selected day (the days above it would vanish).
443
+ const bookedOnly = filtersOn && !!member?.email && bookedFilterFor === member.email;
444
+ const mine = (x: Session) => { const p = places.get(x.key)?.place; return p === "booked" || p === "waitlisted"; };
445
+ const shown = sessions.filter((x) => x.day >= s.today && (!locationKey || x.locationKey === locationKey) && (!bookedOnly || mine(x)));
446
+ const events = rowsOk === false ? [] : shown.map((x, i) => eventOf(x, places.get(x.key), shown[i + 1]?.day !== x.day));
447
+ const sheet = sessions.find((x) => x.key === sheetKey);
448
+ const sheetPlace = sheet ? places.get(sheet.key)?.place ?? "" : "";
449
+ const loaded = s.status === "ready" && rowsOk !== false && !!services;
450
+ const locationEmpty = loaded && !!locationKey && shown.length === 0 && !bookedOnly;
451
+ const bookedEmpty = loaded && bookedOnly && shown.length === 0;
452
+ return {
453
+ ...s,
454
+ filter: bookedOnly ? "booked" : "all",
455
+ // A visitor has no sessions of their own: the filter shows only to a signed-in member.
456
+ hideFilter: !filtersOn || !member?.email,
457
+ bookedEmpty,
458
+ notBookedEmpty: !bookedEmpty,
459
+ ...locationMenu(choices, chosenLocation.id),
460
+ locationSheetOpen: locationSheet,
461
+ locationEmpty,
462
+ notLocationEmpty: !locationEmpty,
463
+ // The dots follow the location too: a day with a session only elsewhere has none.
464
+ decorations: decorationsOf(shown, s.today, s.rangeStart, s.rangeEnd),
465
+ events,
466
+ scrollTo: ((day) => (day && scrollNonce && suffixOk !== false ? `${day}|${scrollNonce}` : day))(scrollDayFor([...new Set(shown.map((x) => x.day))], s.selectedDate)),
467
+ // The only thing an update-required screen says: no tap or page clears it.
468
+ updateMessage: rowsOk === false ? copyParam("agenda.updateRequired", "Update the app to see the class schedule.") : "",
469
+ signedIn: !!member?.email,
470
+ updateRequired: rowsOk === false,
471
+ listHidden: s.busy === true || rowsOk === false || events.length === 0,
472
+ ...emptyFlags(loaded && services!.length === 0, loaded && services!.length > 0 && events.length === 0 && !locationEmpty && !bookedEmpty),
473
+ sheetOpen: !!sheet && !!sheetPlace,
474
+ sheetTitle: sheet?.title ?? "",
475
+ sheetWhen: sheet ? joined(dayLabel(sheet.start, { absolute: true }), timeLabel(sheet.start), lengthLabel(sheet.start, sheet.end)) : "",
476
+ sheetMeta: sheet ? joined(sheet.staff, sheet.location) : "",
477
+ sheetHideCalendar: sheetPlace !== "booked",
478
+ sheetHideCancel: sheetPlace !== "booked",
479
+ sheetHideLeave: sheetPlace !== "waitlisted",
480
+ sheetBusy: busy || calendarBusy,
481
+ sheetServiceId: sheet?.serviceId ?? "",
482
+ sheetSessionId: sheet?.sessionId ?? "",
483
+ sheetStart: sheet?.start ?? "",
484
+ };
485
+ }
486
+
487
+ /** Leave a waitlist. The registration id comes from the load; a place known only by its
488
+ * WAITING_LIST status asks the session's waitlist for it, and a registration Wix no longer lists
489
+ * is released through the member cancel of its booking. */
490
+ async function leave(place: MemberPlace, session: Session, owner: MemberAccess | undefined): Promise<void> {
491
+ let registrationId = place.registrationId ?? "";
492
+ if (!registrationId && session.sessionId) {
493
+ const lists = await listWaitlists([session.sessionId]);
494
+ for (const list of lists.list ?? []) {
495
+ for (const r of list.registrations ?? []) if (r.bookingId === place.bookingId && r.id) registrationId = r.id;
496
+ }
497
+ // The lookup awaited: still the member the place belongs to?
498
+ if (!(await sameMember(owner))) throw memberAccessChanged();
499
+ }
500
+ if (registrationId && session.sessionId) await leaveWaitlist(registrationId, session.sessionId);
501
+ else await cancelBookingAsMember(place.bookingId, place.revision);
502
+ }
503
+
504
+ /** The first runtime whose Android Agenda keeps a worker-bound event's `extra` — every field a row
505
+ * shows, and every flag that hides its other actions. An older Android binary would draw each
506
+ * row blank with all its actions at once, so it is asked to update instead. Checked at run time,
507
+ * not as a descriptor floor: a release takes its highest screen floor as its own. */
508
+ export const AGENDA_MIN_ANDROID_BINARY = "1.6.0";
509
+ let rowsOk: boolean | undefined;
510
+ /** A `scrollTo` of "day|nonce" jumps again to the same day (after a location change). A native
511
+ * renderer before 1.8.0 reads the whole value as the day and finds no row, so it gets the plain
512
+ * day: the list then does not re-land on an unchanged day, but it does reach a new one. */
513
+ export const AGENDA_SCROLL_SUFFIX_MIN_BINARY = "1.8.0";
514
+ let suffixOk: boolean | undefined;
515
+
516
+ async function rowsSupported(): Promise<boolean> {
517
+ const info = await getAppInfo().catch(() => undefined);
518
+ const native = !!info && (info.platform === "ios" || info.platform === "android" || info.platform === "macos");
519
+ suffixOk = !native || atLeast(info!.binaryVersion, AGENDA_SCROLL_SUFFIX_MIN_BINARY);
520
+ if (!info || info.platform !== "android") return true;
521
+ return atLeast(info.binaryVersion, AGENDA_MIN_ANDROID_BINARY);
522
+ }
523
+
524
+ const READY = { status: "ready" as const, error: "", signInRequired: false, notErrored: true, notLoading: true, busy: false, noSignIn: true };
525
+
526
+ type View = Pick<S, "today" | "rangeStart" | "rangeEnd" | "selectedDate" | "firstWeekday">;
527
+ /** The page and day the member asked for LAST. Every action records it before its first await,
528
+ * so a read that lands after a newer page or day tap shows that view, not the one it started
529
+ * from — paging back before the forward read lands must end on the user's last page. */
530
+ let wanted: View | undefined;
531
+
532
+ /** Record what the member asked for and return the state that shows it. */
533
+ function ask(s: S, view: Partial<View>): S {
534
+ wanted = { ...(wanted ?? { today: s.today, rangeStart: s.rangeStart, rangeEnd: s.rangeEnd, selectedDate: s.selectedDate, firstWeekday: s.firstWeekday }), ...view };
535
+ // The initial state carries no date; an action that lands before `load` still needs today.
536
+ if (!wanted.today) wanted = { ...wanted, today: dayKey(new Date()) };
537
+ return { ...s, ...wanted };
538
+ }
539
+
540
+ /** The longest run of days the list grows to before a far page replaces it. */
541
+ export const AGENDA_MAX_DAYS = 120;
542
+
543
+ /** The days to read when `need` is not loaded: the loaded days GROWN to reach it when the two touch
544
+ * (the member scrolled or paged on — the rows above them must stay, or the list jumps under their
545
+ * finger), else `need` alone (a far page). Capped at AGENDA_MAX_DAYS. */
546
+ export function grownWindow(loaded: { start: string; end: string }, need: { start: string; end: string }): { start: string; end: string } {
547
+ if (!loaded.start || need.start > dayKey(addDays(loaded.end, 1)) || need.end < dayKey(addDays(loaded.start, -1))) return need;
548
+ const start = loaded.start < need.start ? loaded.start : need.start;
549
+ const end = loaded.end > need.end ? loaded.end : need.end;
550
+ const span = Math.round((Date.parse(end) - Date.parse(start)) / 86_400_000);
551
+ return span > AGENDA_MAX_DAYS ? need : { start, end };
552
+ }
553
+
554
+ const covers = (win: { start: string; end: string }, need: { start: string; end: string }): boolean =>
555
+ !!win.start && win.start <= need.start && win.end >= need.end;
556
+ const needOf = (s: S) => windowFor(s.today, s.rangeStart, s.rangeEnd, s.selectedDate);
557
+
558
+ /** Bumped by every READ: a read that a newer read overtook stands down (returns `undefined`), and
559
+ * the newer one commits. An action the loaded days already cover reads nothing and bumps nothing,
560
+ * so a day tap never discards a reload in flight. */
561
+ let loadSeq = 0;
562
+
563
+ /** Load the window the state needs, unless it is already loaded. `force` reloads it (the
564
+ * screen re-appeared: the member may have just booked on the Choose Time screen). Resolves to
565
+ * `undefined` when a newer read started while this one awaited. */
566
+ async function ensureLoaded(base: S, force = false): Promise<S | undefined> {
567
+ const s = { ...base, ...wanted };
568
+ if (rowsOk === false) return derive(s);
569
+ const need = needOf(s);
570
+ // Days already loaded mean the last read succeeded (a failure clears them), so the screen is
571
+ // ready — whatever the state this action was dispatched with still said: a calendar's first
572
+ // page report can finish its read while `load`, dispatched with "loading", still waits.
573
+ if (covers(loadedWindow, need) && !force) return derive({ ...s, ...READY });
574
+ const seq = ++loadSeq;
575
+ const win = covers(loadedWindow, need) ? loadedWindow : grownWindow(loadedWindow, need);
576
+ // A result that an action produced while this read ran (Add to Calendar, a failed cancel) is
577
+ // newer than the state this read started from: the commit keeps it rather than closing it.
578
+ const resultAt = resultSeq;
579
+ const fresh = (x: S): S => (resultSeq === resultAt ? x : keepResult(x) ?? x);
580
+ try {
581
+ // A window grown to reach new days reads only those days, and keeps what it has: a scroll that
582
+ // extends the list must not re-read weeks of every class (and the member's bookings) each time.
583
+ // A forced reload (the screen re-appeared) and a far page read the whole window.
584
+ const grown = !force && win !== need && !!loadedWindow.start && win.start <= loadedWindow.start && win.end >= loadedWindow.end;
585
+ const parts = grown
586
+ ? [
587
+ ...(win.start < loadedWindow.start ? [{ start: win.start, end: dayKey(addDays(loadedWindow.start, -1)) }] : []),
588
+ ...(win.end > loadedWindow.end ? [{ start: dayKey(addDays(loadedWindow.end, 1)), end: win.end }] : []),
589
+ ]
590
+ : [win];
591
+ const reads = await Promise.all(parts.map(async (part) => {
592
+ const inPart = await sessionsIn(part.start, part.end);
593
+ const { who: reader, found } = await placesIn(part.start, part.end, inPart);
594
+ return { inPart, reader, found };
595
+ }));
596
+ const nextSessions = grown ? ordered([...sessions, ...reads.flatMap((r) => r.inPart)]) : reads[0]!.inPart;
597
+ const nextPlaces = grown ? new Map([...places, ...reads.flatMap((r) => [...r.found])]) : reads[0]!.found;
598
+ const who = reads[0]?.reader ?? member;
599
+ if (seq !== loadSeq) return undefined;
600
+ // The new days were read for another member than the loaded ones (a sign-out or a switch while
601
+ // the member scrolled): never mix two members' places — read the whole window for this one.
602
+ if (grown && reads.some((r) => (r.reader?.email ?? "") !== (member?.email ?? ""))) return ensureLoaded({ ...s, ...wanted }, true);
603
+ const now = { ...s, ...wanted };
604
+ if (!covers(win, needOf(now))) {
605
+ // The member paged past what this read covers while it ran. The days already loaded may
606
+ // cover where they are now (they paged back); otherwise read those.
607
+ return covers(loadedWindow, needOf(now)) ? derive(fresh({ ...now, ...READY })) : ensureLoaded(fresh(now));
608
+ }
609
+ sessions = nextSessions;
610
+ places = nextPlaces;
611
+ member = who;
612
+ loadedWindow = win;
613
+ return derive(fresh({ ...now, ...READY }));
614
+ } catch (err) {
615
+ if (seq !== loadSeq) return undefined;
616
+ const now = { ...s, ...wanted };
617
+ // The member paged back to days already loaded while this read failed: those still stand.
618
+ if (!covers(win, needOf(now)) && covers(loadedWindow, needOf(now))) return derive(fresh({ ...now, ...READY }));
619
+ // Only the flags: the schedule is not a row collection, and a failed load keeps no rows.
620
+ const { sessions: _rows, emptyText: _empty, ...flags } = loadFailed("sessions", err, {
621
+ prefix: "agenda",
622
+ empty: "No classes from this day on.",
623
+ error: "The schedule couldn't be loaded.",
624
+ signIn: "Sign in to see the schedule.",
625
+ sample: () => [] as Session[],
626
+ });
627
+ sessions = [];
628
+ places = new Map();
629
+ loadedWindow = { start: "", end: "" };
630
+ return derive(fresh({ ...now, ...flags }));
631
+ }
632
+ }
633
+
634
+ function argOf(p: unknown, key: string): string {
635
+ const a = p as Record<string, unknown> | undefined;
636
+ const v = a?.[key] ?? (a?.args as Record<string, unknown> | undefined)?.[key] ?? (a?.params as Record<string, unknown> | undefined)?.[key];
637
+ // Numbers too: every renderer sends onMonthChange's year/month as numbers.
638
+ return typeof v === "string" ? v.trim() : typeof v === "number" && Number.isFinite(v) ? String(v) : "";
639
+ }
640
+
641
+ const eventIdOf = (p: unknown): string => argOf(p, "eventId") || argOf(p, "id");
642
+
643
+ /** Clock-free, so a template builds to the same release every time: `load` — or the
644
+ * first `ask` before it — fills in today and this week. */
645
+ function initial(): S {
646
+ return {
647
+ ...LOADING, firstWeekday: 0, today: "", selectedDate: "", rangeStart: "", rangeEnd: "",
648
+ decorations: [], events: [], scrollTo: "", signedIn: false, updateRequired: false, updateMessage: "", listHidden: true,
649
+ ...emptyFlags(false, false), resultOpen: false, resultOpenB: false, resultText: "", resultOk: false, resultInfo: false,
650
+ sheetOpen: false, sheetTitle: "", sheetWhen: "", sheetMeta: "", sheetHideCalendar: true, sheetHideCancel: true, sheetHideLeave: true, sheetBusy: false, sheetServiceId: "", sheetSessionId: "", sheetStart: "",
651
+ locationOptions: [], locationLabel: "", locationA11y: "", hasLocationMenu: false, noLocationMenu: true,
652
+ locationActive: false, noLocationActive: true, locationSheetOpen: false, locationEmpty: false, notLocationEmpty: true,
653
+ filter: "all", hideFilter: true, bookedEmpty: false, notBookedEmpty: true,
654
+ };
655
+ }
656
+
657
+ /** How long a jump the worker asked for (a calendar tap, a page, a location) takes to settle. */
658
+ export const JUMP_SETTLE_MS = 900;
659
+ const settleJump = () => { quietUntil = Date.now() + JUMP_SETTLE_MS; };
660
+
661
+ /** A selected day with no session moves to the next day that has one ON THE SAME PAGE (the week
662
+ * or month on screen), so the calendar and the list name the same day — the same rule on every
663
+ * platform. With none left on the page the day stays selected, and the list shows the sessions
664
+ * after it. Never off the page: that would page the calendar away under the member's finger. */
665
+ async function settled(next: S | undefined): Promise<S | undefined> {
666
+ // The day the list scrolls to (a location change adds a "|n" suffix that re-applies it).
667
+ const day = next?.scrollTo.split("|")[0] ?? "";
668
+ if (!next || next.status !== "ready" || !day || day === next.selectedDate) return next;
669
+ if (day < next.selectedDate || day > titledDays(next.rangeStart, next.rangeEnd).last) return next;
670
+ return ensureLoaded(ask(next, { selectedDate: day }));
671
+ }
672
+
673
+ /** How the app opens its sign-in screen, from the appear params ("" = push). */
674
+ let signInPresentation: "" | "sheet" | "full_screen" = "";
675
+ let signInStyle: "page" | "" = "";
676
+ /** The app's sign-in screen (`signInScreenId` appear param): Branded Lite's `himi_sign_in` by
677
+ * default; an app with no such screen names its own (salon-spa: the Profile tab, `himi_account`). */
678
+ let signInScreenId = "himi_sign_in";
679
+
680
+ const svc = defineService<S, {
681
+ load: (s: S, p?: unknown) => Promise<S | undefined>;
682
+ retry: (s: S) => Promise<S | undefined>;
683
+ selectDate: (s: S, p?: unknown) => Promise<S | undefined>;
684
+ rangeChanged: (s: S, p?: unknown) => Promise<S | undefined>;
685
+ monthChanged: (s: S, p?: unknown) => Promise<S | undefined>;
686
+ openSheet: (s: S, p?: unknown) => S;
687
+ closeSheet: (s: S) => S;
688
+ viewSession: (s: S) => S;
689
+ closeResult: (s: S, p?: unknown) => S;
690
+ addToCalendar: (s: S) => Promise<S>;
691
+ cancelBooking: (s: S) => Promise<S | undefined>;
692
+ joinWaitlist: (s: S, p?: unknown) => Promise<S | undefined>;
693
+ visibleDate: (s: S, p?: unknown) => Promise<S | undefined>;
694
+ openLocations: (s: S) => S;
695
+ closeLocations: (s: S) => S;
696
+ selectLocation: (s: S, p?: unknown) => Promise<S | undefined>;
697
+ setFilter: (s: S, p?: unknown) => S;
698
+ }>("himiBrandedAgenda", {
699
+ // An action's result belongs to that visit: a cold start must not replay it from saved state,
700
+ // nor reopen the location sheet.
701
+ notHydrated: ["resultOpen", "resultOpenB", "resultText", "resultOk", "resultInfo", "locationSheetOpen", "filter", "hideFilter", "bookedEmpty", "notBookedEmpty"],
702
+ // The optional Booked filter is the member's choice for this run: never written to the device.
703
+ notPersisted: ["filter", "hideFilter", "bookedEmpty", "notBookedEmpty"],
704
+ state: initial(),
705
+ actions: {
706
+ load: async (s, p) => {
707
+ stashCopy(p);
708
+ const presentation = argOf(p, "signInPresentation");
709
+ if (presentation === "sheet" || presentation === "full_screen") {
710
+ signInPresentation = presentation;
711
+ signInStyle = signInPageStyle(argOf(p, "signInSheetStyle"));
712
+ }
713
+ const signInScreen = argOf(p, "signInScreenId");
714
+ if (/^[a-z][a-z0-9_]{0,63}$/.test(signInScreen)) signInScreenId = signInScreen;
715
+ if (argOf(p, "filters") === "1") filtersOn = true;
716
+ const fw = Number(argOf(p, "firstWeekday") || s.firstWeekday);
717
+ const today = dayKey(new Date());
718
+ // First appearance: open on this week. A re-appearance keeps the member's place and
719
+ // reloads, so a session booked on Choose Time comes back marked "Booked".
720
+ // This worker has read nothing yet: open on this week. Not the state's own status — a cold
721
+ // boot restores the last run's snapshot ("ready", last week's page) into a fresh worker.
722
+ const first = !loadedWindow.start;
723
+ const week = weekOf(today, (((fw % 7) + 7) % 7) as Weekday);
724
+ // Re-read the catalog when the screen shows again: classes are added, renamed and removed.
725
+ if (!first) services = null;
726
+ // A result from before the screen was left is not news when it shows again.
727
+ const asked = first
728
+ ? ask(newView(s), { firstWeekday: fw, today, selectedDate: today, rangeStart: week[0], rangeEnd: week[6] })
729
+ : ask(newView(s), { firstWeekday: fw, today });
730
+ // The location chosen on any bookings screen, read again on every appearance: Services or
731
+ // Choose Time may have changed it since.
732
+ chosenLocation = await readSharedLocation();
733
+ rowsOk ??= await rowsSupported();
734
+ if (!rowsOk) return derive({ ...asked, ...READY });
735
+ return first ? settled(await ensureLoaded(asked)) : ensureLoaded(asked, true);
736
+ },
737
+ // A view action: it closes the result, as every other one does through `newView`.
738
+ retry: async (s) => { services = null; return ensureLoaded(newView({ ...s, ...LOADING }), true); },
739
+ // Each compares with the member's LAST ask, not `s`: a read still in flight has not put the
740
+ // previous page into `s` yet, and paging back to that page is still a change.
741
+ selectDate: async (s, p) => {
742
+ const date = argOf(p, "date");
743
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(date) || date === (wanted ?? s).selectedDate) return s;
744
+ // Past days are not selectable — also before the load has dimmed them on the calendar.
745
+ if (date < ((wanted ?? s).today || dayKey(new Date()))) return s;
746
+ settleJump();
747
+ scrollNonce = 0;
748
+ // A month grid's padding day (iOS draws them) belongs to the next month, and the grid moves
749
+ // there without reporting a page: move this page with it, so paging back is still a change.
750
+ const cur = wanted ?? s;
751
+ const span = Math.round((Date.parse(cur.rangeEnd) - Date.parse(cur.rangeStart)) / 86_400_000);
752
+ const page = titledDays(cur.rangeStart, cur.rangeEnd);
753
+ if (span > 7 && (date < page.first || date > page.last)) {
754
+ const grid = monthGridOf(date, s.firstWeekday);
755
+ if (grid) return settled(await ensureLoaded(ask(newView(s), { selectedDate: date, rangeStart: grid.start, rangeEnd: grid.end })));
756
+ }
757
+ return settled(await ensureLoaded(ask(newView(s), { selectedDate: date })));
758
+ },
759
+ rangeChanged: async (s, p) => {
760
+ const start = argOf(p, "startDate"), end = argOf(p, "endDate");
761
+ const cur = wanted ?? s;
762
+ if (!start || !end || (start === cur.rangeStart && end === cur.rangeEnd)) return s;
763
+ // The selection follows the page, so the list under the calendar describes the days
764
+ // on screen rather than a week the user has paged away from.
765
+ const keep = keepsSelection(cur, start, end);
766
+ const selectedDate = keep ? cur.selectedDate : selectionForRange(cur.today || dayKey(new Date()), start, end, cur.selectedDate);
767
+ // The calendar following the list's scroll pages too, and keeps its selection: only a page
768
+ // that moves the selection jumps the list.
769
+ if (!keep) { settleJump(); scrollNonce = 0; }
770
+ // A page that only followed the selection (the list's scroll moved it) is not a view change:
771
+ // a result on screen stays, as it does for the scroll itself.
772
+ return keep
773
+ ? ensureLoaded(ask(s, { rangeStart: start, rangeEnd: end, selectedDate }))
774
+ : settled(await ensureLoaded(ask(newView(s), { rangeStart: start, rangeEnd: end, selectedDate })));
775
+ },
776
+ // An older binary has no week mode and reports only the month. Its grid then spans the
777
+ // month's whole weeks; load those, so dots still show on every visible day.
778
+ monthChanged: async (s, p) => {
779
+ const year = Number(argOf(p, "year")), month = Number(argOf(p, "month"));
780
+ if (!year || !month) return s;
781
+ const first = new Date(year, month - 1, 1);
782
+ const start = weekOf(first, (s.firstWeekday % 7) as Weekday)[0];
783
+ const last = weekOf(new Date(year, month, 0), (s.firstWeekday % 7) as Weekday)[6];
784
+ const cur = wanted ?? s;
785
+ if (!start || !last || (start === cur.rangeStart && last === cur.rangeEnd)) return s;
786
+ const keep = keepsSelection(cur, start, last);
787
+ const selectedDate = keep ? cur.selectedDate : selectionForRange(cur.today || dayKey(new Date()), start, last, cur.selectedDate);
788
+ if (!keep) settleJump();
789
+ return ensureLoaded(ask(newView(s), { rangeStart: start, rangeEnd: last, selectedDate }));
790
+ },
791
+ openSheet: (s, p) => {
792
+ const key = eventIdOf(p);
793
+ if (!places.get(key)) return s;
794
+ sheetKey = key;
795
+ return derive(newView(s));
796
+ },
797
+ closeSheet: (s) => {
798
+ if (busy) return s;
799
+ sheetKey = "";
800
+ return derive(s);
801
+ },
802
+ viewSession: (s) => {
803
+ const session = sessions.find((x) => x.key === sheetKey);
804
+ sheetKey = "";
805
+ return session
806
+ ? navigate(derive(s), { screenId: "himi_service", args: { id: session.serviceId, sessionId: session.sessionId, start: session.start } })
807
+ : derive(s);
808
+ },
809
+ // From one slot's own close or dismissal (`slot`: "a" | "b"), or both when it names none.
810
+ closeResult: (s, p) => {
811
+ const slot = argOf(p, "slot");
812
+ const closed = slot === "a" ? { resultOpen: false } : slot === "b" ? { resultOpenB: false } : NO_RESULT;
813
+ lastResult = { ...lastResult, ...closed };
814
+ if (slot === "a") return s.resultOpen ? { ...s, resultOpen: false } : s;
815
+ if (slot === "b") return s.resultOpenB ? { ...s, resultOpenB: false } : s;
816
+ return s.resultOpen || s.resultOpenB ? { ...s, ...NO_RESULT } : s;
817
+ },
818
+ // Add a booked session to the device calendar — the event screen's flow: ask for write access,
819
+ // create the event, and fall back to the Google Calendar template page when the calendar is
820
+ // refused or creates nothing. Nothing is written to Wix.
821
+ addToCalendar: async (s): Promise<S> => {
822
+ const session = sessions.find((x) => x.key === sheetKey);
823
+ if (!session || places.get(session.key)?.place !== "booked" || busy || calendarBusy) return s;
824
+ // One calendar flow at a time. The sheet is left as it is while the flow runs (a reload that
825
+ // lands meanwhile must not close it — on iOS the calendar page is presented on it), and the
826
+ // member may close it, view the class, or open another session's sheet. Meanwhile its Add to
827
+ // Calendar and Cancel are inert (`calendarBusy`); a sheet opened during the flow reads them as
828
+ // disabled (sheetBusy). At the end the flow closes the sheet only if it is still this
829
+ // session's. Not `busy`: closeSheet must still work while the flow runs.
830
+ calendarBusy = true;
831
+ const start = Date.parse(session.start);
832
+ const end = Date.parse(session.end) > start ? Date.parse(session.end) : start + 60 * 60 * 1000;
833
+ const fallback = async (failed: string, failedFallback: string): Promise<ResultFields> => {
834
+ const opened = await open(calendarFallbackUrl(session, start, end), "in_app_browser").then((r) => r.opened, () => false);
835
+ // On iOS the in-app browser is presented ON the session sheet; closing the sheet now would
836
+ // close the browser with it. The sheet stays, and the member closes it after the browser.
837
+ // So the flow leaves an open sheet open; only a sheet that did not get the page is closed.
838
+ if (!opened && sheetKey === session.key) sheetKey = "";
839
+ return result(opened ? copyParam("agenda.calendarOpened", "Opened your calendar.") : copyParam(failed, failedFallback), false);
840
+ };
841
+ let outcome: ResultFields;
842
+ try {
843
+ let permission = await getPermissionStatus();
844
+ if (permission !== "granted" && permission !== "limited") permission = await requestPermission("writeOnly");
845
+ if (permission !== "granted" && permission !== "limited") {
846
+ outcome = await fallback("agenda.calendarDenied", "The app cannot use your calendar. Allow it in Settings.");
847
+ } else {
848
+ const created = await createEvent({ title: session.title, start, end, location: session.location, notes: session.staff });
849
+ if (created.id) {
850
+ if (sheetKey === session.key) sheetKey = "";
851
+ outcome = result(copyParam("agenda.calendarAdded", "Added to your calendar."), true);
852
+ } else {
853
+ outcome = await fallback("agenda.calendarFailed", "Could not add this class to your calendar.");
854
+ }
855
+ }
856
+ } catch {
857
+ // A calendar that throws (EventKit refusing the save) gets the same fallback as one that
858
+ // creates nothing: the calendar page, which `fallback` opens without throwing.
859
+ outcome = await fallback("agenda.calendarFailed", "Could not add this class to your calendar.");
860
+ } finally {
861
+ calendarBusy = false;
862
+ }
863
+ return derive({ ...(svc.getState() as S), ...outcome });
864
+ },
865
+ // Cancel a booking (the MEMBER cancel, so Wix enforces the business's cancellation
866
+ // policy), or leave a waitlist (which also releases the pending booking it created).
867
+ cancelBooking: async (s): Promise<S | undefined> => {
868
+ const place = places.get(sheetKey);
869
+ // Read with `place`: a reload that lands meanwhile replaces both together.
870
+ const owner = member;
871
+ const session = sessions.find((x) => x.key === sheetKey);
872
+ const leaving = place?.place === "waitlisted";
873
+ if (!place || !session || busy || calendarBusy || (!leaving && !place.revision)) return s;
874
+ busy = true;
875
+ try {
876
+ if (!(await sameMember(owner))) throw memberAccessChanged();
877
+ if (leaving) await leave(place, session, owner);
878
+ else await cancelBookingAsMember(place.bookingId, place.revision);
879
+ places.delete(sheetKey);
880
+ sheetKey = "";
881
+ const done = leaving ? copyParam("agenda.leftWaitlist", "You left the waitlist.") : copyParam("agenda.cancelDone", "Booking cancelled.");
882
+ // Reload against the state as it is NOW: the member may have paged while the write ran.
883
+ const next = await ensureLoaded(svc.getState() as S, true);
884
+ busy = false;
885
+ return derive({ ...(next ?? { ...(svc.getState() as S), ...wanted }), ...result(done, true) });
886
+ } catch (err) {
887
+ sheetKey = "";
888
+ if ((err as { name?: string } | null)?.name === "MemberAccessChanged") {
889
+ // Someone else (or nobody) since the load: show their schedule; nothing is cancelled.
890
+ const next = keepResult(await ensureLoaded(svc.getState() as S, true));
891
+ busy = false;
892
+ return next ? derive(next) : undefined;
893
+ }
894
+ busy = false;
895
+ const failed = isBookingPolicyViolation(err)
896
+ ? copyParam("agenda.cancelPolicy", "It's too late to cancel in the app. Contact the business.")
897
+ : copyParam("agenda.cancelFailed", "That didn't go through. Try again.");
898
+ return derive({ ...(svc.getState() as S), ...result(failed, false) });
899
+ }
900
+ },
901
+ joinWaitlist: async (s, p): Promise<S | undefined> => {
902
+ const key = eventIdOf(p);
903
+ const session = sessions.find((x) => x.key === key);
904
+ // A place already held (just joined, or booked) is never joined again.
905
+ if (!session || busy || places.get(key)) return s;
906
+ const owner = member;
907
+ busy = true;
908
+ try {
909
+ // One person's email and name: the member is read before AND after the name, and the
910
+ // registration goes out only when both reads, and the member the places were loaded for, agree.
911
+ const before = await memberAccess().catch(() => undefined);
912
+ if (!before?.email) {
913
+ busy = false;
914
+ // As a modal it only closes, and this screen loads again (its re-appearance reload).
915
+ return navigate(s, signInPresentation
916
+ ? { screenId: signInScreenId, presentation: signInPresentation, args: { mode: "signin", modal: "1", ...signInSheetStyle(signInPresentation, signInStyle) } }
917
+ : { screenId: signInScreenId, args: { mode: "signin", returnScreenId: "himi_agenda" } });
918
+ }
919
+ const name = await memberName();
920
+ const current = await memberAccess().catch(() => undefined);
921
+ const same = (a: MemberAccess | undefined, b: MemberAccess | undefined) => !!a?.email && a.email === b?.email && a.scope === b?.scope;
922
+ if (!same(before, current) || !same(owner, current)) {
923
+ // Another member since the load — or the load was a visitor's, so their places were never
924
+ // read: show their schedule first; nothing is registered.
925
+ const next = keepResult(await ensureLoaded(svc.getState() as S, true));
926
+ busy = false;
927
+ return next ? derive(next) : undefined;
928
+ }
929
+ const res = await registerToWaitlist(session.sessionId, { email: current!.email, ...name });
930
+ // Marked at once, so until a reload lands the row reads On waitlist and offers no second
931
+ // join — whether this reload commits or a newer page overtakes it.
932
+ places.set(key, { bookingId: res?.booking?.id ?? "", revision: "", place: "waitlisted", registrationId: res?.registrationId, confirmed: false });
933
+ const joined = copyParam("agenda.joinedWaitlist", "You're on the waitlist.");
934
+ const next = await ensureLoaded(svc.getState() as S, true);
935
+ busy = false;
936
+ return derive({ ...(next ?? { ...(svc.getState() as S), ...wanted }), ...result(joined, true) });
937
+ } catch {
938
+ busy = false;
939
+ return derive({ ...(svc.getState() as S), ...result(copyParam("agenda.waitlistFailed", "Couldn't join the waitlist. Try again."), false) });
940
+ }
941
+ },
942
+ // The list's scroll (`onVisibleDateChange`): the day the member reads becomes the selected day,
943
+ // so the calendar (and its week or month) follows the list. Not a view action — a result on
944
+ // screen stays. The list's scroll target follows too, so a return from a session's screen comes
945
+ // back to this day; the renderer does not scroll for its own day (it is where the list is).
946
+ visibleDate: async (s, p) => {
947
+ const date = argOf(p, "date");
948
+ const cur = wanted ?? s;
949
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(date) || date === cur.selectedDate) return s;
950
+ // A report from before a jump the worker asked for: the jump wins.
951
+ if (Date.now() < quietUntil) return s;
952
+ if (date < (cur.today || dayKey(new Date()))) return s;
953
+ scrollNonce = 0;
954
+ return ensureLoaded(ask(s, { selectedDate: date }));
955
+ },
956
+ openLocations: (s) => {
957
+ locationSheet = true;
958
+ return derive({ ...s, ...wanted });
959
+ },
960
+ // The "All · Booked" filter (a segmented control's id, or `{ id }`). A list of the member's own
961
+ // sessions, from the same loaded days; the calendar's dots follow it.
962
+ setFilter: (s, p) => {
963
+ const id = typeof p === "string" ? p : argOf(p, "id") || argOf(p, "value") || argOf(p, "selectedId");
964
+ if (id !== "all" && id !== "booked") return s;
965
+ bookedFilterFor = id === "booked" ? member?.email ?? "" : "";
966
+ return derive({ ...s, ...wanted });
967
+ },
968
+ closeLocations: (s) => {
969
+ if (!locationSheet) return s;
970
+ locationSheet = false;
971
+ return derive({ ...s, ...wanted });
972
+ },
973
+ // A row of the location sheet: "" is every location. Kept for Services and Choose Time too.
974
+ selectLocation: async (s, p): Promise<S | undefined> => {
975
+ const id = argOf(p, "locationId");
976
+ const choice = agendaLocations(services ?? [], sessions, chosenLocation).find((c) => c.key === id);
977
+ chosenLocation = id && choice ? { id, label: choice.label } : { id: "", label: "" };
978
+ locationSheet = false;
979
+ settleJump();
980
+ // Rows above the selected day may have come or gone: the list must land on it again.
981
+ scrollNonce += 1;
982
+ // Not awaited (it never throws): the new list shows at once, whatever the store does.
983
+ void writeSharedLocation(chosenLocation);
984
+ return settled(derive(newView({ ...s, ...wanted })));
985
+ },
986
+ },
987
+ });
988
+ export { svc };