@salla.sa/twilight-components 2.14.518 → 2.14.520

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 (335) hide show
  1. package/dist/cjs/{filepond-9vuLCcek.js → filepond-B-CXEiqm.js} +1 -1
  2. package/dist/cjs/{filepond-plugin-file-poster-CEj7iH7g.js → filepond-plugin-file-poster-wldzYT1k.js} +1 -1
  3. package/dist/cjs/{filepond-plugin-file-validate-size-CyiZTXc-.js → filepond-plugin-file-validate-size-DEKUs2ql.js} +1 -1
  4. package/dist/cjs/{filepond-plugin-file-validate-type-DeJCL4Yd.js → filepond-plugin-file-validate-type-V0nWqzLp.js} +1 -1
  5. package/dist/cjs/{filepond-plugin-image-edit-B1x3Y_zU.js → filepond-plugin-image-edit-C60jMfjF.js} +1 -1
  6. package/dist/cjs/{filepond-plugin-image-exif-orientation-BJaXZ40E.js → filepond-plugin-image-exif-orientation-7rjvzakW.js} +1 -1
  7. package/dist/cjs/{filepond-plugin-image-preview-Di3BZCqQ.js → filepond-plugin-image-preview-CBjNXDm7.js} +1 -1
  8. package/dist/cjs/{functions-DMnGNEY0.js → functions-w4n1Dw12.js} +1 -1
  9. package/dist/cjs/{index-BlM04jZj.js → index-CP4_ZHev.js} +2 -2
  10. package/dist/cjs/{index-DpgcSE84.js → index-Dtd8NT7W.js} +1 -1
  11. package/dist/cjs/loader.cjs.js +1 -1
  12. package/dist/cjs/salla-accordion-body_2.cjs.entry.js +1 -1
  13. package/dist/cjs/salla-accordion_6.cjs.entry.js +1 -1
  14. package/dist/cjs/salla-add-product-button_5.cjs.entry.js +1 -1
  15. package/dist/cjs/salla-advertisement.cjs.entry.js +1 -1
  16. package/dist/cjs/salla-alert_2.cjs.entry.js +1 -1
  17. package/dist/cjs/salla-app-install-alert.cjs.entry.js +1 -1
  18. package/dist/cjs/salla-apps-icons.cjs.entry.js +1 -1
  19. package/dist/cjs/salla-badge.cjs.entry.js +1 -1
  20. package/dist/cjs/salla-basket-gap.cjs.entry.js +1 -1
  21. package/dist/cjs/salla-booking-field_7.cjs.entry.js +10 -10
  22. package/dist/cjs/salla-bullet-delivery_2.cjs.entry.js +1 -1
  23. package/dist/cjs/salla-cart-coupons.cjs.entry.js +1 -1
  24. package/dist/cjs/salla-cart-item-offers_2.cjs.entry.js +1 -1
  25. package/dist/cjs/salla-cart-summary-card.cjs.entry.js +1 -1
  26. package/dist/cjs/salla-cashback-banner.cjs.entry.js +1 -1
  27. package/dist/cjs/salla-comment-factors.cjs.entry.js +1 -1
  28. package/dist/cjs/salla-comment-form_8.cjs.entry.js +1 -1
  29. package/dist/cjs/salla-conditional-offer.cjs.entry.js +1 -1
  30. package/dist/cjs/salla-contacts.cjs.entry.js +1 -1
  31. package/dist/cjs/salla-cookies-bar.cjs.entry.js +1 -1
  32. package/dist/cjs/salla-count-down_2.cjs.entry.js +1 -1
  33. package/dist/cjs/salla-custom-fields.cjs.entry.js +1 -1
  34. package/dist/cjs/salla-delivery-promise.cjs.entry.js +1 -1
  35. package/dist/cjs/salla-edit-order-button.cjs.entry.js +1 -1
  36. package/dist/cjs/salla-filters-widget.cjs.entry.js +1 -1
  37. package/dist/cjs/salla-filters.cjs.entry.js +1 -1
  38. package/dist/cjs/salla-fulfillment-methods.cjs.entry.js +1 -1
  39. package/dist/cjs/salla-gifting.cjs.entry.js +1 -1
  40. package/dist/cjs/salla-hook.cjs.entry.js +1 -1
  41. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +1 -1
  42. package/dist/cjs/salla-installment.cjs.entry.js +2 -2
  43. package/dist/cjs/salla-list-tile.cjs.entry.js +1 -1
  44. package/dist/cjs/salla-localization-modal.cjs.entry.js +1 -1
  45. package/dist/cjs/salla-login-modal.cjs.entry.js +1 -1
  46. package/dist/cjs/salla-loyalty-banner.cjs.entry.js +2 -2
  47. package/dist/cjs/salla-loyalty-exchange-product-card_5.cjs.entry.js +3 -3
  48. package/dist/cjs/salla-loyalty-hero_2.cjs.entry.js +2 -2
  49. package/dist/cjs/salla-loyalty-panel.cjs.entry.js +3 -3
  50. package/dist/cjs/salla-loyalty-points-banner.cjs.entry.js +1 -1
  51. package/dist/cjs/salla-loyalty-points-history.cjs.entry.js +1 -1
  52. package/dist/cjs/salla-loyalty-prize-item.cjs.entry.js +1 -1
  53. package/dist/cjs/salla-loyalty-program.cjs.entry.js +3 -3
  54. package/dist/cjs/salla-loyalty-reward.cjs.entry.js +2 -2
  55. package/dist/cjs/salla-loyalty.cjs.entry.js +1 -1
  56. package/dist/cjs/salla-maintenance-alert.cjs.entry.js +1 -1
  57. package/dist/cjs/salla-map_2.cjs.entry.js +1 -1
  58. package/dist/cjs/salla-menu.cjs.entry.js +1 -1
  59. package/dist/cjs/salla-metadata.cjs.entry.js +1 -1
  60. package/dist/cjs/salla-multiple-bundle-product-cart_2.cjs.entry.js +1 -1
  61. package/dist/cjs/salla-multiple-bundle-product-options-modal_2.cjs.entry.js +1 -1
  62. package/dist/cjs/salla-multiple-bundle-product.cjs.entry.js +1 -1
  63. package/dist/cjs/salla-next-order-coupon.cjs.entry.js +1 -1
  64. package/dist/cjs/salla-notification-item.cjs.entry.js +1 -1
  65. package/dist/cjs/salla-notifications.cjs.entry.js +1 -1
  66. package/dist/cjs/salla-offer-modal.cjs.entry.js +1 -1
  67. package/dist/cjs/salla-offer.cjs.entry.js +1 -1
  68. package/dist/cjs/salla-order-branch.cjs.entry.js +1 -1
  69. package/dist/cjs/salla-order-cancel.cjs.entry.js +1 -1
  70. package/dist/cjs/salla-order-details-multiple-bundle-product.cjs.entry.js +1 -1
  71. package/dist/cjs/salla-order-details-options.cjs.entry.js +1 -1
  72. package/dist/cjs/salla-order-details.cjs.entry.js +1 -1
  73. package/dist/cjs/salla-order-edit-item.cjs.entry.js +1 -1
  74. package/dist/cjs/salla-order-edit-product-card.cjs.entry.js +1 -1
  75. package/dist/cjs/salla-order-edit.cjs.entry.js +1 -1
  76. package/dist/cjs/salla-order-shipments.cjs.entry.js +1 -1
  77. package/dist/cjs/salla-order-summary.cjs.entry.js +1 -1
  78. package/dist/cjs/salla-order-totals-card.cjs.entry.js +1 -1
  79. package/dist/cjs/salla-orders.cjs.entry.js +1 -1
  80. package/dist/cjs/salla-payments.cjs.entry.js +4 -4
  81. package/dist/cjs/salla-placeholder.cjs.entry.js +1 -1
  82. package/dist/cjs/salla-price-range.cjs.entry.js +1 -1
  83. package/dist/cjs/salla-product-card-embed.cjs.entry.js +1 -1
  84. package/dist/cjs/salla-product-card_2.cjs.entry.js +1 -1
  85. package/dist/cjs/salla-product-size-guide.cjs.entry.js +1 -1
  86. package/dist/cjs/salla-products-list.cjs.entry.js +1 -1
  87. package/dist/cjs/salla-quick-order.cjs.entry.js +1 -1
  88. package/dist/cjs/salla-rating-modal-v2.cjs.entry.js +1 -1
  89. package/dist/cjs/salla-rating-modal.cjs.entry.js +1 -1
  90. package/dist/cjs/salla-review-factors-tags.cjs.entry.js +1 -1
  91. package/dist/cjs/salla-scopes.cjs.entry.js +1 -1
  92. package/dist/cjs/salla-search.cjs.entry.js +1 -1
  93. package/dist/cjs/salla-skeleton.cjs.entry.js +1 -1
  94. package/dist/cjs/salla-slider.cjs.entry.js +1 -1
  95. package/dist/cjs/salla-social-share.cjs.entry.js +1 -1
  96. package/dist/cjs/salla-social.cjs.entry.js +1 -1
  97. package/dist/cjs/salla-tab-content_3.cjs.entry.js +1 -1
  98. package/dist/cjs/salla-tiered-offer.cjs.entry.js +1 -1
  99. package/dist/cjs/salla-tooltip.cjs.entry.js +1 -1
  100. package/dist/cjs/salla-trust-badges.cjs.entry.js +1 -1
  101. package/dist/cjs/salla-user-menu.cjs.entry.js +1 -1
  102. package/dist/cjs/salla-user-profile.cjs.entry.js +1 -1
  103. package/dist/cjs/salla-user-settings.cjs.entry.js +1 -1
  104. package/dist/cjs/salla-verify.cjs.entry.js +1 -1
  105. package/dist/cjs/salla-wallet.cjs.entry.js +1 -1
  106. package/dist/cjs/salla-wishlist-actions.cjs.entry.js +1 -1
  107. package/dist/cjs/{tracked-promise-Dzrn1HHw.js → tracked-promise-C8HPKIHB.js} +1 -1
  108. package/dist/cjs/twilight.cjs.js +1 -1
  109. package/dist/cjs/{vanilla-picker-DxM-y1YM.js → vanilla-picker-CfkLDKtB.js} +1 -1
  110. package/dist/collection/components/salla-installment/salla-installment.js +1 -1
  111. package/dist/collection/components/salla-payments/salla-payments.js +3 -3
  112. package/dist/components/index.js +2 -2
  113. package/dist/components/salla-installment.js +1 -1
  114. package/dist/components/salla-payments.js +3 -3
  115. package/dist/esm/{filepond-DFcndQrC.js → filepond-B5AhUd5X.js} +1 -1
  116. package/dist/esm/{filepond-plugin-file-poster-D_PB-IZU.js → filepond-plugin-file-poster-CyUKDIOX.js} +1 -1
  117. package/dist/esm/{filepond-plugin-file-validate-size-BDNeMPPZ.js → filepond-plugin-file-validate-size-oDM0RkiJ.js} +1 -1
  118. package/dist/esm/{filepond-plugin-file-validate-type-BVlfa6XH.js → filepond-plugin-file-validate-type-Bgr0PP4V.js} +1 -1
  119. package/dist/esm/{filepond-plugin-image-edit-B4N_DIO8.js → filepond-plugin-image-edit-CQNKQMzk.js} +1 -1
  120. package/dist/esm/{filepond-plugin-image-exif-orientation-DltZqUg4.js → filepond-plugin-image-exif-orientation-6bqQCmnQ.js} +1 -1
  121. package/dist/esm/{filepond-plugin-image-preview-BaTVWxTU.js → filepond-plugin-image-preview-BxAmNds6.js} +1 -1
  122. package/dist/esm/{functions-Bs_j7WYO.js → functions-UlRBW71R.js} +1 -1
  123. package/dist/esm/{index-CDmdUxH2.js → index-CGCbZsu6.js} +1 -1
  124. package/dist/esm/{index-C2RHZyoj.js → index-DjOBdfDM.js} +2 -2
  125. package/dist/esm/loader.js +2 -2
  126. package/dist/esm/salla-accordion-body_2.entry.js +1 -1
  127. package/dist/esm/salla-accordion_6.entry.js +1 -1
  128. package/dist/esm/salla-add-product-button_5.entry.js +1 -1
  129. package/dist/esm/salla-advertisement.entry.js +1 -1
  130. package/dist/esm/salla-alert_2.entry.js +1 -1
  131. package/dist/esm/salla-app-install-alert.entry.js +1 -1
  132. package/dist/esm/salla-apps-icons.entry.js +1 -1
  133. package/dist/esm/salla-badge.entry.js +1 -1
  134. package/dist/esm/salla-basket-gap.entry.js +1 -1
  135. package/dist/esm/salla-booking-field_7.entry.js +10 -10
  136. package/dist/esm/salla-bullet-delivery_2.entry.js +1 -1
  137. package/dist/esm/salla-cart-coupons.entry.js +1 -1
  138. package/dist/esm/salla-cart-item-offers_2.entry.js +1 -1
  139. package/dist/esm/salla-cart-summary-card.entry.js +1 -1
  140. package/dist/esm/salla-cashback-banner.entry.js +1 -1
  141. package/dist/esm/salla-comment-factors.entry.js +1 -1
  142. package/dist/esm/salla-comment-form_8.entry.js +1 -1
  143. package/dist/esm/salla-conditional-offer.entry.js +1 -1
  144. package/dist/esm/salla-contacts.entry.js +1 -1
  145. package/dist/esm/salla-cookies-bar.entry.js +1 -1
  146. package/dist/esm/salla-count-down_2.entry.js +1 -1
  147. package/dist/esm/salla-custom-fields.entry.js +1 -1
  148. package/dist/esm/salla-delivery-promise.entry.js +1 -1
  149. package/dist/esm/salla-edit-order-button.entry.js +1 -1
  150. package/dist/esm/salla-filters-widget.entry.js +1 -1
  151. package/dist/esm/salla-filters.entry.js +1 -1
  152. package/dist/esm/salla-fulfillment-methods.entry.js +1 -1
  153. package/dist/esm/salla-gifting.entry.js +1 -1
  154. package/dist/esm/salla-hook.entry.js +1 -1
  155. package/dist/esm/salla-infinite-scroll.entry.js +1 -1
  156. package/dist/esm/salla-installment.entry.js +2 -2
  157. package/dist/esm/salla-list-tile.entry.js +1 -1
  158. package/dist/esm/salla-localization-modal.entry.js +1 -1
  159. package/dist/esm/salla-login-modal.entry.js +1 -1
  160. package/dist/esm/salla-loyalty-banner.entry.js +2 -2
  161. package/dist/esm/salla-loyalty-exchange-product-card_5.entry.js +3 -3
  162. package/dist/esm/salla-loyalty-hero_2.entry.js +2 -2
  163. package/dist/esm/salla-loyalty-panel.entry.js +3 -3
  164. package/dist/esm/salla-loyalty-points-banner.entry.js +1 -1
  165. package/dist/esm/salla-loyalty-points-history.entry.js +1 -1
  166. package/dist/esm/salla-loyalty-prize-item.entry.js +1 -1
  167. package/dist/esm/salla-loyalty-program.entry.js +3 -3
  168. package/dist/esm/salla-loyalty-reward.entry.js +2 -2
  169. package/dist/esm/salla-loyalty.entry.js +1 -1
  170. package/dist/esm/salla-maintenance-alert.entry.js +1 -1
  171. package/dist/esm/salla-map_2.entry.js +1 -1
  172. package/dist/esm/salla-menu.entry.js +1 -1
  173. package/dist/esm/salla-metadata.entry.js +1 -1
  174. package/dist/esm/salla-multiple-bundle-product-cart_2.entry.js +1 -1
  175. package/dist/esm/salla-multiple-bundle-product-options-modal_2.entry.js +1 -1
  176. package/dist/esm/salla-multiple-bundle-product.entry.js +1 -1
  177. package/dist/esm/salla-next-order-coupon.entry.js +1 -1
  178. package/dist/esm/salla-notification-item.entry.js +1 -1
  179. package/dist/esm/salla-notifications.entry.js +1 -1
  180. package/dist/esm/salla-offer-modal.entry.js +1 -1
  181. package/dist/esm/salla-offer.entry.js +1 -1
  182. package/dist/esm/salla-order-branch.entry.js +1 -1
  183. package/dist/esm/salla-order-cancel.entry.js +1 -1
  184. package/dist/esm/salla-order-details-multiple-bundle-product.entry.js +1 -1
  185. package/dist/esm/salla-order-details-options.entry.js +1 -1
  186. package/dist/esm/salla-order-details.entry.js +1 -1
  187. package/dist/esm/salla-order-edit-item.entry.js +1 -1
  188. package/dist/esm/salla-order-edit-product-card.entry.js +1 -1
  189. package/dist/esm/salla-order-edit.entry.js +1 -1
  190. package/dist/esm/salla-order-shipments.entry.js +1 -1
  191. package/dist/esm/salla-order-summary.entry.js +1 -1
  192. package/dist/esm/salla-order-totals-card.entry.js +1 -1
  193. package/dist/esm/salla-orders.entry.js +1 -1
  194. package/dist/esm/salla-payments.entry.js +4 -4
  195. package/dist/esm/salla-placeholder.entry.js +1 -1
  196. package/dist/esm/salla-price-range.entry.js +1 -1
  197. package/dist/esm/salla-product-card-embed.entry.js +1 -1
  198. package/dist/esm/salla-product-card_2.entry.js +1 -1
  199. package/dist/esm/salla-product-size-guide.entry.js +1 -1
  200. package/dist/esm/salla-products-list.entry.js +1 -1
  201. package/dist/esm/salla-quick-order.entry.js +1 -1
  202. package/dist/esm/salla-rating-modal-v2.entry.js +1 -1
  203. package/dist/esm/salla-rating-modal.entry.js +1 -1
  204. package/dist/esm/salla-review-factors-tags.entry.js +1 -1
  205. package/dist/esm/salla-scopes.entry.js +1 -1
  206. package/dist/esm/salla-search.entry.js +1 -1
  207. package/dist/esm/salla-skeleton.entry.js +1 -1
  208. package/dist/esm/salla-slider.entry.js +1 -1
  209. package/dist/esm/salla-social-share.entry.js +1 -1
  210. package/dist/esm/salla-social.entry.js +1 -1
  211. package/dist/esm/salla-tab-content_3.entry.js +1 -1
  212. package/dist/esm/salla-tiered-offer.entry.js +1 -1
  213. package/dist/esm/salla-tooltip.entry.js +1 -1
  214. package/dist/esm/salla-trust-badges.entry.js +1 -1
  215. package/dist/esm/salla-user-menu.entry.js +1 -1
  216. package/dist/esm/salla-user-profile.entry.js +1 -1
  217. package/dist/esm/salla-user-settings.entry.js +1 -1
  218. package/dist/esm/salla-verify.entry.js +1 -1
  219. package/dist/esm/salla-wallet.entry.js +1 -1
  220. package/dist/esm/salla-wishlist-actions.entry.js +1 -1
  221. package/dist/esm/{tracked-promise-Bac1d5rP.js → tracked-promise-CjzMNHuW.js} +1 -1
  222. package/dist/esm/twilight.js +2 -2
  223. package/dist/esm/{vanilla-picker-DkDn1mCy.js → vanilla-picker-C0WhEpLR.js} +1 -1
  224. package/dist/twilight/{p-DPxh47LR.js → p--ucq83XK.js} +1 -1
  225. package/dist/twilight/{p-e7ce766b.entry.js → p-0103f018.entry.js} +1 -1
  226. package/dist/twilight/{p-9248fdf2.entry.js → p-04c4ac9d.entry.js} +1 -1
  227. package/dist/twilight/{p-d3f1c168.entry.js → p-0697f8d6.entry.js} +1 -1
  228. package/dist/twilight/{p-85bf6531.entry.js → p-07f53154.entry.js} +1 -1
  229. package/dist/twilight/{p-19da2b5f.entry.js → p-0b77c960.entry.js} +1 -1
  230. package/dist/twilight/{p-27c7a2c9.entry.js → p-123bd7f1.entry.js} +1 -1
  231. package/dist/twilight/p-12b95fd5.entry.js +4 -0
  232. package/dist/twilight/{p-e066ba8a.entry.js → p-1334a1aa.entry.js} +1 -1
  233. package/dist/twilight/{p-816fa850.entry.js → p-1485dba4.entry.js} +1 -1
  234. package/dist/twilight/{p-e707b1b3.entry.js → p-14ab267b.entry.js} +1 -1
  235. package/dist/twilight/p-157963b1.entry.js +4 -0
  236. package/dist/twilight/{p-abaac4b2.entry.js → p-15afb5f2.entry.js} +1 -1
  237. package/dist/twilight/{p-e6c22a1d.entry.js → p-16d00717.entry.js} +1 -1
  238. package/dist/twilight/{p-1a35503d.entry.js → p-1d2bc592.entry.js} +1 -1
  239. package/dist/twilight/{p-d7292a7d.entry.js → p-1e1a77d1.entry.js} +1 -1
  240. package/dist/twilight/{p-d3341f15.entry.js → p-1e80102d.entry.js} +1 -1
  241. package/dist/twilight/{p-dc62af21.entry.js → p-259956fe.entry.js} +1 -1
  242. package/dist/twilight/{p-6adfa24a.entry.js → p-26b01da9.entry.js} +1 -1
  243. package/dist/twilight/{p-ebadf5db.entry.js → p-2bcd9e4b.entry.js} +1 -1
  244. package/dist/twilight/{p-e5a53d38.entry.js → p-359351e3.entry.js} +1 -1
  245. package/dist/twilight/{p-bd432397.entry.js → p-395dfda3.entry.js} +1 -1
  246. package/dist/twilight/{p-5d90d656.entry.js → p-3a3145e4.entry.js} +1 -1
  247. package/dist/twilight/{p-6efbd4c4.entry.js → p-41e66fae.entry.js} +1 -1
  248. package/dist/twilight/{p-0c0b0f17.entry.js → p-441fcdb4.entry.js} +1 -1
  249. package/dist/twilight/{p-93f3e882.entry.js → p-468d142a.entry.js} +1 -1
  250. package/dist/twilight/{p-d70dcd98.entry.js → p-4705b3ee.entry.js} +1 -1
  251. package/dist/twilight/{p-7c8f7654.entry.js → p-484522bf.entry.js} +1 -1
  252. package/dist/twilight/{p-e7a63e62.entry.js → p-4b764afc.entry.js} +1 -1
  253. package/dist/twilight/{p-14e4d573.entry.js → p-4d650b67.entry.js} +1 -1
  254. package/dist/twilight/{p-2c562480.entry.js → p-4e708377.entry.js} +1 -1
  255. package/dist/twilight/{p-d0e105b6.entry.js → p-509279da.entry.js} +1 -1
  256. package/dist/twilight/{p-5ccf3db9.entry.js → p-50940460.entry.js} +1 -1
  257. package/dist/twilight/{p-eb1f64cd.entry.js → p-517cdc60.entry.js} +1 -1
  258. package/dist/twilight/{p-c410c308.entry.js → p-5202a5a2.entry.js} +1 -1
  259. package/dist/twilight/{p-4f40c588.entry.js → p-53e47f9d.entry.js} +1 -1
  260. package/dist/twilight/{p-f6964426.entry.js → p-56554552.entry.js} +1 -1
  261. package/dist/twilight/{p-0562b11a.entry.js → p-5cc43d68.entry.js} +1 -1
  262. package/dist/twilight/{p-beb10a19.entry.js → p-6183d223.entry.js} +1 -1
  263. package/dist/twilight/{p-0f46096a.entry.js → p-6bc0a7cb.entry.js} +1 -1
  264. package/dist/twilight/{p-0bf8b901.entry.js → p-6d114c0b.entry.js} +1 -1
  265. package/dist/twilight/{p-38daf7e5.entry.js → p-70416928.entry.js} +1 -1
  266. package/dist/twilight/{p-2461d714.entry.js → p-71b24810.entry.js} +1 -1
  267. package/dist/twilight/{p-b09b6eac.entry.js → p-75c5d67c.entry.js} +1 -1
  268. package/dist/twilight/{p-ca767303.entry.js → p-767fc48b.entry.js} +1 -1
  269. package/dist/twilight/{p-07172f87.entry.js → p-7782ef7a.entry.js} +1 -1
  270. package/dist/twilight/{p-f1aee1ed.entry.js → p-779e8604.entry.js} +1 -1
  271. package/dist/twilight/{p-5516c00f.entry.js → p-79994729.entry.js} +1 -1
  272. package/dist/twilight/{p-413ed3a8.entry.js → p-7ccd3918.entry.js} +1 -1
  273. package/dist/twilight/{p-170b0b20.entry.js → p-7daa82fe.entry.js} +1 -1
  274. package/dist/twilight/{p-5ffe3f2d.entry.js → p-7df3873f.entry.js} +1 -1
  275. package/dist/twilight/{p-edd24a95.entry.js → p-80b34fa0.entry.js} +1 -1
  276. package/dist/twilight/{p-6106b77f.entry.js → p-815559c2.entry.js} +1 -1
  277. package/dist/twilight/{p-8ac8ae79.entry.js → p-8633dca6.entry.js} +1 -1
  278. package/dist/twilight/{p-d6595f08.entry.js → p-877de10b.entry.js} +1 -1
  279. package/dist/twilight/{p-bf8dc054.entry.js → p-8aa94d13.entry.js} +1 -1
  280. package/dist/twilight/{p-6383c0c9.entry.js → p-8d77fc58.entry.js} +1 -1
  281. package/dist/twilight/{p-ffb7f5e3.entry.js → p-8fba19d5.entry.js} +1 -1
  282. package/dist/twilight/{p-affa8fba.entry.js → p-937f7f9b.entry.js} +1 -1
  283. package/dist/twilight/{p-25e4db15.entry.js → p-93f7e2a0.entry.js} +1 -1
  284. package/dist/twilight/{p-d4f95050.entry.js → p-96908e15.entry.js} +1 -1
  285. package/dist/twilight/{p-d341d13d.entry.js → p-977d4b62.entry.js} +1 -1
  286. package/dist/twilight/{p-850ee472.entry.js → p-97bf34f8.entry.js} +1 -1
  287. package/dist/twilight/{p-52e08fdf.entry.js → p-9a259cd4.entry.js} +1 -1
  288. package/dist/twilight/{p-4f1b21ae.entry.js → p-9e1fa90c.entry.js} +1 -1
  289. package/dist/twilight/{p-fb79c232.entry.js → p-9e950969.entry.js} +1 -1
  290. package/dist/twilight/{p-709e6928.entry.js → p-9edb33a2.entry.js} +1 -1
  291. package/dist/twilight/{p-b9ca0260.entry.js → p-9f384e06.entry.js} +1 -1
  292. package/dist/twilight/{p-8pvTyiJe.js → p-9td0x-W4.js} +1 -1
  293. package/dist/twilight/p-B6g8RXLV.js +4 -0
  294. package/dist/twilight/{p-DP7_3WjR.js → p-BXjd-F0j.js} +1 -1
  295. package/dist/twilight/{p-Bq836xP-.js → p-CYbUnAsY.js} +1 -1
  296. package/dist/twilight/{p-IiKvzpNh.js → p-D136Y0xG.js} +1 -1
  297. package/dist/twilight/{p-C2RHZyoj.js → p-DjOBdfDM.js} +1 -1
  298. package/dist/twilight/{p-QQHVhk5Y.js → p-Djm0oxTL.js} +1 -1
  299. package/dist/twilight/{p-BajcFLeO.js → p-DyQCnC43.js} +1 -1
  300. package/dist/twilight/{p-rMqhG07q.js → p-Z5t88y_p.js} +1 -1
  301. package/dist/twilight/{p-a0e1c93b.entry.js → p-a3e65c78.entry.js} +1 -1
  302. package/dist/twilight/{p-fe686d0e.entry.js → p-a4c2aaf4.entry.js} +1 -1
  303. package/dist/twilight/{p-8b673e8d.entry.js → p-a539d51c.entry.js} +1 -1
  304. package/dist/twilight/{p-7f4d38c3.entry.js → p-a53b3edf.entry.js} +1 -1
  305. package/dist/twilight/{p-8a4ca0ae.entry.js → p-a83693c7.entry.js} +1 -1
  306. package/dist/twilight/{p-73b94072.entry.js → p-a8ccb3b5.entry.js} +1 -1
  307. package/dist/twilight/{p-79b8068e.entry.js → p-a9853194.entry.js} +1 -1
  308. package/dist/twilight/{p-899202da.entry.js → p-aeef91fe.entry.js} +1 -1
  309. package/dist/twilight/{p-6e50105e.entry.js → p-af61b17f.entry.js} +1 -1
  310. package/dist/twilight/{p-f9c442ef.entry.js → p-af88e681.entry.js} +1 -1
  311. package/dist/twilight/{p-35ec17e1.entry.js → p-b357f9ea.entry.js} +1 -1
  312. package/dist/twilight/{p-810d4d3c.entry.js → p-ba2ec852.entry.js} +1 -1
  313. package/dist/twilight/{p-7b774173.entry.js → p-bbf6ad7e.entry.js} +1 -1
  314. package/dist/twilight/{p-828d9df1.entry.js → p-bf78b156.entry.js} +1 -1
  315. package/dist/twilight/{p-f806661c.entry.js → p-c0f2f74c.entry.js} +1 -1
  316. package/dist/twilight/{p-e0a7907c.entry.js → p-c4297ff7.entry.js} +1 -1
  317. package/dist/twilight/{p-fcfa3759.entry.js → p-c721e1f9.entry.js} +1 -1
  318. package/dist/twilight/{p-2093e47a.entry.js → p-d0a173d2.entry.js} +1 -1
  319. package/dist/twilight/{p-1fbf48e4.entry.js → p-d1f54ea9.entry.js} +1 -1
  320. package/dist/twilight/{p-1dc1808d.entry.js → p-d25eaeb2.entry.js} +1 -1
  321. package/dist/twilight/{p-2c7ecbda.entry.js → p-d3e569a0.entry.js} +1 -1
  322. package/dist/twilight/{p-767d8982.entry.js → p-d7b6f6d3.entry.js} +1 -1
  323. package/dist/twilight/{p-365bc069.entry.js → p-d90a4f86.entry.js} +1 -1
  324. package/dist/twilight/{p-75f96daa.entry.js → p-ea68294d.entry.js} +1 -1
  325. package/dist/twilight/{p-e9d45abb.entry.js → p-ee8d8338.entry.js} +1 -1
  326. package/dist/twilight/{p-bdc4cf8a.entry.js → p-f5c7d01f.entry.js} +1 -1
  327. package/dist/twilight/{p-31b4d58b.entry.js → p-f5fc1892.entry.js} +1 -1
  328. package/dist/twilight/{p-1e264b7b.entry.js → p-fa5c37c2.entry.js} +1 -1
  329. package/dist/twilight/{p-D3223Swj.js → p-n3pMJbfq.js} +1 -1
  330. package/dist/twilight/{p-tywMY7wu.js → p-utw6PQ3w.js} +1 -1
  331. package/dist/twilight/twilight.esm.js +1 -1
  332. package/package.json +5 -5
  333. package/dist/twilight/p-17f6d5e9.entry.js +0 -4
  334. package/dist/twilight/p-CAX4v4uY.js +0 -4
  335. package/dist/twilight/p-a23e9a84.entry.js +0 -4
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as s,h as e,a}from"./p-C2RHZyoj.js";import{S as t}from"./p-BscTeWDc.js";import{H as i}from"./p-XnA1YTjA.js";import"./p-CgtvEd63.js";const c=class{constructor(e){s(this,e),this.inputValue="",this.translationLoaded=!1,this.loading=!1,this.typing=!1,this.debounce=setTimeout((()=>""),1e3),this.placeholder=!1,this.inline=!1,this.oval=!1,this.height=60,this.maxWords=5,this.showAction=!1,this.productSlot=this.host.querySelector('[slot="product"]')?.innerHTML||this.getDefaultProductSlot(),salla.event.on("search::open",(()=>this.open())),salla.lang.onLoaded((()=>{this.translationLoaded=!0})),salla.event.on("modalClosed",(()=>this.onModalClose()))}async open(){this.inline||await this.modal.open().then((()=>setTimeout((()=>this.searchInput.focus()),300)))}onModalClose(){this.searchInput.value="",this.results=void 0,this.afterSearching(),this.container.classList.remove("s-search-no-results")}handleKeyDown(s){"Enter"===s.key&&this.search_term?.length&&(window.location.href=salla.url.get("search?q="+encodeURI(this.search_term)))}getDefaultProductSlot(){return'<div class="s-search-product-image-container"> <img class="s-search-product-image" src="{image}" alt="{name}"/></div><div class="s-search-product-details"> <div class="s-search-product-title">{name}</div> <div class="s-search-product-price">{price} <span class="s-search-product-regular-price">{regular_price}</span></div></div>'}debounceSearch(s){this.typing=!0,clearTimeout(this.debounce),this.debounce=setTimeout((()=>{this.typing=!1,this.search_term=s.target.value}),700)}limitWordsAndSearch(s){const e=s.target.value.trim().split(/\s+/);if(e.length>this.maxWords){const s=e.slice(0,this.maxWords).join(" ");this.searchInput.value=s}this.debounceSearch(s)}getQueryParam(s){return new URLSearchParams(window.location.search).get(s)}handleActionClick(){if(this.search_term&&this.search_term.length>2)return this.search(this.search_term)}handleSearch(s){this.inputValue=s,s.length>2?this.search(s):(this.results=void 0,this.afterSearching())}search(s){this.noResults.style.display="none",this.loading=!0,salla.product.fetch({source:"search",source_value:s}).then((e=>{this.results=e,salla.event.emit("Products Searched",s)})).catch((s=>"Query is same as previous one!"!==s?this.results=void 0:null)).finally((()=>this.afterSearching(!1)))}afterSearching(s=!0){this.noResults.style.display=s||this.results?.data.length>0?"none":"block",i.toggleElementClassIf(this.container,"s-search-container-open","s-search-no-results",(()=>this.results?.data.length)),this.loading=!1,salla.product.api.previousQuery="",this.inputValue.length<3&&this.container.classList.remove("s-search-no-results")}render(){const s=e("div",{key:"ca8dec5eb90cd0893a1a3364df34ba0ee4d60891",class:{"s-search-container":!0,"s-search-inline":this.inline},ref:s=>this.container=s},e("div",{key:"212f8180ecca220a8b89231311dec6cdf3ef0b06",class:"s-search-input-wrapper"},e("span",{key:"51fb0f9a2e342afd35eb82b57f55471aa9e1519f",class:"s-search-icon-wrap"},e("span",{key:"e75117068c51c6d200e8e20fa0f00ca02ed0c61d",class:"s-search-icon",innerHTML:this.loading?'<i class="s-search-spinner-loader"/>':t})),e("input",{key:"442b1704b75a33e8c9e02da8200151a1d8e8db72",type:"search",enterkeyhint:"search",autocomplete:"off",class:"s-search-input",placeholder:salla.lang.get("blocks.header.search_placeholder"),onInput:s=>this.limitWordsAndSearch(s),onKeyDown:s=>this.handleKeyDown(s),ref:s=>this.searchInput=s,style:{height:this.height+"px",borderRadius:this.oval?this.height/2+"px":""}}),this.showAction?e("salla-button",{loading:this.loading,class:{"s-search-action":!0,"s-search-action-oval":this.oval},onClick:()=>this.handleActionClick()},!this.loading&&e("span",{innerHTML:t})):null),e("div",{key:"f3b40ce4ec24678f6d8421f3da8ac9e1bd631c3a",class:"s-search-results"},this.results?.data.map((s=>e("a",{href:s.url+"?from=search-bar",class:{"s-search-product":!0,"s-search-product-not-available":!s.is_available},innerHTML:this.productSlot.replace(/\{name\}/g,s.name).replace(/\{price\}/g,s.price?salla.money(s.price):"").replace(/\{regular_price\}/g,s.is_on_sale&&s.regular_price?salla.money(s.regular_price):"").replace(/\{image\}/g,s.image.url)}))),e("p",{key:"fdbb21061c599a59c6d828eec80e8d591a708cca",ref:s=>this.noResults=s,class:"s-search-no-results-placeholder"},salla.lang.get("common.elements.no_options")))),a=e("salla-modal",{key:"ca90aea3fb92d1ba7d8270c26e2ecd82d5018784",position:"top",class:"s-search-modal",ref:s=>this.modal=s},s),i=e("div",{key:"73333ce51cabadc4963a9fe9d1372bb7d63925c8",class:"s-search-placeholder-wrapper s-search-inline"},e("div",{key:"77a66e9bba504557160c8c50d91f1216cc68f253",class:"s-search-input-wrapper"},e("span",{key:"18fb5ce6e3e72874e76dd1ef2c6db8718a68f778",class:"s-search-icon-wrap"},e("span",{key:"63b9e9af1c51647df734cc4d5cf7a825b922ce38",class:"s-search-icon",innerHTML:t})),e("button",{key:"b70169ed2d80ec2ad6b09952ad104824610212df",type:"button",class:"s-search-input s-search-placeholder-trigger",onClick:()=>this.open(),style:{height:this.height+"px",borderRadius:this.oval?this.height/2+"px":""}},salla.lang.get("blocks.header.search_placeholder"))),a);return this.placeholder?i:this.inline?e("div",{class:"s-search-modal"},s):a}componentDidLoad(){this.afterSearching(),this.searchInput.value=this.getQueryParam("q")}get host(){return a(this)}static get watchers(){return{search_term:["handleSearch"]}}};c.style=".s-search-placeholder-wrapper{position:relative;display:inline-block}.s-search-input-wrapper{position:relative}.s-search-placeholder-trigger{cursor:pointer;appearance:none;text-align:start}";export{c as salla_search}
4
+ import{r as s,h as e,a}from"./p-DjOBdfDM.js";import{S as t}from"./p-BscTeWDc.js";import{H as i}from"./p-XnA1YTjA.js";import"./p-CgtvEd63.js";const c=class{constructor(e){s(this,e),this.inputValue="",this.translationLoaded=!1,this.loading=!1,this.typing=!1,this.debounce=setTimeout((()=>""),1e3),this.placeholder=!1,this.inline=!1,this.oval=!1,this.height=60,this.maxWords=5,this.showAction=!1,this.productSlot=this.host.querySelector('[slot="product"]')?.innerHTML||this.getDefaultProductSlot(),salla.event.on("search::open",(()=>this.open())),salla.lang.onLoaded((()=>{this.translationLoaded=!0})),salla.event.on("modalClosed",(()=>this.onModalClose()))}async open(){this.inline||await this.modal.open().then((()=>setTimeout((()=>this.searchInput.focus()),300)))}onModalClose(){this.searchInput.value="",this.results=void 0,this.afterSearching(),this.container.classList.remove("s-search-no-results")}handleKeyDown(s){"Enter"===s.key&&this.search_term?.length&&(window.location.href=salla.url.get("search?q="+encodeURI(this.search_term)))}getDefaultProductSlot(){return'<div class="s-search-product-image-container"> <img class="s-search-product-image" src="{image}" alt="{name}"/></div><div class="s-search-product-details"> <div class="s-search-product-title">{name}</div> <div class="s-search-product-price">{price} <span class="s-search-product-regular-price">{regular_price}</span></div></div>'}debounceSearch(s){this.typing=!0,clearTimeout(this.debounce),this.debounce=setTimeout((()=>{this.typing=!1,this.search_term=s.target.value}),700)}limitWordsAndSearch(s){const e=s.target.value.trim().split(/\s+/);if(e.length>this.maxWords){const s=e.slice(0,this.maxWords).join(" ");this.searchInput.value=s}this.debounceSearch(s)}getQueryParam(s){return new URLSearchParams(window.location.search).get(s)}handleActionClick(){if(this.search_term&&this.search_term.length>2)return this.search(this.search_term)}handleSearch(s){this.inputValue=s,s.length>2?this.search(s):(this.results=void 0,this.afterSearching())}search(s){this.noResults.style.display="none",this.loading=!0,salla.product.fetch({source:"search",source_value:s}).then((e=>{this.results=e,salla.event.emit("Products Searched",s)})).catch((s=>"Query is same as previous one!"!==s?this.results=void 0:null)).finally((()=>this.afterSearching(!1)))}afterSearching(s=!0){this.noResults.style.display=s||this.results?.data.length>0?"none":"block",i.toggleElementClassIf(this.container,"s-search-container-open","s-search-no-results",(()=>this.results?.data.length)),this.loading=!1,salla.product.api.previousQuery="",this.inputValue.length<3&&this.container.classList.remove("s-search-no-results")}render(){const s=e("div",{key:"ca8dec5eb90cd0893a1a3364df34ba0ee4d60891",class:{"s-search-container":!0,"s-search-inline":this.inline},ref:s=>this.container=s},e("div",{key:"212f8180ecca220a8b89231311dec6cdf3ef0b06",class:"s-search-input-wrapper"},e("span",{key:"51fb0f9a2e342afd35eb82b57f55471aa9e1519f",class:"s-search-icon-wrap"},e("span",{key:"e75117068c51c6d200e8e20fa0f00ca02ed0c61d",class:"s-search-icon",innerHTML:this.loading?'<i class="s-search-spinner-loader"/>':t})),e("input",{key:"442b1704b75a33e8c9e02da8200151a1d8e8db72",type:"search",enterkeyhint:"search",autocomplete:"off",class:"s-search-input",placeholder:salla.lang.get("blocks.header.search_placeholder"),onInput:s=>this.limitWordsAndSearch(s),onKeyDown:s=>this.handleKeyDown(s),ref:s=>this.searchInput=s,style:{height:this.height+"px",borderRadius:this.oval?this.height/2+"px":""}}),this.showAction?e("salla-button",{loading:this.loading,class:{"s-search-action":!0,"s-search-action-oval":this.oval},onClick:()=>this.handleActionClick()},!this.loading&&e("span",{innerHTML:t})):null),e("div",{key:"f3b40ce4ec24678f6d8421f3da8ac9e1bd631c3a",class:"s-search-results"},this.results?.data.map((s=>e("a",{href:s.url+"?from=search-bar",class:{"s-search-product":!0,"s-search-product-not-available":!s.is_available},innerHTML:this.productSlot.replace(/\{name\}/g,s.name).replace(/\{price\}/g,s.price?salla.money(s.price):"").replace(/\{regular_price\}/g,s.is_on_sale&&s.regular_price?salla.money(s.regular_price):"").replace(/\{image\}/g,s.image.url)}))),e("p",{key:"fdbb21061c599a59c6d828eec80e8d591a708cca",ref:s=>this.noResults=s,class:"s-search-no-results-placeholder"},salla.lang.get("common.elements.no_options")))),a=e("salla-modal",{key:"ca90aea3fb92d1ba7d8270c26e2ecd82d5018784",position:"top",class:"s-search-modal",ref:s=>this.modal=s},s),i=e("div",{key:"73333ce51cabadc4963a9fe9d1372bb7d63925c8",class:"s-search-placeholder-wrapper s-search-inline"},e("div",{key:"77a66e9bba504557160c8c50d91f1216cc68f253",class:"s-search-input-wrapper"},e("span",{key:"18fb5ce6e3e72874e76dd1ef2c6db8718a68f778",class:"s-search-icon-wrap"},e("span",{key:"63b9e9af1c51647df734cc4d5cf7a825b922ce38",class:"s-search-icon",innerHTML:t})),e("button",{key:"b70169ed2d80ec2ad6b09952ad104824610212df",type:"button",class:"s-search-input s-search-placeholder-trigger",onClick:()=>this.open(),style:{height:this.height+"px",borderRadius:this.oval?this.height/2+"px":""}},salla.lang.get("blocks.header.search_placeholder"))),a);return this.placeholder?i:this.inline?e("div",{class:"s-search-modal"},s):a}componentDidLoad(){this.afterSearching(),this.searchInput.value=this.getQueryParam("q")}get host(){return a(this)}static get watchers(){return{search_term:["handleSearch"]}}};c.style=".s-search-placeholder-wrapper{position:relative;display:inline-block}.s-search-input-wrapper{position:relative}.s-search-placeholder-trigger{cursor:pointer;appearance:none;text-align:start}";export{c as salla_search}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as s,h as t,H as e}from"./p-C2RHZyoj.js";import{S as l}from"./p-BscTeWDc.js";var i;!function(s){s.DEFAULT="default",s.AVAILABILITY="availability"}(i||(i={}));const a=class{constructor(t){s(this,t),this.loadedScopes={[i.DEFAULT]:null,[i.AVAILABILITY]:null},this.translationLoaded=!1,this.mode=i.DEFAULT,this.scopes=[],this.originalScopesList=[],this.isOpenedBefore=salla.storage.get("branch-choosed-before"),this.hasError=!1,this.loading=!1,this.selection="optional",this.searchDisplayLimit=6,this.getFormTitle=()=>{if(this.originalScopesList?.length<2)return"";const s=salla.config.get("store.features")?.includes("multi-countries");return this.mode===i.DEFAULT?salla.lang.get(s?"blocks.scope.shopping_from_another_market":"blocks.scope.shopping_from_another_branch"):salla.lang.get("blocks.scope.search_for_availability_in_other_branches")},salla.event.on("scopes::open",(({mode:s=null,product_id:t=null}={})=>{this.open(s,t)})),salla.lang.onLoaded((()=>{this.translationLoaded=!0}))}get isNativeApp(){return!!salla.mobile?.isSpaWebview?.()}async close(){return await(this.modal?.close())}async open(s=i.DEFAULT,t=null){return this.isNativeApp?(salla.log("SallaScope:: delegated open to native app"),void salla.mobile?.openScopes?.()):(this.hasError=!1,this.mode=[i.AVAILABILITY,i.DEFAULT].includes(s)?s:i.DEFAULT,this.loading=!this.loadedScopes[this.mode],this.setScopeValues([]),salla.log("SallaScope:: opened"),this.modal.open(),this.loading?await salla.api.withoutNotifier((()=>s==i.AVAILABILITY?salla.scope.getProductAvailability(t):salla.scope.get())).then((t=>{if(s==i.AVAILABILITY)return this.setScopeValues(this.loadedScopes[i.AVAILABILITY]=t.data);this.setScopeValues(this.loadedScopes[this.mode]=t.data.scopes)})).catch((s=>{console.log(s),this.hasError=!0})).finally((()=>{this.modal.stopLoading(),this.loading=!1})):(this.setScopeValues(this.loadedScopes[this.mode]),this.modal.stopLoading()))}async handleSubmit(){let s={id:this.current_scope.id};return this.changeBtn.load(),await salla.scope.change(s).then((()=>{salla.storage.set("branch-choosed-before",!0),salla.storage.set("scope",{type:this.current_scope.type,id:this.current_scope.id}),salla.cart.reset(),window.location.replace(salla.helpers.addParamToUrl("scope",this.current_scope.id))})).catch((s=>console.log(s))).finally((()=>{this.changeBtn.stop()}))}setScopeValues(s){this.scopes=s,this.originalScopesList=s,1==s?.length?(this.current_scope=s[0],this.selected_scope=s[0],this.scopes=[s[0]]):(this.current_scope=s?.find((s=>s.selected)),this.selected_scope=s?.find((s=>s.selected)))}handleSearchFieldTyping(s){let t=s.target.value.toLocaleLowerCase();this.scopes=t?this.originalScopesList.filter((s=>s.name.toLowerCase().includes(t))):this.originalScopesList}handleScopeSelection(s){this.current_scope=this.scopes?.find((t=>t.id==s.target.value))}placeholderContent(){return t("salla-placeholder",{alignment:"center",class:"s-scopes-placeholder"},t("span",{slot:"title"},salla.lang.get("blocks.scope.branch_looking_for_not_found")),t("span",{slot:"description"},salla.lang.get("blocks.scope.our_services_not_available_in_this_branch")))}defaultContent(){return[t("div",{class:"s-scopes-container s-scrollbar"},this.scopes?.map((s=>t("div",{class:"s-scopes-input-wrap","data-selection":this.selection},t("input",{id:`${this.selection} + '_scope_' + ${s.id}`,name:"lang",type:"radio",value:s.id,onChange:s=>this.handleScopeSelection(s),class:"s-scopes-input",checked:!!this.current_scope&&this.current_scope.id==s.id}),t("label",{htmlFor:`${this.selection} + '_scope_' + ${s.id}`,class:"s-scopes-label s-scopes-clickable"},t("span",null,s.name)))))),this.footerContent()]}availabilityContent(){return t("div",{class:"s-scopes-container"},this.scopes?.map((s=>t("div",{class:"s-scopes-input-wrap","data-selection":this.selection},t("h2",{class:{"s-scopes-label":!0,"s-scopes-clickable":this.mode===i.DEFAULT}},t("span",null,s.name)),t("h2",{style:{color:s?.availability?.color},class:`s-scopes-${s?.availability?.key}`},s?.availability?.label)))))}footerContent(){return t("div",{class:"s-scopes-footer"},t("slot",{name:"footer"},t("salla-button",{ref:s=>this.changeBtn=s,disabled:!this.current_scope,onClick:()=>this.handleSubmit(),class:"s-scopes-submit","loader-position":"center",width:"wide"},salla.lang.get("common.elements.confirm"))))}componentWillLoad(){return salla.onReady()}render(){return this.isNativeApp?null:t(e,null,t("salla-modal",{ref:s=>this.modal=s,isClosable:!(!this.isOpenedBefore&&"optional"!=this.selection),class:"s-scopes-modal",isLoading:this.loading,"has-skeleton":!0},this.loading?t("div",{slot:"loading"},t("div",{class:"s-scopes-skeleton"},t("salla-list-tile",{class:"s-scopes-header"},t("div",{slot:"icon",class:"s-scopes-header-icon"},t("salla-skeleton",{type:"circle"})),t("div",{slot:"title",class:"s-scopes-header-title mb-5"},t("salla-skeleton",{height:"15px",width:"50%"})),t("div",{slot:"subtitle",class:"s-scopes-header-subtitle"},t("salla-skeleton",{height:"10px"}),t("salla-skeleton",{height:"10px",width:"75%"}))),t("div",{class:"s-scopes-skeleton-search"},t("salla-skeleton",{height:"10px",width:"50%"}),t("salla-skeleton",{height:"30px",width:"100%"})),t("div",{class:"s-scopes-skeleton-scopes"},t("salla-skeleton",{height:"10px",width:"30%"}),t("salla-skeleton",{height:"10px",width:"25%"}),t("salla-skeleton",{height:"10px",width:"30%"}),t("salla-skeleton",{height:"10px",width:"25%"}),t("salla-skeleton",{height:"10px",width:"30%"}),t("salla-skeleton",{height:"10px",width:"25%"}),t("salla-skeleton",{height:"10px",width:"30%"}),t("salla-skeleton",{height:"10px",width:"25%"})),t("div",{class:"s-scopes-skeleton-btn"},t("salla-skeleton",{height:"40px",width:"100%"})))):[t("salla-list-tile",{class:this.originalScopesList?.length?"s-scopes-header block":"s-hidden"},t("div",{slot:"icon",class:"s-scopes-header-icon",innerHTML:'\x3c!-- Generated by IcoMoon.io --\x3e\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">\n<title>store-alt</title>\n<path d="M6.667 24h5.333c0.736 0 1.333-0.596 1.333-1.333s-0.597-1.333-1.333-1.333h-5.333c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333zM31.86 10.071l-4-8c-0.227-0.452-0.688-0.737-1.193-0.737h-21.333c-0.505 0-0.967 0.285-1.193 0.737l-4 8c-0.092 0.184-0.14 0.389-0.14 0.596v18.667c0 0.737 0.597 1.333 1.333 1.333h29.333c0.736 0 1.333-0.596 1.333-1.333v-18.667c0-0.207-0.048-0.412-0.14-0.596zM6.157 4h19.685l3.333 6.667h-26.352zM24 28h-5.333v-9.333h5.333zM29.333 28h-2.667v-10.667c0-0.737-0.597-1.333-1.333-1.333h-8c-0.736 0-1.333 0.596-1.333 1.333v10.667h-13.333v-14.667h26.667zM6.667 18.667h5.333c0.736 0 1.333-0.596 1.333-1.333s-0.597-1.333-1.333-1.333h-5.333c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333z"></path>\n</svg>\n'}),t("div",{slot:"title",class:"s-scopes-header-title"},salla.lang.get("blocks.scope.you_are_browse_store_from")),t("div",{slot:"subtitle",class:"s-scopes-header-subtitle"},this.selected_scope?this.selected_scope.name:"")),t("div",{class:"s-scopes-wrap"},!!this.originalScopesList?.length&&t("h4",{class:"s-scopes-title"},this.getFormTitle()),this.originalScopesList?.length>this.searchDisplayLimit?t("div",{class:"s-scopes-search-wrapper"},t("div",{class:"s-scopes-search-icon",innerHTML:l}),t("input",{type:"text",class:"s-scopes-search-input",onInput:s=>this.handleSearchFieldTyping(s),enterkeyhint:"search",placeholder:salla.lang.get("blocks.scope.searching_for_a_branch")})):"",this.hasError||!this.originalScopesList?.length&&this.mode!==i.AVAILABILITY?this.placeholderContent():this.mode===i.DEFAULT?this.defaultContent():this.availabilityContent())]))}async componentDidLoad(){await Salla.hooks.registerComponent("salla-scopes",this),salla.config.isMobileApp()||this.isNativeApp||this.isOpenedBefore||"mandatory"!=this.selection||this.open()}};a.style=".s-scopes-availability-content{display:flex;justify-content:center;align-items:center}.s-scopes-placeholder{flex:0 0 85%}";export{a as salla_scopes}
4
+ import{r as s,h as t,H as e}from"./p-DjOBdfDM.js";import{S as l}from"./p-BscTeWDc.js";var i;!function(s){s.DEFAULT="default",s.AVAILABILITY="availability"}(i||(i={}));const a=class{constructor(t){s(this,t),this.loadedScopes={[i.DEFAULT]:null,[i.AVAILABILITY]:null},this.translationLoaded=!1,this.mode=i.DEFAULT,this.scopes=[],this.originalScopesList=[],this.isOpenedBefore=salla.storage.get("branch-choosed-before"),this.hasError=!1,this.loading=!1,this.selection="optional",this.searchDisplayLimit=6,this.getFormTitle=()=>{if(this.originalScopesList?.length<2)return"";const s=salla.config.get("store.features")?.includes("multi-countries");return this.mode===i.DEFAULT?salla.lang.get(s?"blocks.scope.shopping_from_another_market":"blocks.scope.shopping_from_another_branch"):salla.lang.get("blocks.scope.search_for_availability_in_other_branches")},salla.event.on("scopes::open",(({mode:s=null,product_id:t=null}={})=>{this.open(s,t)})),salla.lang.onLoaded((()=>{this.translationLoaded=!0}))}get isNativeApp(){return!!salla.mobile?.isSpaWebview?.()}async close(){return await(this.modal?.close())}async open(s=i.DEFAULT,t=null){return this.isNativeApp?(salla.log("SallaScope:: delegated open to native app"),void salla.mobile?.openScopes?.()):(this.hasError=!1,this.mode=[i.AVAILABILITY,i.DEFAULT].includes(s)?s:i.DEFAULT,this.loading=!this.loadedScopes[this.mode],this.setScopeValues([]),salla.log("SallaScope:: opened"),this.modal.open(),this.loading?await salla.api.withoutNotifier((()=>s==i.AVAILABILITY?salla.scope.getProductAvailability(t):salla.scope.get())).then((t=>{if(s==i.AVAILABILITY)return this.setScopeValues(this.loadedScopes[i.AVAILABILITY]=t.data);this.setScopeValues(this.loadedScopes[this.mode]=t.data.scopes)})).catch((s=>{console.log(s),this.hasError=!0})).finally((()=>{this.modal.stopLoading(),this.loading=!1})):(this.setScopeValues(this.loadedScopes[this.mode]),this.modal.stopLoading()))}async handleSubmit(){let s={id:this.current_scope.id};return this.changeBtn.load(),await salla.scope.change(s).then((()=>{salla.storage.set("branch-choosed-before",!0),salla.storage.set("scope",{type:this.current_scope.type,id:this.current_scope.id}),salla.cart.reset(),window.location.replace(salla.helpers.addParamToUrl("scope",this.current_scope.id))})).catch((s=>console.log(s))).finally((()=>{this.changeBtn.stop()}))}setScopeValues(s){this.scopes=s,this.originalScopesList=s,1==s?.length?(this.current_scope=s[0],this.selected_scope=s[0],this.scopes=[s[0]]):(this.current_scope=s?.find((s=>s.selected)),this.selected_scope=s?.find((s=>s.selected)))}handleSearchFieldTyping(s){let t=s.target.value.toLocaleLowerCase();this.scopes=t?this.originalScopesList.filter((s=>s.name.toLowerCase().includes(t))):this.originalScopesList}handleScopeSelection(s){this.current_scope=this.scopes?.find((t=>t.id==s.target.value))}placeholderContent(){return t("salla-placeholder",{alignment:"center",class:"s-scopes-placeholder"},t("span",{slot:"title"},salla.lang.get("blocks.scope.branch_looking_for_not_found")),t("span",{slot:"description"},salla.lang.get("blocks.scope.our_services_not_available_in_this_branch")))}defaultContent(){return[t("div",{class:"s-scopes-container s-scrollbar"},this.scopes?.map((s=>t("div",{class:"s-scopes-input-wrap","data-selection":this.selection},t("input",{id:`${this.selection} + '_scope_' + ${s.id}`,name:"lang",type:"radio",value:s.id,onChange:s=>this.handleScopeSelection(s),class:"s-scopes-input",checked:!!this.current_scope&&this.current_scope.id==s.id}),t("label",{htmlFor:`${this.selection} + '_scope_' + ${s.id}`,class:"s-scopes-label s-scopes-clickable"},t("span",null,s.name)))))),this.footerContent()]}availabilityContent(){return t("div",{class:"s-scopes-container"},this.scopes?.map((s=>t("div",{class:"s-scopes-input-wrap","data-selection":this.selection},t("h2",{class:{"s-scopes-label":!0,"s-scopes-clickable":this.mode===i.DEFAULT}},t("span",null,s.name)),t("h2",{style:{color:s?.availability?.color},class:`s-scopes-${s?.availability?.key}`},s?.availability?.label)))))}footerContent(){return t("div",{class:"s-scopes-footer"},t("slot",{name:"footer"},t("salla-button",{ref:s=>this.changeBtn=s,disabled:!this.current_scope,onClick:()=>this.handleSubmit(),class:"s-scopes-submit","loader-position":"center",width:"wide"},salla.lang.get("common.elements.confirm"))))}componentWillLoad(){return salla.onReady()}render(){return this.isNativeApp?null:t(e,null,t("salla-modal",{ref:s=>this.modal=s,isClosable:!(!this.isOpenedBefore&&"optional"!=this.selection),class:"s-scopes-modal",isLoading:this.loading,"has-skeleton":!0},this.loading?t("div",{slot:"loading"},t("div",{class:"s-scopes-skeleton"},t("salla-list-tile",{class:"s-scopes-header"},t("div",{slot:"icon",class:"s-scopes-header-icon"},t("salla-skeleton",{type:"circle"})),t("div",{slot:"title",class:"s-scopes-header-title mb-5"},t("salla-skeleton",{height:"15px",width:"50%"})),t("div",{slot:"subtitle",class:"s-scopes-header-subtitle"},t("salla-skeleton",{height:"10px"}),t("salla-skeleton",{height:"10px",width:"75%"}))),t("div",{class:"s-scopes-skeleton-search"},t("salla-skeleton",{height:"10px",width:"50%"}),t("salla-skeleton",{height:"30px",width:"100%"})),t("div",{class:"s-scopes-skeleton-scopes"},t("salla-skeleton",{height:"10px",width:"30%"}),t("salla-skeleton",{height:"10px",width:"25%"}),t("salla-skeleton",{height:"10px",width:"30%"}),t("salla-skeleton",{height:"10px",width:"25%"}),t("salla-skeleton",{height:"10px",width:"30%"}),t("salla-skeleton",{height:"10px",width:"25%"}),t("salla-skeleton",{height:"10px",width:"30%"}),t("salla-skeleton",{height:"10px",width:"25%"})),t("div",{class:"s-scopes-skeleton-btn"},t("salla-skeleton",{height:"40px",width:"100%"})))):[t("salla-list-tile",{class:this.originalScopesList?.length?"s-scopes-header block":"s-hidden"},t("div",{slot:"icon",class:"s-scopes-header-icon",innerHTML:'\x3c!-- Generated by IcoMoon.io --\x3e\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">\n<title>store-alt</title>\n<path d="M6.667 24h5.333c0.736 0 1.333-0.596 1.333-1.333s-0.597-1.333-1.333-1.333h-5.333c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333zM31.86 10.071l-4-8c-0.227-0.452-0.688-0.737-1.193-0.737h-21.333c-0.505 0-0.967 0.285-1.193 0.737l-4 8c-0.092 0.184-0.14 0.389-0.14 0.596v18.667c0 0.737 0.597 1.333 1.333 1.333h29.333c0.736 0 1.333-0.596 1.333-1.333v-18.667c0-0.207-0.048-0.412-0.14-0.596zM6.157 4h19.685l3.333 6.667h-26.352zM24 28h-5.333v-9.333h5.333zM29.333 28h-2.667v-10.667c0-0.737-0.597-1.333-1.333-1.333h-8c-0.736 0-1.333 0.596-1.333 1.333v10.667h-13.333v-14.667h26.667zM6.667 18.667h5.333c0.736 0 1.333-0.596 1.333-1.333s-0.597-1.333-1.333-1.333h-5.333c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333z"></path>\n</svg>\n'}),t("div",{slot:"title",class:"s-scopes-header-title"},salla.lang.get("blocks.scope.you_are_browse_store_from")),t("div",{slot:"subtitle",class:"s-scopes-header-subtitle"},this.selected_scope?this.selected_scope.name:"")),t("div",{class:"s-scopes-wrap"},!!this.originalScopesList?.length&&t("h4",{class:"s-scopes-title"},this.getFormTitle()),this.originalScopesList?.length>this.searchDisplayLimit?t("div",{class:"s-scopes-search-wrapper"},t("div",{class:"s-scopes-search-icon",innerHTML:l}),t("input",{type:"text",class:"s-scopes-search-input",onInput:s=>this.handleSearchFieldTyping(s),enterkeyhint:"search",placeholder:salla.lang.get("blocks.scope.searching_for_a_branch")})):"",this.hasError||!this.originalScopesList?.length&&this.mode!==i.AVAILABILITY?this.placeholderContent():this.mode===i.DEFAULT?this.defaultContent():this.availabilityContent())]))}async componentDidLoad(){await Salla.hooks.registerComponent("salla-scopes",this),salla.config.isMobileApp()||this.isNativeApp||this.isOpenedBefore||"mandatory"!=this.selection||this.open()}};a.style=".s-scopes-availability-content{display:flex;justify-content:center;align-items:center}.s-scopes-placeholder{flex:0 0 85%}";export{a as salla_scopes}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as t,h as i,H as e}from"./p-C2RHZyoj.js";var s,a;!function(t){t.PERCENTAGE="percentage",t.FIXED="fixed",t.FREE_PRODUCT="free_product"}(s||(s={})),function(t){t.PRODUCT_COUNT="products_count",t.PRODUCT_PURCHASE="order_amount"}(a||(a={}));const l=class{constructor(i){t(this,i),this.offer=null,this.products={},this.isLoading=!1,this.canRender=!0}componentWillLoad(){salla.onReady().then((()=>{if(!salla.config.get("store.features")?.includes("conditional-offer")||""!==salla.storage.get("cart")&&!salla.storage.get("cart")?.summary?.count)throw new Error("feature or cart object does not existed")})).then((()=>salla.api.cart.offers())).then((({data:t})=>{if(this.offer=t.find((t=>"conditional"===t.type)),this.offer)return this.isLoading=!0,this.offer.details.discounts.unshift({value:0,min_spend:0}),this.updateInitialOfferValue();this.canRender=!1})).then((()=>{if(this.offer)return this.getProducts()})).then((()=>{this.offer&&salla.event.on("cart::updated",(t=>this.updateOfferValues(t)))})).catch((t=>{this.canRender=!1,salla.logger.warn("salla-conditional-offer:: ",t)})).finally((()=>{this.isLoading=!1}))}getProducts(){const t=this.offer.details.discounts.filter((({type:t})=>t===s.FREE_PRODUCT)).map((({value:t})=>t)).filter(Boolean);if(t.length>0)return salla.product.fetch({source:"selected",source_value:t}).then((t=>{const i=t?.data;if(i&&Array.isArray(i)){const t={...this.products};i.forEach((({id:i,url:e,image:s,name:a,price:l})=>{i&&a&&s?.url&&e&&void 0!==l&&(t[i]={url:e,image:s,name:a,price:l})})),this.products=t}}))}updateInitialOfferValue(){return salla.api.cart.details().then((({data:{cart:t}})=>this.updateOfferValues(t)))}updateOfferValues({items:t,sub_total:i}){const e=this.offer.details.based_on===a.PRODUCT_COUNT?t?.reduce(((t,{quantity:i})=>t+i),0)??0:i;return this.offer={...this.offer,details:{...this.offer?.details,current_value:e}},this.offer}renderTooltip(t){const e=t.value,s=this.products[e];return s?i("salla-tooltip",{class:"absolute left-0 -top-2",targetId:`avatar-product-${e}`,theme:"dark"},i("div",{class:"flex gap-3 text-start"},s?.image?.url&&i("img",{src:s.image.url,alt:s?.image?.alt||s.name||"",class:"w-12 h-12 object-cover rounded-lg flex-shrink-0",loading:"lazy",decoding:"async"}),i("div",{class:"flex-1"},i("div",{class:"leading-tight mb-1"},s.name),i("div",{class:"text-xs text-gray-300",innerHTML:salla.money(s.price)})))):(salla.logger.error(`salla-conditional-offer:: there is no product with id (${t.value})!`),null)}getCheckpointContent(t){if(t.type===s.PERCENTAGE)return`${t.value}%`;if(t.type===s.FIXED)return i("span",{innerHTML:salla.money(t.value)});if(t.type!==s.FREE_PRODUCT)return salla.logger.error(`salla-conditional-offer:: unexpected type (${t.type})!`),"";const e=this.products[t.value];return e?i("a",{class:"s-conditional-offer-product-link",href:e.url},i("img",{class:"s-conditional-offer-checkpoint-image-content",loading:"lazy",decoding:"async",alt:e?.image?.alt||"",src:e?.image?.url})):(salla.logger.error(`salla-conditional-offer:: there is no product with id (${t.value})!`),"")}getOfferType(t){const i=this.offer.details?.based_on;if(i===a.PRODUCT_COUNT)try{return salla.lang.choice("blocks.header.products_count",t.min_spend)}catch(i){return salla.logger.warn("salla-conditional-offer:: invalid products_count interval",i),`${t.min_spend}`}return i===a.PRODUCT_PURCHASE?salla.money(t.min_spend):(salla.logger.warn(`salla-conditional-offer:: Unexpected offer detail's based_on value: ${i}`),`${t.min_spend}`)}clamp(t,i,e){return Math.max(i,Math.min(t,e))}mapValueRanges(t,i,e,s,a){const l=(t-i)*(a-s)/(e-i)+s;return l===Number.POSITIVE_INFINITY?100:l===Number.NEGATIVE_INFINITY?0:this.clamp(l,0,100)}getCheckPointView(t,e){const a=this.offer.details.discounts.findIndex((({min_spend:i})=>i===t.min_spend)),l=this.mapValueRanges(this.offer.details.current_value,this.offer.details.discounts[a-1]?.min_spend??0,t.min_spend,0,100),n=t.min_spend<=this.offer.details.current_value;return i("div",{class:"s-conditional-offer-checkpoint-container"},e>0?[i("div",{key:"progress-line",class:"s-conditional-offer-progress-line-container"},i("div",{class:"s-conditional-offer-progress-line-inactive"}),i("div",{class:"s-conditional-offer-progress-line-active",style:{width:`${l}%`}})),i("div",{key:"checkpoint",class:"s-conditional-offer-checkpoint "+(n?"s-conditional-offer-active-checkpoint":"")},i("div",{class:"s-conditional-offer-item-avatar-content "+(n?"active":""),id:t.type===s.FREE_PRODUCT?`avatar-product-${t.value}`:`avatar-${t.value??e}`},this.products&&this.getCheckpointContent(t)),this.products&&t.type===s.FREE_PRODUCT&&this.renderTooltip(t),i("div",{class:"s-conditional-offer-checkpoint-label "+(n?"active":""),innerHTML:this.getOfferType(t)}))]:i("div",{key:"label",class:{"s-conditional-offer-checkpoint-label":!0,"first-checkpoint":0===e,active:n,hidden:0===e,"sm:block":0===e},innerHTML:this.getOfferType(t)}))}getLoadingSkeletonView(){return i(e,{class:"s-conditional-offer-container"},i("div",{class:"s-conditional-offer-skeleton-inner-container"},i("div",{class:"s-conditional-offer-skeleton-subtitle"},i("salla-skeleton",{height:"16px",width:"30%"})),i("div",{class:"s-conditional-offer-skeleton-subtitle"},i("salla-skeleton",{height:"16px",width:"35%"})),i("div",{class:"s-conditional-offer-skeleton-checkpoints-wrapper"},Array(3).fill(null).map((()=>[i("salla-skeleton",{key:"checkpoint-line",height:"8px"}),i("div",{key:"checkpoint"},i("salla-skeleton",{height:"60px",width:"60px",type:"circle"}))])))))}render(){return this.canRender?this.isLoading?this.getLoadingSkeletonView():this.offer?i(e,{class:"s-conditional-offer-container"},i("div",{class:"s-conditional-offer-title-wrapper"},i("div",{class:"s-conditional-offer-title"},this.offer.title),this.offer.description?i("div",{class:"s-conditional-offer-subtitle"},this.offer.description," ",i("i",{class:"sicon-information"})):null),i("div",{class:"s-conditional-offer-progress-container"},this.offer.details.discounts.map(((t,e)=>i("div",{class:{"flex-1":e>0},key:t.min_spend},this.getCheckPointView(t,e)))))):null:null}};l.style=":host{display:block}";export{l as salla_conditional_offer}
4
+ import{r as t,h as i,H as e}from"./p-DjOBdfDM.js";var s,a;!function(t){t.PERCENTAGE="percentage",t.FIXED="fixed",t.FREE_PRODUCT="free_product"}(s||(s={})),function(t){t.PRODUCT_COUNT="products_count",t.PRODUCT_PURCHASE="order_amount"}(a||(a={}));const l=class{constructor(i){t(this,i),this.offer=null,this.products={},this.isLoading=!1,this.canRender=!0}componentWillLoad(){salla.onReady().then((()=>{if(!salla.config.get("store.features")?.includes("conditional-offer")||""!==salla.storage.get("cart")&&!salla.storage.get("cart")?.summary?.count)throw new Error("feature or cart object does not existed")})).then((()=>salla.api.cart.offers())).then((({data:t})=>{if(this.offer=t.find((t=>"conditional"===t.type)),this.offer)return this.isLoading=!0,this.offer.details.discounts.unshift({value:0,min_spend:0}),this.updateInitialOfferValue();this.canRender=!1})).then((()=>{if(this.offer)return this.getProducts()})).then((()=>{this.offer&&salla.event.on("cart::updated",(t=>this.updateOfferValues(t)))})).catch((t=>{this.canRender=!1,salla.logger.warn("salla-conditional-offer:: ",t)})).finally((()=>{this.isLoading=!1}))}getProducts(){const t=this.offer.details.discounts.filter((({type:t})=>t===s.FREE_PRODUCT)).map((({value:t})=>t)).filter(Boolean);if(t.length>0)return salla.product.fetch({source:"selected",source_value:t}).then((t=>{const i=t?.data;if(i&&Array.isArray(i)){const t={...this.products};i.forEach((({id:i,url:e,image:s,name:a,price:l})=>{i&&a&&s?.url&&e&&void 0!==l&&(t[i]={url:e,image:s,name:a,price:l})})),this.products=t}}))}updateInitialOfferValue(){return salla.api.cart.details().then((({data:{cart:t}})=>this.updateOfferValues(t)))}updateOfferValues({items:t,sub_total:i}){const e=this.offer.details.based_on===a.PRODUCT_COUNT?t?.reduce(((t,{quantity:i})=>t+i),0)??0:i;return this.offer={...this.offer,details:{...this.offer?.details,current_value:e}},this.offer}renderTooltip(t){const e=t.value,s=this.products[e];return s?i("salla-tooltip",{class:"absolute left-0 -top-2",targetId:`avatar-product-${e}`,theme:"dark"},i("div",{class:"flex gap-3 text-start"},s?.image?.url&&i("img",{src:s.image.url,alt:s?.image?.alt||s.name||"",class:"w-12 h-12 object-cover rounded-lg flex-shrink-0",loading:"lazy",decoding:"async"}),i("div",{class:"flex-1"},i("div",{class:"leading-tight mb-1"},s.name),i("div",{class:"text-xs text-gray-300",innerHTML:salla.money(s.price)})))):(salla.logger.error(`salla-conditional-offer:: there is no product with id (${t.value})!`),null)}getCheckpointContent(t){if(t.type===s.PERCENTAGE)return`${t.value}%`;if(t.type===s.FIXED)return i("span",{innerHTML:salla.money(t.value)});if(t.type!==s.FREE_PRODUCT)return salla.logger.error(`salla-conditional-offer:: unexpected type (${t.type})!`),"";const e=this.products[t.value];return e?i("a",{class:"s-conditional-offer-product-link",href:e.url},i("img",{class:"s-conditional-offer-checkpoint-image-content",loading:"lazy",decoding:"async",alt:e?.image?.alt||"",src:e?.image?.url})):(salla.logger.error(`salla-conditional-offer:: there is no product with id (${t.value})!`),"")}getOfferType(t){const i=this.offer.details?.based_on;if(i===a.PRODUCT_COUNT)try{return salla.lang.choice("blocks.header.products_count",t.min_spend)}catch(i){return salla.logger.warn("salla-conditional-offer:: invalid products_count interval",i),`${t.min_spend}`}return i===a.PRODUCT_PURCHASE?salla.money(t.min_spend):(salla.logger.warn(`salla-conditional-offer:: Unexpected offer detail's based_on value: ${i}`),`${t.min_spend}`)}clamp(t,i,e){return Math.max(i,Math.min(t,e))}mapValueRanges(t,i,e,s,a){const l=(t-i)*(a-s)/(e-i)+s;return l===Number.POSITIVE_INFINITY?100:l===Number.NEGATIVE_INFINITY?0:this.clamp(l,0,100)}getCheckPointView(t,e){const a=this.offer.details.discounts.findIndex((({min_spend:i})=>i===t.min_spend)),l=this.mapValueRanges(this.offer.details.current_value,this.offer.details.discounts[a-1]?.min_spend??0,t.min_spend,0,100),n=t.min_spend<=this.offer.details.current_value;return i("div",{class:"s-conditional-offer-checkpoint-container"},e>0?[i("div",{key:"progress-line",class:"s-conditional-offer-progress-line-container"},i("div",{class:"s-conditional-offer-progress-line-inactive"}),i("div",{class:"s-conditional-offer-progress-line-active",style:{width:`${l}%`}})),i("div",{key:"checkpoint",class:"s-conditional-offer-checkpoint "+(n?"s-conditional-offer-active-checkpoint":"")},i("div",{class:"s-conditional-offer-item-avatar-content "+(n?"active":""),id:t.type===s.FREE_PRODUCT?`avatar-product-${t.value}`:`avatar-${t.value??e}`},this.products&&this.getCheckpointContent(t)),this.products&&t.type===s.FREE_PRODUCT&&this.renderTooltip(t),i("div",{class:"s-conditional-offer-checkpoint-label "+(n?"active":""),innerHTML:this.getOfferType(t)}))]:i("div",{key:"label",class:{"s-conditional-offer-checkpoint-label":!0,"first-checkpoint":0===e,active:n,hidden:0===e,"sm:block":0===e},innerHTML:this.getOfferType(t)}))}getLoadingSkeletonView(){return i(e,{class:"s-conditional-offer-container"},i("div",{class:"s-conditional-offer-skeleton-inner-container"},i("div",{class:"s-conditional-offer-skeleton-subtitle"},i("salla-skeleton",{height:"16px",width:"30%"})),i("div",{class:"s-conditional-offer-skeleton-subtitle"},i("salla-skeleton",{height:"16px",width:"35%"})),i("div",{class:"s-conditional-offer-skeleton-checkpoints-wrapper"},Array(3).fill(null).map((()=>[i("salla-skeleton",{key:"checkpoint-line",height:"8px"}),i("div",{key:"checkpoint"},i("salla-skeleton",{height:"60px",width:"60px",type:"circle"}))])))))}render(){return this.canRender?this.isLoading?this.getLoadingSkeletonView():this.offer?i(e,{class:"s-conditional-offer-container"},i("div",{class:"s-conditional-offer-title-wrapper"},i("div",{class:"s-conditional-offer-title"},this.offer.title),this.offer.description?i("div",{class:"s-conditional-offer-subtitle"},this.offer.description," ",i("i",{class:"sicon-information"})):null),i("div",{class:"s-conditional-offer-progress-container"},this.offer.details.discounts.map(((t,e)=>i("div",{class:{"flex-1":e>0},key:t.min_spend},this.getCheckPointView(t,e)))))):null:null}};l.style=":host{display:block}";export{l as salla_conditional_offer}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as t,h as e,H as i,a as s}from"./p-C2RHZyoj.js";const a=class{constructor(e){t(this,e),this.loading=!1,this.hasError=!1,this.productData=null}async componentWillLoad(){await salla.onReady(),await this.fetchProduct()}componentDidLoad(){this.ensureParentContainsFloats()}componentDidRender(){this.renderCardNode()}ensureParentContainsFloats(){if("left"!==this.align&&"right"!==this.align)return;const t=this.hostEl?.parentElement;if(!t)return;const e=getComputedStyle(t);"block"===e.display&&"visible"===e.overflow&&"none"===e.float&&(t.style.display="flow-root")}fetchProduct(){return this.productId?(this.loading=!0,this.hasError=!1,salla.api.withoutNotifier((()=>salla.product.api.getDetails(this.productId))).then((t=>{const e=t.data;this.productData=e??null,this.hasError=!e})).catch((()=>{this.productData=null,this.hasError=!0})).finally((()=>{this.loading=!1}))):(this.productData=null,this.loading=!1,void(this.hasError=!1))}renderCardNode(){if(!this.cardContainer)return;if(this.cardContainer.textContent="",!this.productData||this.loading||this.hasError)return;const t=window.customElements.get("custom-salla-product-card")?"custom-salla-product-card":"salla-product-card",e=document.createElement(t),i=this.source||"embed-card";e.setAttribute("source",i),e.product={...this.productData,url:this.withViewedSource(this.productData.url,i)},this.cardContainer.appendChild(e)}withViewedSource(t,e){if(!t)return t;try{const i=new URL(t,window.location.origin);return i.searchParams.set("_svs",e),i.toString()}catch{return t}}render(){const t={"s-product-card-embed-card":!0,"s-product-card-embed-card-align-left":"left"===this.align,"s-product-card-embed-card-align-right":"right"===this.align,"s-product-card-embed-card-align-center":"center"===this.align};return e(i,{key:"3d9fb0dc8473e0959bbe13b4f8c8eea7a51830ea"},this.hasError&&e("span",{key:"25228d6d007d7dcda5e5767e14d2c363abfdab3e",class:"s-product-card-embed-fallback"}),e("div",{key:"d66d592bfad1468b745f3a954c335f72ecda1e08",class:t,ref:t=>{this.cardContainer=t}}))}get hostEl(){return s(this)}};a.style='@charset "UTF-8";:host{display:inline-block;vertical-align:top;max-width:12rem}:host([align=left]){float:inline-start;margin-block-end:1em;margin-inline-end:1em;shape-outside:margin-box}:host([align=right]){float:inline-end;margin-block-end:1em;margin-inline-start:1em;shape-outside:margin-box}:host([align=center]){display:block;clear:both;margin-block:1em;margin-inline:auto}.s-product-card-embed-card{display:block}';export{a as salla_product_card_embed}
4
+ import{r as t,h as e,H as i,a as s}from"./p-DjOBdfDM.js";const a=class{constructor(e){t(this,e),this.loading=!1,this.hasError=!1,this.productData=null}async componentWillLoad(){await salla.onReady(),await this.fetchProduct()}componentDidLoad(){this.ensureParentContainsFloats()}componentDidRender(){this.renderCardNode()}ensureParentContainsFloats(){if("left"!==this.align&&"right"!==this.align)return;const t=this.hostEl?.parentElement;if(!t)return;const e=getComputedStyle(t);"block"===e.display&&"visible"===e.overflow&&"none"===e.float&&(t.style.display="flow-root")}fetchProduct(){return this.productId?(this.loading=!0,this.hasError=!1,salla.api.withoutNotifier((()=>salla.product.api.getDetails(this.productId))).then((t=>{const e=t.data;this.productData=e??null,this.hasError=!e})).catch((()=>{this.productData=null,this.hasError=!0})).finally((()=>{this.loading=!1}))):(this.productData=null,this.loading=!1,void(this.hasError=!1))}renderCardNode(){if(!this.cardContainer)return;if(this.cardContainer.textContent="",!this.productData||this.loading||this.hasError)return;const t=window.customElements.get("custom-salla-product-card")?"custom-salla-product-card":"salla-product-card",e=document.createElement(t),i=this.source||"embed-card";e.setAttribute("source",i),e.product={...this.productData,url:this.withViewedSource(this.productData.url,i)},this.cardContainer.appendChild(e)}withViewedSource(t,e){if(!t)return t;try{const i=new URL(t,window.location.origin);return i.searchParams.set("_svs",e),i.toString()}catch{return t}}render(){const t={"s-product-card-embed-card":!0,"s-product-card-embed-card-align-left":"left"===this.align,"s-product-card-embed-card-align-right":"right"===this.align,"s-product-card-embed-card-align-center":"center"===this.align};return e(i,{key:"3d9fb0dc8473e0959bbe13b4f8c8eea7a51830ea"},this.hasError&&e("span",{key:"25228d6d007d7dcda5e5767e14d2c363abfdab3e",class:"s-product-card-embed-fallback"}),e("div",{key:"d66d592bfad1468b745f3a954c335f72ecda1e08",class:t,ref:t=>{this.cardContainer=t}}))}get hostEl(){return s(this)}};a.style='@charset "UTF-8";:host{display:inline-block;vertical-align:top;max-width:12rem}:host([align=left]){float:inline-start;margin-block-end:1em;margin-inline-end:1em;shape-outside:margin-box}:host([align=right]){float:inline-end;margin-block-end:1em;margin-inline-start:1em;shape-outside:margin-box}:host([align=center]){display:block;clear:both;margin-block:1em;margin-inline:auto}.s-product-card-embed-card{display:block}';export{a as salla_product_card_embed}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as s,h as e,F as t,H as a}from"./p-C2RHZyoj.js";const r=class{constructor(e){s(this,e)}parseOrderDetailsData(s){this.parsedOrderDetailsData=s,this.parsedOrderDetailsData="string"==typeof this.orderDetails?JSON.parse(s):s}componentWillLoad(){this.parseOrderDetailsData(this.orderDetails),console.log("Parent componentWillLoad - parsedOrderDetailsData:",this.parsedOrderDetailsData)}renderOrderDetailsContent(){return this.parsedOrderDetailsData?[this.parsedOrderDetailsData.options&&this.parsedOrderDetailsData.options.length>0&&e("salla-order-details-options",{options:this.parsedOrderDetailsData.options}),this.parsedOrderDetailsData.sub_products&&this.parsedOrderDetailsData.sub_products.length>0&&e(t,null,e("h2",{class:"s-order-details-bundle-title"},salla.lang.get("pages.orders.sub_products")),e("div",{class:"s-order-details-bundle-content"},this.parsedOrderDetailsData.sub_products.map((s=>e("salla-order-details-multiple-bundle-product",{key:s?.id,productDetails:s})))))]:(console.warn("No parsedOrderDetailsData available"),null)}render(){return e(a,{key:"ffa22cae6c347b5acbe4836378f1f3843184e8f5",class:"s-order-details-wrapper"},this.renderOrderDetailsContent())}static get watchers(){return{orderDetails:["parseOrderDetailsData"]}}};r.style="";export{r as salla_order_details}
4
+ import{r as s,h as e,F as t,H as a}from"./p-DjOBdfDM.js";const r=class{constructor(e){s(this,e)}parseOrderDetailsData(s){this.parsedOrderDetailsData=s,this.parsedOrderDetailsData="string"==typeof this.orderDetails?JSON.parse(s):s}componentWillLoad(){this.parseOrderDetailsData(this.orderDetails),console.log("Parent componentWillLoad - parsedOrderDetailsData:",this.parsedOrderDetailsData)}renderOrderDetailsContent(){return this.parsedOrderDetailsData?[this.parsedOrderDetailsData.options&&this.parsedOrderDetailsData.options.length>0&&e("salla-order-details-options",{options:this.parsedOrderDetailsData.options}),this.parsedOrderDetailsData.sub_products&&this.parsedOrderDetailsData.sub_products.length>0&&e(t,null,e("h2",{class:"s-order-details-bundle-title"},salla.lang.get("pages.orders.sub_products")),e("div",{class:"s-order-details-bundle-content"},this.parsedOrderDetailsData.sub_products.map((s=>e("salla-order-details-multiple-bundle-product",{key:s?.id,productDetails:s})))))]:(console.warn("No parsedOrderDetailsData available"),null)}render(){return e(a,{key:"ffa22cae6c347b5acbe4836378f1f3843184e8f5",class:"s-order-details-wrapper"},this.renderOrderDetailsContent())}static get watchers(){return{orderDetails:["parseOrderDetailsData"]}}};r.style="";export{r as salla_order_details}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as t,c as s,h as i,H as a,a as e,e as o}from"./p-C2RHZyoj.js";import{P as n}from"./p-DY4LZmNP.js";import{H as l}from"./p-XnA1YTjA.js";import{a as r}from"./p-CL7OPpYS.js";import{B as c}from"./p-D3mWkc-3.js";import{D as d}from"./p-CoQJOPRz.js";import{S as h}from"./p-BZp0rKEO.js";import{C as p}from"./p-C6jIkM-X.js";import"./p-CgtvEd63.js";class u{constructor(t,s){this.host=t,this.productId=s,this.collected=!1,this.livePrice=0}static attach(t,s){const i=t.querySelector("salla-mini-checkout-widget");if(!i)return!1;const a=new u(t,String(s));return salla.product?.event?.onPriceUpdated?.((t=>{a.livePrice=Number(t?.data?.price)||a.livePrice})),i.addEventListener("click",(t=>a.handleWidgetClick(t,i)),!0),!0}getSelectedQuantity(){try{const t=document.querySelector("form.product-form"),s=t?.getElementSallaData?.(),i=Number(s instanceof FormData?s.get("quantity"):s?.quantity);if(Number.isFinite(i)&&i>0)return i}catch{}return Number(this.host.getAttribute("quantity"))||1}async handleWidgetClick(t,s){if(this.collected)return void(this.collected=!1);if(t.preventDefault(),t.stopImmediatePropagation(),!await this.validatePdpOptions())return;if(salla.config.isGuest())return void salla.api.auth.requireLoginThen("salla-add-product-button::oo.after-login",(()=>this.handleWidgetClick(t,s)));let i;s.classList.add("s-add-product-button-busy");try{i=await salla.api.withoutNotifier((()=>salla.product.api.getOrderOptions([{id:this.productId,quantity:this.getSelectedQuantity()}])))}catch(t){return salla?.logger?.warn?.("order-options: fetch failed",t),s.classList.remove("s-add-product-button-busy"),void this.resumeWidget(s)}s.classList.remove("s-add-product-button-busy");const a=i?.data?.order_options||[];if(!a.length)return void this.resumeWidget(s);const e=this.livePrice>0?this.livePrice:Number(i?.data?.products?.[0]?.price?.amount)||0,o=this.ensureModal();try{const t=await o.open({orderOptions:a,basePrice:e});this.injectIntoMini(t?.orderOptions||[]),this.resumeWidget(s)}catch{}}async validatePdpOptions(){const t=document.querySelector(`salla-product-options[product-id="${this.productId}"]`);return!t||("function"==typeof t.validateAndScroll?await t.validateAndScroll():"function"!=typeof t.reportValidity||await t.reportValidity())}injectIntoMini(t){if(!t.length)return;const s=this.productId,i=a=>{if(String(a?.id)===String(s))try{a?.payload?.set?.("order_options",t)}finally{salla.event.off("cart::before.add.item",i)}};salla.event.on("cart::before.add.item",i)}ensureModal(){let t=document.querySelector("salla-order-options-modal");return t||(t=document.createElement("salla-order-options-modal"),document.body.appendChild(t)),t}resumeWidget(t){this.collected=!0;const s=t.shadowRoot?.querySelector?.(".s-fast-checkout-button");s?s.click():"function"==typeof t.click&&t.click()}}const m=class{constructor(i){t(this,i),this.success=s(this,"success"),this.failed=s(this,"failed"),this.hostAttributes={},this.hasPreOrder=!1,this.productStatus="sale",this.productType="product",this.selectedOptions=[],this.buyNowText=salla.lang.get("pages.products.buy_now"),this.isDesktopViewport="undefined"==typeof window||window.matchMedia("(min-width: 768px)").matches,this.viewportMediaQuery=null,this.orderOptionsGateAttached=!1,this.onViewportChange=t=>{this.isDesktopViewport=t.matches,this.btn?.setText(t.matches&&this.passedLabel?this.passedLabel:this.getLabel())},salla.lang.onLoaded((()=>{this.buyNowText=salla.lang.get("pages.products.buy_now")}))}getLabel(){return"sale"===this.productStatus&&this.supportStickyBar&&!this.isDesktopViewport&&this.showQuickBuy&&this.isApplePayActive?n:this.hasPreOrder?salla.lang.get("pages.products.pre_order_now"):"sale"===this.productStatus&&"booking"===this.productType?salla.lang.get("pages.cart.book_now"):"sale"===this.productStatus?salla.lang.get("pages.cart.add_to_cart"):"donating"!==this.productType?salla.lang.get("pages.products.out_of_stock"):salla.lang.get("pages.products.donation_exceed")}addProductToCart(t){if("booking"===this.productType)return t.preventDefault(),this.addBookingProduct();if("submit"===this.hostAttributes.type)return!1;t.preventDefault(),this.btn?.disable();const s=document.querySelector(`salla-product-options[product-id="${this.productId}"]`);return s&&"function"==typeof s.validateAndScroll?s.validateAndScroll().then((async t=>{const s={isValid:t,component:this};if(await salla.hooks.call("salla-add-product-button","validate",s),s.isValid)return this._proceedAddToCart();this.btn?.enable()})).catch((()=>{this.btn?.enable()})):this._proceedAddToCart()}async _proceedAddToCart(){const t=this.host.closest("salla-products-list, salla-products-slider")??this.host.closest("salla-product-card, custom-salla-product-card"),s=Object.entries({id:this.productId,donation_amount:this.donatingAmount,quantity:this.quantity,endpoint:"quickAdd",source:l.getProductsSource(t?.getAttribute("source"))}).reduce(((t,[s,i])=>i?(t[s]=i,t):t),{});return salla.cart.addItem(s).then((async t=>(this.selectedOptions=[],this.btn?.enable(),this.success.emit(t),t))).catch((t=>{this.failed.emit(t),this.btn?.enable()}))}addBookingProduct(){return salla.config.isGuest()?(salla.auth.api.setAfterLoginEvent("booking::add",this.productId),void salla.event.dispatch("login::open")):salla.booking.add(this.productId).then((t=>this.success.emit(t))).catch((t=>this.failed.emit(t)))}getBtnAttributes(){for(let t=0;t<this.host.attributes.length;t++)["id","class"].includes(this.host.attributes[t].name)||(this.hostAttributes[this.host.attributes[t].name]=this.host.attributes[t].value);return this.hostAttributes}get notifyChannels(){return this.channels||salla.api.product.getAvailabilityChannels?.()||l.availabilityChannels()}getQuickBuyBtnAttributes(){return{...this.getBtnAttributes(),type:this.supportStickyBar&&!this.isDesktopViewport?"plain":"donating"==this.productType?"donate":"buy"}}miniCheckoutWidget(){let t=salla.config.get("store.id");if(t)return i("salla-mini-checkout-widget",{language:salla.lang.locale,"store-id":t,config:{user:salla.config.get("user"),failure_url:window.location.href},products:[this.productId],api:salla.config.get("store.api"),outline:!0,"form-selector":"form.product-form",class:"s-add-product-button-mini-checkout"},i("div",{slot:"widget-label",class:"s-add-product-button-mini-checkout-content"},i("span",{innerHTML:'\x3c!-- Generated by IcoMoon.io --\x3e\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">\n<title>full-wallet</title>\n<path d="M29 12h-26c-0.668-0.008-1.284-0.226-1.787-0.59l0.009 0.006c-0.744-0.552-1.222-1.428-1.222-2.416 0-1.657 1.343-3 2.999-3h6c0.552 0 1 0.448 1 1s-0.448 1-1 1v0h-6c-0.552 0-1 0.448-1 1 0 0.326 0.156 0.616 0.397 0.798l0.002 0.002c0.167 0.12 0.374 0.194 0.599 0.2l0.001 0h26c0.552 0 1 0.448 1 1s-0.448 1-1 1v0zM27 12c-0.552 0-1-0.448-1-1v0-3h-3c-0.552 0-1-0.448-1-1s0.448-1 1-1v0h4c0.552 0 1 0.448 1 1v0 4c0 0.552-0.448 1-1 1v0zM29 30h-26c-1.657 0-3-1.343-3-3v0-18c0-0.552 0.448-1 1-1s1 0.448 1 1v0 18c0 0.552 0.448 1 1 1v0h25v-5c0-0.552 0.448-1 1-1s1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM29 18c-0.552 0-1-0.448-1-1v0-6c0-0.552 0.448-1 1-1s1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM31 24h-7c-2.209 0-4-1.791-4-4s1.791-4 4-4v0h7c0.552 0 1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM24 18c-1.105 0-2 0.895-2 2s0.895 2 2 2v0h6v-4zM25 12c-0.001 0-0.001 0-0.002 0-0.389 0-0.726-0.222-0.891-0.546l-0.003-0.006-3.552-7.106-2.306 1.152c-0.13 0.066-0.284 0.105-0.447 0.105-0.552 0-1-0.448-1-1 0-0.39 0.223-0.727 0.548-0.892l0.006-0.003 3.2-1.6c0.13-0.067 0.284-0.106 0.447-0.106 0.39 0 0.727 0.223 0.892 0.548l0.003 0.006 4 8c0.067 0.13 0.106 0.285 0.106 0.448 0 0.552-0.448 1-1 1v0zM21 12c-0.001 0-0.001 0-0.002 0-0.389 0-0.726-0.222-0.891-0.546l-0.003-0.006-3.552-7.106-15.104 7.552c-0.13 0.066-0.284 0.105-0.447 0.105-0.552 0-1-0.448-1-1 0-0.39 0.223-0.727 0.548-0.892l0.006-0.003 16-8c0.13-0.067 0.284-0.106 0.447-0.106 0.39 0 0.727 0.223 0.892 0.548l0.003 0.006 4 8c0.067 0.13 0.106 0.285 0.106 0.448 0 0.552-0.448 1-1 1-0.001 0-0.001 0-0.002 0h0z"></path>\n</svg>\n'}),this.buyNowText))}componentWillLoad(){return salla.onReady().then((()=>{if(document.documentElement.classList.add("hydrated"),this.showQuickBuy=this.quickBuy&&salla.config.get("store.settings.buy_now")&&"sale"==this.productStatus&&"booking"!==this.productType,this.isApplePayActive=window.ApplePaySession?.canMakePayments()&&salla.config.get("store.settings.payments")?.includes("apple_pay")&&salla.config.get("store.settings.is_salla_gateway",!1),this.passedLabel=this.host.innerHTML.replace("\x3c!----\x3e","").trim(),this.passedLabel&&this.isDesktopViewport)return this.btn?.setText(this.passedLabel);"submit"===this.host.getAttribute("type")&&this.supportStickyBar&&(this.viewportMediaQuery=window.matchMedia("(min-width: 768px)"),this.viewportMediaQuery.addEventListener("change",this.onViewportChange))}))}render(){return this.host.closest(".swiper-slide")?.classList.contains("swiper-slide-duplicate")?"":this.hasSubscribedOptions?i(a,null,i("salla-product-availability",{...this.getBtnAttributes(),"is-subscribed":!0},i("span",{class:"s-hidden"},i("slot",null)))):"out-and-notify"===this.productStatus&&this.notifyChannels||this.hasOutOfStockOption?i(a,null,i("salla-product-availability",{...this.getBtnAttributes()},i("span",{class:"s-hidden"},i("slot",null)))):i(a,{class:{"s-add-product-button-with-quick-buy":this.showQuickBuy,"s-add-product-button-with-sticky-bar":this.supportStickyBar,"s-add-product-button-with-apple-pay":this.showQuickBuy&&this.isApplePayActive}},i("div",{class:{"s-add-product-button-main":this.showQuickBuy,"w-full":!document.getElementById("fast-checkout-js")||["financial_support","donating"].includes(this.productType)}},i("salla-button",{color:"sale"===this.productStatus?"primary":"light",type:"button",fill:"sale"===this.productStatus?"solid":"outline",ref:t=>this.btn=t,onClick:t=>this.addProductToCart(t),disabled:"sale"!==this.productStatus,...this.getBtnAttributes(),"loader-position":"center"},i("slot",null)),this.showQuickBuy&&document.getElementById("fast-checkout-js")&&!["financial_support","donating"].includes(this.productType)?this.miniCheckoutWidget():""),this.showQuickBuy&&this.isApplePayActive?i("salla-quick-buy",{...this.getQuickBuyBtnAttributes()}):"")}async componentDidLoad(){await Salla.hooks.registerComponent("salla-add-product-button",this),this.notifyOptionsAvailability&&salla.event.on("product-options::change",(async t=>{if(!["thumbnail","color","single-option"].includes(t.option.type))return;this.hasSubscribedOptions=!1,this.selectedOptions=await(document.querySelector(`salla-product-options[product-id="${this.productId}"]`)?.getSelectedOptions()),this.hasOutOfStockOption=await(document.querySelector(`salla-product-options[product-id="${this.productId}"]`)?.hasOutOfStockOption());let s=salla.storage.get(`product-${this.productId}-subscribed-options`);if((s||this.subscribedOptions)&&this.hasOutOfStockOption)if(salla.config.isGuest()){const t=s?s.map((t=>t.split(",").map((t=>parseInt(t))))):[];this.hasSubscribedOptions=t.length>0&&t.some((t=>t.every((t=>this.selectedOptions.some((s=>s.id===t))))))}else this.hasSubscribedOptions=!(!this.subscribedOptions||"null"===this.subscribedOptions||"[]"===this.subscribedOptions)&&JSON.parse(this.subscribedOptions).some((t=>t.every((t=>this.selectedOptions.some((s=>s.id===t))))))}))}componentDidRender(){!this.orderOptionsGateAttached&&this.productId&&salla.config.get("store.settings.order_options.mandatory",!1)&&u.attach(this.host,this.productId)&&(this.orderOptionsGateAttached=!0),!this.passedLabel||this.supportStickyBar&&!this.isDesktopViewport?(this.btn?.setText(this.getLabel()),salla.lang.onLoaded((()=>this.btn?.setText(this.getLabel())))):this.btn?.setText(this.passedLabel)}disconnectedCallback(){this.viewportMediaQuery?.removeEventListener("change",this.onViewportChange)}get host(){return e(this)}};m.style=":host{display:block}salla-add-product-button[width=wide]{width:100%}";const y=class{constructor(s){t(this,s),this.limit=3,this.recommendations=[],this.selectedIds=new Set,this.isLoading=!0,this.canRender=!0,this.isAdding=!1,this.title=salla.lang.get("pages.products.bought_together_title"),this.subtitle=salla.lang.get("pages.products.bought_together_subtitle"),this.buyTogetherFor=salla.lang.get("pages.products.buy_together_for"),this.resolvedProductId=0,this.listViewTracked=!1,salla.lang.onLoaded((()=>{this.title=salla.lang.get("pages.products.bought_together_title"),this.subtitle=salla.lang.get("pages.products.bought_together_subtitle"),this.buyTogetherFor=salla.lang.get("pages.products.buy_together_for")}))}componentWillLoad(){salla.onReady().then((()=>{if(!salla.config.get("store.settings.product.bought_together"))return void(this.canRender=!1);const t=salla.config.get("page.id");if(t)return this.resolvedProductId=t,r(String(t));this.canRender=!1})).then((t=>{if(!t?.length)return void(this.canRender=!1);const s=[String(this.resolvedProductId),...t.slice(0,this.limit)];return salla.product.fetch({source:"selected",source_value:s})})).then((t=>{if(!t)return;const s=t?.data??[];if(!s.length)return void(this.canRender=!1);const i=s.find((t=>String(t.id)===String(this.resolvedProductId))),a=s.filter((t=>String(t.id)!==String(this.resolvedProductId)));a.length?(this.recommendations=i?[i,...a]:a,this.selectedIds=new Set(this.recommendations.map((t=>t.id)))):this.canRender=!1})).catch((()=>{this.canRender=!1})).finally((()=>{this.isLoading=!1}))}componentDidRender(){!this.recommendations.length||this.listViewTracked||this.intersectionObserver||(this.intersectionObserver=new IntersectionObserver((t=>{t.some((t=>t.isIntersecting))&&(this.listViewTracked=!0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.emitListViewed())}),{threshold:.1}),this.intersectionObserver.observe(this.el))}disconnectedCallback(){this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0}emitListViewed(){const t=this.recommendations.filter((t=>!this.isMainProduct(t.id)));salla.event.emit("salla-bought-together::list.viewed",{products:t})}isMainProduct(t){return String(t)===String(this.resolvedProductId)}recommendedPosition(t){const s=this.recommendations.filter((t=>!this.isMainProduct(t.id))).findIndex((s=>String(s.id)===String(t)));return-1===s?-1:s+1}emitProductClicked(t,s){salla.event.emit("salla-bought-together::product.clicked",[{product:t,position:s}])}toggleProduct(t){const s=new Set(this.selectedIds);s.has(t)?s.delete(t):s.add(t),this.selectedIds=s}get totalPrice(){const t=this.recommendations.filter((t=>this.selectedIds.has(t.id))).reduce(((t,s)=>t+(s.price??0)),0),s=salla.config.get("store.currency.decimals")??2,i=Math.pow(10,s);return salla.money(Math.round(t*i)/i)}async addSelectedToCart(){if(this.isAdding||!this.selectedIds.size)return;this.isAdding=!0;let t=!1;try{for(const s of Array.from(this.selectedIds))try{salla.cart?.api&&(salla.cart.api.addToCartSource="pdp_fbt");const t=await salla.cart.addItem({id:s,endpoint:"quickAdd",source:"pdp_fbt"}),i=this.recommendations.find((t=>t.id===s));if(i){const a=this.isMainProduct(s)?0:this.recommendedPosition(s),e=t?.data?.items?.find((t=>String(t.product_id)===String(i.id)))??t?.data?.items?.slice(-1)[0];salla.event.emit("salla-bought-together::product.added",[{product:i,position:a,cartItem:e,cartId:t?.data?.id}])}}catch(s){salla.log(s),t=!0}t&&salla.error(salla.lang.get("common.messages.error"))}finally{this.isAdding=!1}}getSkeletonView(){return i(a,{class:"s-bought-together-entry"},i("div",{class:"s-bought-together-skeleton"},i("div",{class:"s-bought-together-skeleton-header"},i("salla-skeleton",{height:"16px",width:"35%"}),i("salla-skeleton",{height:"10px",width:"60%"})),Array(4).fill(null).map(((t,s)=>i("div",{key:s,class:"s-bought-together-skeleton-item"},i("salla-skeleton",{height:"22px",width:"22px"}),i("salla-skeleton",{height:"48px",width:"48px"}),i("div",{class:"s-bought-together-skeleton-info"},i("salla-skeleton",{height:"12px",width:"55%",style:{marginBottom:"3px"}}),i("salla-skeleton",{height:"10px",width:"25%"}))))),i("salla-skeleton",{height:"44px",width:"100%"})))}render(){return this.canRender?this.isLoading?this.getSkeletonView():this.recommendations.length?i(a,{class:"s-bought-together-entry"},i("div",{class:"s-bought-together-header"},i("h3",{class:"s-bought-together-title"},this.title),i("p",{class:"s-bought-together-subtitle"},this.subtitle)),i("div",{class:"s-bought-together-list"},this.recommendations.map((t=>i("div",{key:t.id,class:"s-bought-together-item"+(this.selectedIds.has(t.id)?"":" s-bought-together-item--unchecked")},i("label",{class:"s-bought-together-checkbox-label"},i("input",{type:"checkbox",class:"s-bought-together-checkbox",checked:this.selectedIds.has(t.id),onChange:()=>this.toggleProduct(t.id)}),i("span",{class:"s-bought-together-checkmark"})),i("a",{class:"s-bought-together-item-link",href:t.url,onClick:()=>!this.isMainProduct(t.id)&&this.emitProductClicked(t,this.recommendedPosition(t.id))},i("img",{class:"s-bought-together-item-img",src:t.image?.url||salla.url.cdn("images/s-empty.png"),alt:t.image?.alt||t.name,loading:"lazy",decoding:"async",onError:t=>{t.currentTarget.onerror=null,t.currentTarget.src=salla.url.cdn("images/s-empty.png")}}),i("span",{class:"s-bought-together-item-name"},t.name)),i("span",{class:"s-bought-together-item-price",innerHTML:null!=t.price?salla.money(t.price):""}))))),i("salla-button",{class:"s-bought-together-btn",disabled:!this.selectedIds.size||this.isAdding,loading:this.isAdding,onClick:()=>this.addSelectedToCart()},i("span",{innerHTML:`${this.buyTogetherFor} ${this.totalPrice}`}))):null:null}get el(){return e(this)}};y.style=':host{display:block}.s-bought-together-checkbox:checked~.s-bought-together-checkmark{background-color:var(--color-primary, #2ECC71);border-color:var(--color-primary, #2ECC71)}.s-bought-together-checkbox:checked~.s-bought-together-checkmark::after{content:"";display:block;width:5px;height:9px;border:solid #fff;border-width:0 2px 2px 0;transform:rotate(45deg);margin-top:-2px}';const g=class{constructor(s){t(this,s),this.isUser=salla.config.isUser(),this.translationLoaded=!1,this.notifyOptionsAvailability=!1,this.isSubscribed=!1,this.handleSubmitOptions=async()=>{let t={id:this.productId};if(!this.notifyOptionsAvailability)return t;let s=document.querySelector(`salla-product-options[product-id="${this.productId}"]`),i=Object.values(await(s?.getSelectedOptionsData())||{});if(i.length&&!await(s?.reportValidity())){let t=salla.lang.get("common.messages.required_fields");throw salla.error(t),t}return t.options=[],i.forEach((s=>{s&&!isNaN(s)&&t.options.push(Number(s))})),t},this.typing=t=>{const s=t.target.nextElementSibling;t.target.classList.remove("s-has-error"),s?.classList.contains("s-product-availability-error-msg")&&(s.innerText=""),13===t.keyCode&&this.submit()},salla.lang.onLoaded((()=>{this.translationLoaded=!0,this.title_=this.host.title||salla.lang.get("pages.products.notify_availability_title"),this.modal?.setTitle(this.title_)})),this.productId||(this.productId=salla.config.get("page.id")),this.isUser||(this.channelsWatcher(this.channels),this.title_=this.host.title||salla.lang.get("pages.products.notify_availability_title"),this.host.removeAttribute("title"))}channelsWatcher(t){let s=t||salla.api.product.getAvailabilityChannels?.()||l.availabilityChannels();this.channels_=s?s.split(","):[]}get isSubscribedToProduct(){return this.isSubscribed||!this.notifyOptionsAvailability&&(!!salla.api.product.isSubscribedToAvailability?.(this.productId)||!!salla.storage.get(`product-${this.productId}-subscribed`))}openModel(){this.handleSubmitOptions().then((t=>t?this.modal.open():null))}async submit(){let t=await this.handleSubmitOptions();if(this.isUser)return salla.api.product.availabilitySubscribe(t).then((()=>this.isSubscribed=!0));if(this.channels_.includes("sms")||this.channels_.includes("whatsapp")){let{phone:s,countryCode:i}=await this.mobileInput.getValues();t.country_code=i,t.phone=s}return this.channels_.includes("email")&&""!==this.email.value&&(t.email=this.email.value),await this.validateform(),this.btn.load().then((()=>this.btn.disable())).then((()=>salla.api.product.availabilitySubscribe(t))).then((()=>{if(this.notifyOptionsAvailability){if(t.options.length){let s=salla.storage.get(`product-${this.productId}-subscribed-options`)||[],i=t.options.join(",");s.includes(i)?salla.log("already subscribed to this options"):(s.push(i),salla.storage.set(`product-${this.productId}-subscribed-options`,s),this.isSubscribed=!0)}}else this.isSubscribed=!0})).then((()=>this.btn.stop())).then((()=>this.modal.close())).catch((()=>this.btn.stop()&&this.btn.enable()))}async validateform(){try{if(this.channels_.includes("email")){const t=l.isValidEmail(this.email.value);if(t)return;!t&&this.validateField(this.email,salla.lang.get("common.elements.email_is_valid"))}if((this.channels_.includes("sms")||this.channels_.includes("whatsapp"))&&await this.mobileInput.isValid())return}catch(t){throw"Please insert required fields"}}validateField(t,s){t.classList.add("s-has-error"),t.nextElementSibling.innerText="* "+s}render(){return i(a,{key:"ccb098126e7809a6386ff38c74dfa0f00f64deeb",class:"s-product-availability-wrap"},this.isSubscribedToProduct?i("div",{class:"s-product-availability-subscribed"},i("span",{innerHTML:c,class:"s-product-availability-subs-icon"}),salla.lang.get("pages.products.notify_availability_success")):i("salla-button",{width:"wide",onClick:()=>this.isUser?this.submit():this.openModel()},salla.lang.get("pages.products.notify_availability")),this.isUser||this.isSubscribedToProduct?"":this.renderModal())}renderModal(){return i("salla-modal",{ref:t=>this.modal=t,"modal-title":this.title_,subTitle:salla.lang.get("pages.products.notify_availability_subtitle"),width:"sm"},i("span",{slot:"icon",class:"s-product-availability-header-icon",innerHTML:c}),i("div",{class:"s-product-availability-body"},this.channels_.includes("email")?[i("label",{class:"s-product-availability-label"},salla.lang.get("common.elements.email")),i("input",{class:"s-product-availability-input",onKeyDown:t=>this.typing(t),placeholder:salla.lang.get("common.elements.email_placeholder")||"your@email.com",ref:t=>this.email=t,type:"email"}),i("span",{class:"s-product-availability-error-msg"})]:"",this.channels_.includes("sms")||this.channels_.includes("whatsapp")?[i("label",{class:"s-product-availability-label"},salla.lang.get("common.elements.mobile")),i("salla-tel-input",{ref:t=>this.mobileInput=t,onKeyDown:t=>this.typing(t)})]:""),i("div",{slot:"footer",class:"s-product-availability-footer"},i("salla-button",{class:"modal-cancel-btn",width:"wide",color:"light",fill:"outline",onClick:()=>this.modal.close()},salla.lang.get("common.elements.cancel")),i("salla-button",{class:"submit-btn","loader-position":"center",width:"wide",ref:t=>this.btn=t,onClick:()=>this.submit()},salla.lang.get("common.elements.submit"))))}get host(){return e(this)}static get watchers(){return{channels:["channelsWatcher"]}}};var f,b,w;g.style="",function(t){t[t.INIT=1]="INIT",t[t.IDLE=2]="IDLE",t[t.PROCESSING_QUEUED=9]="PROCESSING_QUEUED",t[t.PROCESSING=3]="PROCESSING",t[t.PROCESSING_COMPLETE=5]="PROCESSING_COMPLETE",t[t.PROCESSING_ERROR=6]="PROCESSING_ERROR",t[t.PROCESSING_REVERT_ERROR=10]="PROCESSING_REVERT_ERROR",t[t.LOADING=7]="LOADING",t[t.LOAD_ERROR=8]="LOAD_ERROR"}(f||(f={})),function(t){t[t.EMPTY=0]="EMPTY",t[t.IDLE=1]="IDLE",t[t.ERROR=2]="ERROR",t[t.BUSY=3]="BUSY",t[t.READY=4]="READY"}(b||(b={})),function(t){t[t.INPUT=1]="INPUT",t[t.LIMBO=2]="LIMBO",t[t.LOCAL=3]="LOCAL"}(w||(w={}));const v=class{constructor(a){if(t(this,a),this.changed=s(this,"changed"),this.fileTypes={pdf:"application/pdf",png:"image/png",jpg:"image/jpeg",word:"application/doc,application/ms-doc,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",exl:"application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",txt:"text/plain"},this.outOfStockText="",this.donationAmount=salla.lang.get("pages.products.donation_amount"),this.selectDonationAmount=salla.lang.getWithDefault("pages.products.select_donation_amount","تحديد مبلغ التبرع"),this.selectAmount=salla.lang.getWithDefault("pages.products.select_amount","اختر المبلغ"),this.isCustomDonation=!1,this.selectedOptions=[],this.canDisabled=!1,this.disableCardValue=!0,this.availableDigitalCardValues=[],this.userInitiatedValidation=!1,this.isCartMode=!1,this.availabilityMap={},this.productAvailable=!1,this.outSkus=[],this.ignoreDefaultCardValue=!1,this.productId=salla.config.get("page.id"),this.noPadding=!1,this.handleDonationOptions=(t,s,i)=>{if("custom"===s&&"input"===i){const s=t.target;return salla.helpers.inputDigitsOnly(s),salla.event.emit("product-options::donation-changed",{id:this.productId,price:s.value}),void s.dispatchEvent(new window.Event("change",{bubbles:!0}))}const a="option"===i?String(t.target?.value??""):"";if("option"===i&&"custom"===s&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()),this.isCustomDonation="custom"===a,this.donationInput){if("custom"===a?(this.donationInput.value="",this.donationInput.focus()):this.donationInput.value=a,"custom"===s)return;salla.event.emit("product-options::donation-changed",{id:this.productId,price:a})}},this.hideLabel=t=>!(t.type!==d.DONATION||!t.donation||t.donation.can_donate),this.getExpireDonationMessage=t=>{if(!t.donation)return;const s=t.donation.target_amount<=t.donation.collected_amount;return i("div",{class:{"s-product-options-donation-message":!0,"s-product-options-donation-completed":s,"s-product-options-donation-expired":!s}},i("p",null,t.donation.target_message),i("span",{innerHTML:s?salla.money(t.donation.target_amount):""}))},salla.lang.onLoaded((()=>{this.outOfStockText=salla.lang.get("pages.products.out_of_stock"),this.donationAmount=salla.lang.get("pages.products.donation_amount"),this.selectDonationAmount=salla.lang.getWithDefault("pages.products.select_donation_amount","تحديد مبلغ التبرع"),this.selectAmount=salla.lang.getWithDefault("pages.products.select_amount","اختر المبلغ")})),this.options)try{return void this.setOptionsData(Array.isArray(this.options)?this.options:JSON.parse(this.options))}catch(t){salla.log("Bad json passed via options prop")}Array.isArray(this.optionsData)||(salla.log("Options is not an array[] ---\x3e ",this.optionsData),this.setOptionsData([])),this.productId&&!salla.url.is_page("cart")&&salla.api.product.getDetails(this.productId,["options"]).then((t=>{this.productAvailable=!t.data.is_out_of_stock,this.setOptionsData(t.data.options)}))}async setOptionsData(t){this.optionsData=t,this.outSkus=[],this.optionsData[0]?.details?.forEach((t=>{Object.entries(t.skus_availability||{}).filter((([,t])=>!t)).forEach((([t])=>this.outSkus.push(Number(t))))})),this.fillSelectedOptions(),this.computeAvailability()}async getOptionsData(){return this.optionsData}async getSelectedOptionsData(){const t={},s=this.host.getElementSallaData(),i=void 0!==this.bundleContext?this.bundleContext:null;return s.forEach(((s,a)=>{if(i){if(a.startsWith("bundle[")&&a.includes("[options][")){const i=a.split("[options][")[1].replace("]","");t[i]=s}}else a.startsWith("options[")&&(t[a.replace("options[","").replace("]","")]=s)})),t}async reportValidity(){const t=this.host.querySelectorAll("[required]");let s=!0;for(let i=0;i<t.length;i++){const a=t[i];a.disabled||a.closest(".hidden")||"reportValidity"in a&&!a.reportValidity()&&(s=!1)}return s}async hasOutOfStockOption(){return this.selectedOptions.some((t=>t.is_out))||this.selectedSkus?.length&&this.selectedSkus?.every((t=>this.outSkus.includes(t)))}async getSelectedOptions(){return this.selectedOptions}async getOption(t){return this.optionsData.find((s=>s.id===t))}invalidHandler(t,s){const i=t.target.closest(".s-product-options-option");i.classList.contains("s-product-options-option-error")||i.classList.add("s-product-options-option-error"),!this.userInitiatedValidation&&!salla.helpers.isIOSDevice()||salla.url.is_page("cart")||this.host.querySelector(".s-product-options-option-error")===i&&this.scrollToElement(i)}scrollToElement(t){t&&t.scrollIntoView({behavior:"smooth",block:"center"})}changedHandler(t,s,i=!0){const a={event:t,option:s,detail:null,productId:this.productId};if(s.details){const i=s.details.find((s=>Number(s.id)===Number(t.target.value)));a.detail=i}"country"===s.type&&this.handleCountryOptionChange(t,a.detail);const e=t.target.closest(".s-product-options-option");(t.target.value||(s.type===d.FILE||s.type===d.IMAGE)&&"added"===t.type||s.type===d.MAP&&"selected"===t.type&&t.target.lat&&t.target.lng)&&setTimeout((()=>{e.classList.remove("s-product-options-option-error")}),200),s.type===d.DONATION&&salla.event.emit("product-options::donation-changed",{id:this.productId,price:t.target.value}),this.setSelectedSkus(),this.handleRequiredMultipleOptions(s);const o=this.selectedOptions.findIndex((t=>t.option_id===a.option.id));if(a.option.type===d.MULTIPLE_OPTIONS){const t=this.selectedOptions.findIndex((t=>t.option_id===a.option.id&&t?.id===a.detail?.id));t>-1?this.selectedOptions.splice(t,1):this.selectedOptions.push({...a.detail,option_id:a.option.id})}else a.detail&&0!==Object.keys(a.detail).length?o>-1?this.selectedOptions[o]={...a.detail,option_id:a.option.id}:this.selectedOptions.push({...a.detail,option_id:a.option.id}):o>-1&&this.selectedOptions.splice(o,1);this.optionsData=this.optionsData.map((t=>t.id===a.option.id?{...t,details:t.details.map((t=>({...t,is_selected:a.option.type===d.MULTIPLE_OPTIONS?this.selectedOptions.some((s=>s.id===t.id)):Number(t.id)===Number(a.detail?.id),value:a.detail?.value})))}:t)),this.pruneInvisibleConditionalSelections(),this.setSelectedSkus(),requestAnimationFrame((()=>{this.optionsData?.filter((t=>t.type===d.MULTIPLE_OPTIONS&&t.required)).forEach((t=>this.handleRequiredMultipleOptions(t)))})),i&&(this.changed.emit(a),salla.event.emit("product-options::change",a))}setSelectedSkus(){this.selectedSkus=this.selectedOptions.map((t=>Object.keys(t.skus_availability||{}))).reduce(((t,s)=>t.filter((t=>s.includes(t)))),[]).map((t=>Number(t))),this.computeAvailability()}handleRequiredMultipleOptions(t){if(t.type!==d.MULTIPLE_OPTIONS||!t.required)return;const s=this.host.querySelector(`[data-option-id="${t.id}"]`);if(!s)return;const i=s.querySelectorAll("input:checked").length;s.querySelectorAll("input").forEach((t=>t.toggleAttribute("required",!i)))}pruneInvisibleConditionalSelections(){const t=Math.max(1,this.optionsData.length);for(let s=0;s<t;s++){let t=!1;for(const s of this.optionsData){const i=s.visibility_condition;if(!i)continue;const a=this.selectedOptions.filter((t=>t.option_id===i.option)).map((t=>String(t.id))).includes(String(i.value));("="===i.operator?a:!a)||this.clearStaleOption(s.id)&&(t=!0)}if(!t)break}}clearStaleOption(t){const s=this.optionsData.find((s=>s.id===t));if(!s)return!1;const i=this.selectedOptions.length;this.selectedOptions=this.selectedOptions.filter((s=>s.option_id!==t));const a=this.selectedOptions.length!==i,e=null!=s.value&&String(s.value).length>0,o=s.details?.some((t=>t.is_selected))??!1;return!!(a||e||o)&&(this.optionsData=this.optionsData.map((s=>s.id!==t?s:{...s,value:void 0,details:s.details?.map((t=>({...t,is_selected:!1})))??s.details})),!0)}getLatLng(t,s){return t?t.split(",")["lat"===s?0:1]:""}getDisplayForType(t){return this[`${t.type}Option`]?this[`${t.type}Option`](t):t.type===d.COLOR_PICKER?this.colorPickerOption(t):t.type===d.MULTIPLE_OPTIONS?this.multipleOptions(t):t.type===d.SINGLE_OPTION?this.singleOption(t):t.type===d.RADIO?this.radioOption(t):t.type===d.DIGITAL_CARD_VALUE?this.digitalCardValuesOption(t):t.type===d.COUNTRY?this.countryOption(t):t.type===d.BOOKING&&salla.url.is_page("cart")?i("salla-booking-field",{onInvalidInput:s=>this.invalidHandler(s,t),option:t,productId:t.value}):(salla.log(`Couldn't find options type(${t.type})😢`),"")}getOptionShownWhen(t){return t.visibility_condition?{"data-show-when":`options[${t.visibility_condition.option}] ${t.visibility_condition.operator} ${t.visibility_condition.value}`}:{}}getAvailableDigitalCardSKUs(t){const s=this.optionsData.find((({type:t})=>"digital-code-value"===t));if(!s)throw new Error("product-options:: No digital card options found");const i=Object.keys(t.skus_availability).filter((s=>!1===t.skus_availability[s]));this.availableDigitalCardValues=s.details.filter((t=>!Object.keys(t.skus_availability).filter((t=>i.includes(t))).length))}handleCountryOptionChange(t,s){t.stopImmediatePropagation(),this.ignoreDefaultCardValue=!0;const i=this.host.querySelector("input[data-code-value]:checked");if(i&&(i.checked=!1),!this.optionsData.find((({type:t})=>"digital-code-value"===t)))throw new Error("product-options:: No digital card options found");this.getAvailableDigitalCardSKUs(s)}getSelectedDigitalCardOptions(t){const s=t.details.find((t=>t.is_selected)),i=t.details.find((t=>!!t.is_default))||t.details[0];if(["digital-code-value","country"].includes(t.type))return s||i}async componentWillLoad(){if(salla.url.is_page("cart")&&(this.disableCardValue=!1,this.fillSelectedOptions()),this.config)try{this.optionConfig="string"==typeof this.config?JSON.parse(this.config):this.config}catch(t){console.error("Failed to parse JSON in config prop:",t)}if(this.optionsData.filter((({type:t})=>["country","digital-card-value"].includes(t))).length>0&&salla.url.is_page("cart")){const t=this.optionsData.find((t=>"country"===t.type)),s=t&&this.getSelectedDigitalCardOptions(t);s&&this.getAvailableDigitalCardSKUs(s)}return this.outOfStockText=salla.lang.get("pages.products.out_of_stock"),this.computeAvailability(),await salla.onReady(),this.canDisabled=!salla.config.get("store.settings.product.notify_options_availability")||salla.url.is_page("cart"),this.pasteHandler=this.handlePaste.bind(this),document.addEventListener("paste",this.pasteHandler),!salla.storage.get("cart.id")&&this.optionsData.some((t=>["file","image"].includes(t.type)))?salla.api.cart.getCurrentCartId(!1,"salla-product-options"):null}disconnectedCallback(){this.pasteHandler&&document.removeEventListener("paste",this.pasteHandler)}handlePaste(t){const s=t.target;if(!(Salla.helpers.isAppleDevice()&&(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement)&&s.classList.contains("s-form-control")&&this.host.contains(s)))return;t.preventDefault();const i=t.clipboardData?.getData("text")||"",a=s.selectionStart,e=s.selectionEnd,o=s.value.slice(0,a)+i+s.value.slice(e);s.value=o,s.setSelectionRange(a+i.length,a+i.length);try{s.dispatchEvent(new window.Event("change",{bubbles:!0}))}catch(t){Salla.log("Error on change")}}hideDigitalCardsOptions(t){return this.disableCardValue&&t.type===d.DIGITAL_CARD_VALUE&&!salla.url.is_page("cart")}render(){if(0!==this.optionsData?.length)return i(a,{class:{"s-product-options-wrapper":!0,"s-product-options-no-padding":this.noPadding}},i("salla-conditional-fields",null,this.optionsData.map((t=>i("div",{key:t.id,class:"s-product-options-option-container"+(t.visibility_condition||this.hideDigitalCardsOptions(t)?" hidden":""),"data-option-id":t.id,...this.getOptionShownWhen(t)},"splitter"===t.name?this.splitterOption():i("div",{class:{"s-product-options-option":!0,"s-product-options-option-booking":t.type===d.BOOKING&&salla.url.is_page("cart")},"data-option-type":t.type,"data-option-required":`${t.required}`},i("label",{htmlFor:this.generateInputId(t.id),class:"s-product-options-option-label "+(this.hideLabel(t)?"s-product-options-option-label-hidden":"")},i("b",null,t.name,t.required&&i("span",null," * ")," "),i("small",null,t.placeholder)),i("div",{class:"s-product-options-option-content "+(this.hideLabel(t)||t.type===d.BOOKING&&salla.url.is_page("cart")?"s-product-options-option-content-full-width":"")},this.getDisplayForType(t))))))))}generateUniqueKey(t){const s=this.bundleContext;let i=this.uniqueKey?`${t}-${this.uniqueKey}`:t;if(s)try{const t="string"==typeof s?JSON.parse(s):s,{sectionId:a,productId:e}=t;i=`${i}-bundle-${a}-${e}`}catch(t){}return i}generateInputId(t){return this.generateUniqueKey(`option-${t}`)}generateInputName(t){const s=this.bundleContext,i=t.toString();if(s)try{const t="string"==typeof s?JSON.parse(s):s,{sectionId:a,productId:e}=t;return`bundle[${a}][${e}][options][${i}]`}catch(t){return`options[${i}]`}return`options[${i}]`}fillSelectedOptions(){this.selectedOptions=this.optionsData.reduce(((t,s)=>{const i=(s.details??[]).filter((t=>t.is_selected)).map((t=>({...t,option_id:s.id})));return t.concat(i)}),[])}async seedSelectedOptions(){this.fillSelectedOptions(),requestAnimationFrame((()=>{this.optionsData?.filter((t=>t.type===d.MULTIPLE_OPTIONS&&t.required)).forEach((t=>this.handleRequiredMultipleOptions(t)))}))}async componentDidLoad(){if(!this.optionsData?.length)return;await Salla.hooks.registerComponent("salla-product-options",this);const t=this.optionsData.find((t=>t.type===d.DONATION))?.details?.find((t=>t.is_selected));if(t&&setTimeout((()=>{salla.event.emit("product-options::donation-changed",{id:this.productId,price:t.additional_price})}),1e3),!salla.url.is_page("cart")&&!this.isCartMode){const t=[d.SINGLE_OPTION,d.MULTIPLE_OPTIONS,d.COLOR,d.THUMBNAIL,d.DONATION,d.DIGITAL_CARD_VALUE,d.COUNTRY];this.optionsData.some((s=>t.includes(s.type)&&s.details?.some((t=>t.is_selected))))&&requestAnimationFrame((()=>{try{const t=this.host.closest("form");if(!t)return;const s=new FormData(t),i=s.get("id")||s.get("product_id");if(i&&String(i)!==String(this.productId))return;salla.product.getPrice(s)}catch(t){salla.log("Error updating price for pre-selected options:",t)}}))}}async enterCartMode(){this.isCartMode=!0,this.disableCardValue=!1,this.canDisabled=!0,this.fillSelectedOptions(),this.computeAvailability()}async enableUserInitiatedValidation(){this.userInitiatedValidation=!0}async validateAndScroll(){return await this.enableUserInitiatedValidation(),this.reportValidity()}donationOption(t,s){return i("div",{class:"s-product-options-donation-wrapper"},t.donation?.can_donate?[t.donation?i("div",{key:t.id,class:"s-product-options-donation-progress"},i("salla-progress-bar",{donation:t.donation})):"",t.details.length?[i("h4",{key:t.id},this.selectAmount),i("div",{key:t.id,class:"s-product-options-donation-options"},t.details.map(((s,a)=>i("div",{key:t.id,class:"s-product-options-donation-options-item"},i("input",{id:this.generateUniqueKey(`donation-option-${a}`),type:"radio",name:"donating_option",checked:s.is_selected,value:s.additional_price,onChange:i=>this.handleDonationOptions(i,s,"option",t)}),i("label",{htmlFor:this.generateUniqueKey(`donation-option-${a}`)},i("span",{innerHTML:salla.money(s.name)}))))),t.donation?.custom_amount_enabled?i("div",{class:"s-product-options-donation-options-item"},i("input",{id:this.generateUniqueKey("donation-option-custom"),type:"radio",name:"donating_option",value:"custom",onChange:s=>this.handleDonationOptions(s,"custom","option",t)}),i("label",{htmlFor:this.generateUniqueKey("donation-option-custom")},i("span",null," ",this.selectDonationAmount," "))):"")]:"",i("div",{key:t.id,class:{"s-product-options-donation-input-group":!0,shown:!t.details.length||t.details.length&&this.isCustomDonation}},i("input",{type:"text",id:"donating-amount",name:"donation_amount",class:"s-form-control",ref:t=>{this.donationInput=t},value:t.details.length&&t.details.some((t=>t.is_selected))?t.details.find((t=>t.is_selected)).additional_price:t.value,placeholder:t.placeholder,onInput:s=>this.handleDonationOptions(s,"custom","input",t),onBlur:s=>this.changedHandler(s,t),onInvalid:s=>this.invalidHandler(s,t)}),i("span",{class:"s-product-options-donation-amount-currency"},salla.config.currency(salla.config.get("user.currency_code")).symbol))]:this.getExpireDonationMessage(t))}fileUploader(t,s=null){return i("salla-file-upload",{...s||{},"payload-name":"file",value:t.value,"instant-upload":!0,name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,height:"120px",onAdded:s=>{this.changedHandler(s,t,!(s.detail?.file?.origin===w.LOCAL))},url:salla.cart.api.getUploadImageEndpoint(),"form-data":{cart_item_id:this.productId,product_id:this.productId},onInvalidInput:s=>this.invalidHandler(s,t),class:{"s-product-options-image-input":!0,required:t.required}},i("div",{class:"s-product-options-filepond-placeholder"},i("span",{class:"s-product-options-filepond-placeholder-icon",innerHTML:s.accept?.split(",").every((t=>t.includes("image")))?p:'\x3c!-- Generated by IcoMoon.io --\x3e\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">\n<title>file-upload</title>\n<path d="M21.333 24c0.341 0 0.683-0.131 0.943-0.391 0.521-0.521 0.521-1.364 0-1.885l-5.333-5.333c-0.123-0.123-0.271-0.22-0.433-0.288-0.327-0.135-0.693-0.135-1.019 0-0.163 0.068-0.311 0.165-0.433 0.288l-5.333 5.333c-0.521 0.521-0.521 1.364 0 1.885s1.364 0.521 1.885 0l3.057-3.057v10.115c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-10.115l3.057 3.057c0.26 0.26 0.601 0.391 0.943 0.391zM28.943 9.724l-9.333-9.333c-0.249-0.251-0.589-0.391-0.943-0.391h-12c-2.205 0-4 1.795-4 4v24c0 2.205 1.795 4 4 4h4c0.736 0 1.333-0.597 1.333-1.333s-0.597-1.333-1.333-1.333h-4c-0.735 0-1.333-0.599-1.333-1.333v-24c0-0.735 0.599-1.333 1.333-1.333h11.448l8.552 8.552v16.781c0 0.735-0.599 1.333-1.333 1.333h-4c-0.736 0-1.333 0.597-1.333 1.333s0.597 1.333 1.333 1.333h4c2.205 0 4-1.795 4-4v-17.333c0-0.353-0.14-0.693-0.391-0.943z"></path>\n</svg>\n'}),i("p",{class:"s-product-options-filepond-placeholder-text"},salla.lang.get("common.uploader.drag_and_drop")),i("span",{class:"filepond--label-action"},salla.lang.get("common.uploader.browse"))))}imageOption(t){return this.fileUploader(t,{accept:"image/png,image/jpeg,image/jpg,image/gif"})}fileOption(t){const s=t.details.map((t=>this.fileTypes[t.name])).filter(Boolean);return s?.length?this.fileUploader(t,{accept:s.join(",")}):"File types not selected."}numberOption(t){return i("input",{type:"text",value:t.value,class:"s-form-control",required:!t.visibility_condition&&t.required,id:this.generateInputId(t.id),name:this.generateInputName(t.id),placeholder:t.placeholder,onBlur:s=>this.changedHandler(s,t),onInvalid:s=>this.invalidHandler(s,t),onInput:t=>salla.helpers.inputDigitsOnly(t.target)})}splitterOption(){return i("div",{class:"s-product-options-splitter"})}textOption(t){return i("div",{class:"s-product-options-text"},i("input",{type:"text",value:t.value,maxLength:t?.length,class:"s-form-control",required:!t.visibility_condition&&t.required,id:this.generateInputId(t.id),name:this.generateInputName(t.id),placeholder:t.placeholder,onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t)}))}textareaOption(t){return i("div",{class:"s-product-options-textarea"},i("div",{class:"mt-1"},i("textarea",{rows:4,value:t.value,maxLength:t?.length,class:"s-form-control",required:!t.visibility_condition&&t.required,id:this.generateInputId(t.id),name:this.generateInputName(t.id),placeholder:t.placeholder,onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t)})))}mapOption(t){return i("salla-map",{zoom:15,lat:this.getLatLng(t.value,"lat"),lng:this.getLatLng(t.value,"lng"),name:this.generateInputName(t.id),searchable:!0,required:t.required,onInvalidInput:s=>this.invalidHandler(s,t),onSelected:s=>this.changedHandler(s,t)})}colorPickerOption(t){return i("salla-color-picker",{onSubmitted:s=>this.changedHandler(s,t),name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,onInvalidInput:s=>this.invalidHandler(s,t),color:t.value})}timeOption(t){return i("salla-datetime-picker",{noCalendar:!0,enableTime:!0,dateFormat:"h:i K",value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,name:this.generateInputName(t.id),class:"s-product-options-time-element",onInvalidInput:s=>this.invalidHandler(s,t),onPicked:s=>this.changedHandler(s,t)})}dateOption(t){return i("div",{class:"s-product-options-date-element"},i("salla-datetime-picker",{value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,minDate:new Date,name:this.generateInputName(t.id),onInvalidInput:s=>this.invalidHandler(s,t),onPicked:s=>this.changedHandler(s,t)}))}datetimeOption(t){return i("div",{class:"s-product-options-datetime-element"},i("salla-datetime-picker",{enableTime:!0,value:t.value,dateFormat:"Y-m-d G:i:K",placeholder:t.name,required:!t.visibility_condition&&t.required,name:this.generateInputName(t.id),maxDate:t.to_date_time,minDate:t.from_date_time,onInvalidInput:s=>this.invalidHandler(s,t),onPicked:s=>this.changedHandler(s,t)}))}getOptionDetailName(t,s=!0,i,a){let e;if(i&&i===d.COLOR&&(e=t.name+(s&&this.isOptionDetailOut(t)&&!salla.url.is_page("cart")&&!this.hideOutLabel?` <br/> <p> ${this.outOfStockText} </p>`:"")+(t.additional_price?` <p> (${salla.money(t.additional_price,!1)}) </p>`:"")),!e){const i=(s&&this.isOptionDetailOut(t)&&!salla.url.is_page("cart")&&!this.hideOutLabel?` - ${this.outOfStockText}`:"")+(t.additional_price?` (${salla.money(t.additional_price,!1)})`:"");if("price"===a){const s=salla.helpers.digitsOnly(t.name),a=Number(s);return s&&Number.isFinite(a)?salla.money(a,!0)+i:i}e=t.name+i}return e.replace("<i class=sicon-sar></i>",salla.config.currency()?.symbol||"ر.س")}computeAvailability(){this.availabilityMap=function(t,s,i=!0){const a={};if(!t?.length)return a;const e=t.filter((t=>t.details?.some((t=>t.skus_availability&&Object.keys(t.skus_availability).length>0)))),o=e.length<=1,n=new Set(t.filter((t=>!1===t.is_advance)).map((t=>t.id)));if(0===e.length){for(const s of t)for(const t of s.details)a[t.id]=t.is_out?"out_of_stock":"available";return a}const l=e.some((t=>t.details?.some((t=>t.skus_availability&&Object.values(t.skus_availability).some(Boolean))))),r=i&&!l;for(const t of e){const i=s.filter((s=>s.option_id!==t.id));for(const s of t.details){const t=s.skus_availability;if(!t||!Object.keys(t).length){a[s.id]=s.is_out?"out_of_stock":"available";continue}const e=Object.keys(t).map(Number),l=e.some((s=>t[s]));if(o||0===i.length){a[s.id]=!l&&r||l?"available":"out_of_stock";continue}let c=e;for(const t of i){if(n.has(t.option_id))continue;const s=new Set(Object.keys(t.skus_availability||{}).map(Number));c=c.filter((t=>s.has(t)))}if(!c.length){a[s.id]=r?"available":"impossible";continue}const d=c.some((s=>t[s]));a[s.id]=!d&&r||d?"available":"out_of_stock"}}return a}(this.optionsData||[],this.selectedOptions||[],this.productAvailable)}isOptionDetailOut(t){const s=this.availabilityMap[t.id];return void 0!==s?"available"!==s:!!t.is_out}renderInput(t,s,a,e,o,n){const l=this.generateUniqueKey(`${t}-${a.id}-${s.id}`),r=this.isOptionDetailOut(s),c=this.getOptionDetailName(s,!0,a.type,a.format),d={"s-product-options-grid-mode-span":n,"s-product-options-disabled":this.canDisabled&&r};return i("label",{class:{"s-product-options-disabled":this.canDisabled&&r,"s-product-options-option-stock-out":r}},i("input",{id:l,type:t,name:o,value:s.id,disabled:this.canDisabled&&r,required:e,checked:s.is_selected,onInvalid:t=>this.invalidHandler(t,a),onChange:t=>this.changedHandler(t,a)}),"price"===a.format?i("div",{class:d,innerHTML:c}):i("div",{class:d},c))}renderOptionDetails(t,s,i,a=!1){const e=this.generateInputName(s.id),o="radio"===t?e:`${e}[]`;return s?.details.map((e=>this.renderInput(t,e,s,i,o,a)))}renderSelect(t){return i("div",null,i("select",{id:this.generateInputId(t.id),name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,class:"s-form-control",onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t)},i("option",{value:""},t.placeholder),t?.details.map((t=>i("option",{key:t.id,value:t.id,disabled:this.canDisabled&&this.isOptionDetailOut(t),selected:t.is_selected},this.getOptionDetailName(t))))))}renderButtonStyle(t,s,a){return i("div",{class:"s-product-options-grid-mode"},this.renderOptionDetails(t,s,a,!0))}singleOption(t){return"button"===this.optionConfig?.["single-option"]?.type||t.type===d.SINGLE_OPTION&&"price"===t.format?this.renderButtonStyle("radio",t,!t.visibility_condition&&t.required):this.renderSelect(t)}multipleOptions(t){const s="button"===this.optionConfig?.["multiple-option"]?.type,a=t.required&&!t.details.some((t=>t.is_selected))&&!t.visibility_condition;return s?this.renderButtonStyle("checkbox",t,a):i("div",{class:{"s-product-options-multiple-options-wrapper":!0,required:t.required}},this.renderOptionDetails("checkbox",t,a))}radioOption(t){return this.singleOption(t)}colorOption(t){return i("fieldset",{class:"s-product-options-colors-wrapper"},t?.details.map((s=>{const a=this.isOptionDetailOut(s);return i("div",{class:{"s-product-options-colors-item":!0,"s-product-options-option-stock-out":a},key:s.id},i("input",{type:"radio",value:s.id,required:!t.visibility_condition&&t.required,checked:s.is_selected,name:this.generateInputName(t.id),disabled:this.canDisabled&&a,id:this.generateUniqueKey(`color-${this.productId}-${t.id}-${s.id}`),onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t),"data-img-id":s.option_value}),i("label",{htmlFor:this.generateUniqueKey(`color-${this.productId}-${t.id}-${s.id}`),"data-img-id":s.option_value},i("span",{style:{backgroundColor:s.color}}),i("div",{innerHTML:this.getOptionDetailName(s,!0,t.type)})))})))}thumbnailOption(t){return i("div",{class:"s-product-options-thumbnails-wrapper"},t.details.map((s=>{const a=this.isOptionDetailOut(s);return i("div",{key:s.id,class:{"s-product-options-option-stock-out":a}},i("input",{type:"radio",value:s.id,"data-itemid":s.id,required:!t.visibility_condition&&t.required,checked:s.is_selected,name:this.generateInputName(t.id),"data-img-id":s.option_value,disabled:this.canDisabled&&a,id:this.generateUniqueKey(`option_${this.productId}-${t.id}_${s.id}`),onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t)}),i("label",{htmlFor:this.generateUniqueKey(`option_${this.productId}-${t.id}_${s.id}`),"data-img-id":s.option_value,class:"go-to-slide"},i("img",{"data-src":s.image,src:s.image,title:s.name,alt:s.name}),i("span",{innerHTML:h,class:"s-product-options-thumbnails-icon"}),a?[i("small",{key:`badge-${s.id}`,class:"s-product-options-thumbnails-stock-badge"},this.outOfStockText),this.canDisabled?i("div",{key:`overlay-${s.id}`,class:"s-product-options-thumbnails-badge-overlay"}):""]:""),i("p",null,this.getOptionDetailName(s,!1)," "))})))}digitalCardValuesOption(t){return i("div",{class:"s-product-options-digital-card-wrapper"},this.availableDigitalCardValues.length>0?this.availableDigitalCardValues.map((s=>{const a=String(s.id);return i("label",{htmlFor:this.generateUniqueKey(a.toString()),key:a,class:"s-product-options-digital-card-option"},i("input",{type:"radio","data-code-value":!0,class:"s-form-control s-product-options-digital-card-input",value:s.id,name:this.generateInputName(t.id),id:this.generateUniqueKey(a.toString()),required:!t.visibility_condition&&t.required,onInvalid:s=>this.invalidHandler(s,t),...this.ignoreDefaultCardValue?{}:{defaultChecked:this.getSelectedDigitalCardOptions(t)?.id===s.id}}),i("span",null,s.name," ",salla.config?.currency()?.symbol))})):i("div",{class:"s-product-options-digital-card-out-of-stock"}))}countryOption(t){return i("div",{class:"s-product-options-digital-card-wrapper"},t.details.map((s=>{const a=this.isOptionDetailOut(s);return i("label",{htmlFor:this.generateUniqueKey(s.id.toString()),key:s.id,class:{"s-product-options-digital-card-option":!0,"s-product-options-digital-card-option-stock-out":a,"s-product-options-option-stock-out":a}},i("input",{id:this.generateUniqueKey(s.id.toString()),type:"radio",class:"s-form-control s-product-options-digital-card-input",value:s.id,name:this.generateInputName(t.id),disabled:this.canDisabled&&a,required:!t.visibility_condition&&t.required,onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t),onClick:()=>{this.disableCardValue=!1},...salla.url.is_page("cart")?{defaultChecked:this.getSelectedDigitalCardOptions(t)?.id===s.id}:{}}),i("img",{loading:"lazy",alt:s.code,height:24,width:24,class:"s-product-options-country-flag",src:`https://cdn.assets.salla.network/prod/admin/cp/assets/flags/1x1/${String(s.code).toLocaleLowerCase()}.svg`,onError:t=>{t.currentTarget.onerror=null,t.currentTarget.src=salla.url.cdn("images/globe.svg")}}),i("span",null,s.name))})))}get host(){return e(this)}};function k(){o.defaults.headers.common.currency=salla?.config?.get?.("user.currency_code")}v.style="";var _={request:(t,s,i,a=null,e=null)=>(k(),o.request({url:s,data:i,method:t.toLowerCase(),responseType:"json"}).then(a).catch(e)),get:(t,s=null,i=null,a)=>(k(),o.get(t,{params:a}).then(s).catch(i)),post(t,s,i=null,a=null){return this.request("post",t,s,i,a)},put(t,s,i=null,a=null){return this.request("put",t,s,i,a)},delete(t,s,i=null,a=null){return this.request("delete",t,s,i,a)},requestWithSupportAjax(t,s,i="post"){return new Promise(((a,e)=>{if(!window?.isLegacyTheme)return this.request(i,t,s,(({data:t})=>a(t)),(({response:t})=>e(t)));k(),$.ajax({url:t,method:i.toUpperCase(),data:s,headers:{currency:o.defaults.headers.common.currency},async:!1,success:function({data:t}){return a(t)},error:function({response:t}){return e(t)}})}))}},S={options:[],header:"undefined"!=typeof navigator&&"undefined"!=typeof window?[navigator.platform,navigator.userAgent,navigator.appVersion,navigator.vendor,window.opera]:[],dataos:[{name:"Windows Phone",value:"Windows Phone",version:"OS"},{name:"Windows",value:"Win",version:"NT"},{name:"iPhone",value:"iPhone",version:"OS"},{name:"iPad",value:"iPad",version:"OS"},{name:"Kindle",value:"Silk",version:"Silk"},{name:"Android",value:"Android",version:"Android"},{name:"PlayBook",value:"PlayBook",version:"OS"},{name:"BlackBerry",value:"BlackBerry",version:"/"},{name:"Macintosh",value:"Mac",version:"OS X"},{name:"Linux",value:"Linux",version:"rv"},{name:"Palm",value:"Palm",version:"PalmOS"}],databrowser:[{name:"Chrome",value:"Chrome",version:"Chrome"},{name:"Firefox",value:"Firefox",version:"Firefox"},{name:"Safari",value:"Safari",version:"Version"},{name:"Internet Explorer",value:"MSIE",version:"MSIE"},{name:"Opera",value:"Opera",version:"Opera"},{name:"BlackBerry",value:"CLDC",version:"CLDC"},{name:"Mozilla",value:"Mozilla",version:"Mozilla"}],init:function(){var t=this.header.join(" ");return{os:this.matchItem(t,this.dataos),browser:this.matchItem(t,this.databrowser)}},matchItem:function(t,s){var i,a,e,o=0,n=0;for(o=0;o<s.length;o+=1)if(new RegExp(s[o].value,"i").test(t)){if(i=new RegExp(s[o].version+"[- /:;]([\\d._]+)","i"),e="",(a=t.match(i))&&a[1]&&(a=a[1]),a)for(a=a.split(/[._]+/),n=0;n<a.length;n+=1)e+=0===n?a[n]+".":a[n];else e="0";return{name:s[o].name,version:parseFloat(e)}}return{name:"unknown",version:0}}};async function C(t,s,i=!1){if(salla.logger.log("🍏 Pay: mutateShippingContact called",s,i),t.detail.requiredShippingContactFields&&0!=t.detail.requiredShippingContactFields.length)if(i){if(salla.config.isGuest()&&salla.config.get("store.features").includes("guest-checkout")){if(!(s.emailAddress&&s.givenName&&s.familyName&&s.phoneNumber)){salla.logger.warn("🍏 Pay: Guest contact fields are required",s);const i=[];return s.emailAddress||i.push(new window.ApplePayError("shippingContactInvalid","emailAddress","Email address is required")),s.phoneNumber||i.push(new window.ApplePayError("shippingContactInvalid","phoneNumber","Phone number is required")),s.givenName&&s.familyName||i.push(new window.ApplePayError("shippingContactInvalid","name","Name is required")),void t.session.completePayment({status:t.session.STATUS_INVALID_SHIPPING_CONTACT,errors:i})}await async function(t,s){return salla.logger.log("🍏 Pay: Updating guest contact",s),new Promise(((i,a)=>{_.post(t.detail.guestContactSelected.url.replace("{id}",t.id),{email:s.emailAddress||null,first_name:s.givenName||null,last_name:s.familyName||null,phone_number:s.phoneNumber||null,country_code:s.countryCode||null},(async({data:s})=>{"function"==typeof t.detail.guestContactSelected?.onSuccess&&t.detail.guestContactSelected.onSuccess(s),i(s)}),(({response:s})=>{salla.logger.warn("🍏 Pay: Failed to update guest contact via api",s),"function"==typeof t.detail.guestContactSelected?.onFailed&&t.detail.guestContactSelected.onFailed(s),a({response:s})}))}))}(t,s)}}else if(t.detail.requiredShippingContactFields.includes("postalAddress"))return _.post(t.detail.shippingContactSelected.url.replace("{id}",t.id),{country:s.country,city:s.locality,local:s.subLocality||s.administrativeArea||s.locality,description:s.subAdministrativeArea,street:s.addressLines?.join(", ")||s.administrativeArea,country_code:s.countryCode,postal_code:s.postalCode},(async({data:s})=>{if("function"==typeof t.detail.shippingContactSelected.onSuccess&&t.detail.shippingContactSelected.onSuccess(s),t.address_id=s.data.address_id,t.shipping_methods=s.data.shipping_methods,!t.shipping_methods||t.shipping_methods&&!t.shipping_methods.length)return salla.logger.warn("🍏 Pay: We dont found any supported methods",s),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]});try{await t.selectApplePayShippingMethod(t.shipping_methods[0])}catch(s){return salla.logger.warn("Failed set the shipping details to api",s),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}try{await t.recalculateTotal()}catch(s){return salla.logger.warn("🍏 Pay: Failed recalculate total",s),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}const i={newTotal:t.prepareTotal(),newLineItems:t.prepareLineItems(),newShippingMethods:t.mappingShippingMethods(t.shipping_methods)};salla.logger.log("🍏 Pay: completeShippingContactSelection",i),t.session.completeShippingContactSelection(i)}),(({response:s})=>{salla.logger.warn("🍏 Pay: Failed add address via api",s),"function"==typeof t.detail.shippingContactSelected.onFailed&&t.detail.shippingContactSelected.onFailed(s);let i=s?.data?.error?.fields,a=function(t){return Object.entries(t).filter((([t,s])=>s&&s.length>0)).map((([t,s])=>new window.ApplePayError("shippingContactInvalid",t,s[0])))}({countryCode:i?.country_code&&i.country_code.length>0?i.country_code[0]:null,locality:i?.city&&i.city.length>0?i.city[0]:null,country:i?.country&&i.country.length>0?i.country[0]:null});0===a.length&&s?.data?.error?.message&&a.push(new window.ApplePayError("shippingContactInvalid","locality",s?.data?.error?.message)),t.session.completeShippingContactSelection({newTotal:t.prepareTotal(),newLineItems:t.prepareLineItems(),status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:a})}))}"undefined"!=typeof window&&(window.Salla=window.Salla||{},window.Salla.Payments=window.Salla.Payments||{});const P="undefined"!=typeof window?{session:null,detail:null,address_id:null,shipping_methods:[],total:void 0,request:void 0,id:void 0,countryCode:null,totals:[],shippingCompany:null,init:function(){document.removeEventListener("payments::apple-pay.start-transaction",P.startSession),Salla.event.addEventListener("payments::apple-pay.start-transaction",P.startSession)},initDefault:function(){P.detail.onError||(P.detail.onError=function(t){salla.notify.error(t)}),P.detail.authorized.onFailed||(P.detail.authorized.onFailed=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleErrorResponse(t),P.onCancel({},t.data.error.message)}),P.detail.validateMerchant.onFailed||(P.detail.validateMerchant.onFailed=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleErrorResponse({response:t}),P.onCancel({},t.data.error.message)}),P.detail.authorized.onSuccess||(P.detail.authorized.onSuccess=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleAfterResponseActions(t)})},prepareLineItems:function(){return P.detail?.items?.length||(P.detail.items=[{label:salla.lang.get("pages.cart.items_total"),amount:parseFloat(P.detail.amount).toString()}]),P.detail.items},prepareTotal:function(){return{label:window.location.hostname||"Salla",amount:parseFloat(P.detail.amount).toString()}},isPhysical:()=>P.detail?.requiredShippingContactFields?.includes("postalAddress"),startSession:async function(t){P.detail=t.detail||t,salla.log("🍏 Pay: payments::apple-pay.start-transaction",P.detail),P.initDefault();let s,i=P.getApplePaySessionVersion(),a=P.detail.supportedNetworks,e=Array.isArray(a)?[...a]:Object.values(a||{});e.length||(e=["masterCard","visa"]),5!==i||e.includes("mada")||e.push("mada"),P.request={countryCode:P.detail.countryCode||"SA",supportsCouponCode:!0,couponCode:"",currencyCode:P.detail.currency||"SAR",requiredShippingContactFields:P.detail.requiredShippingContactFields?P.detail.requiredShippingContactFields:[],merchantCapabilities:["supports3DS"],supportedNetworks:e,supportedCountries:P.detail.supportedCountries||["SA"],total:P.prepareTotal(),shippingContact:P.detail.shippingContact?P.detail.shippingContact:{},shippingMethods:P.detail.shippingMethods&&P.detail.shippingMethods.length?P.mappingShippingMethods(t.detail.shippingMethods):[],lineItems:P.prepareLineItems()},salla.log("🍏 Pay: init ",P.request),P.session=new ApplePaySession(i,P.request),P.session.onshippingcontactselected=P.onShippingContactSelected,P.session.onshippingmethodselected=P.onShippingMethodSelected,P.session.onvalidatemerchant=P.onValidateMerchant,P.session.onpaymentauthorized=P.onPaymentAuthorized,P.session.oncancel=P.onCancel,P.session.oncouponcodechanged=P.onCouponCodeChanged,P.session.onpaymentmethodselected=P.onPaymentMethodSelected,"function"==typeof P.detail.onStartedSession&&(s=P.detail.onStartedSession(P.session)),s||P.session.begin()},onPaymentMethodSelected:async t=>{if(salla.logger.log("🍏 Pay: onPaymentMethodSelected",t),P.isPhysical())salla.logger.log("🍏 Pay: completePaymentMethodSelection",{newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()}),P.session.completePaymentMethodSelection({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()});else try{await P.recalculateTotal();const t={newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()};salla.logger.log("🍏 Pay: completePaymentMethodSelection",t),P.session.completePaymentMethodSelection(t)}catch(t){salla.logger.warn("🍏 Pay: Failed recalculate total",t),P.session.completePaymentMethodSelection({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems(),status:P.session.STATUS_FAILURE,errors:[new window.ApplePayError("unknown",void 0,t?.response?.data?.error?.message||t?.response?.data?.error?.code||"Failed to recalculate total")]})}},onCouponCodeChanged:t=>(Salla.event.dispatch("payments::apple-pay.coupon.change",t),_.post(P.detail.onCouponCodeChanged.url.replace("{id}",P.id),{coupon:t.couponCode,payment_method:"apple_pay"},(async({data:t})=>{"function"==typeof P.detail.onCouponCodeChanged.onSuccess&&P.detail.onCouponCodeChanged.onSuccess(t),salla.log("🍏 Pay: Coupon applied success"),await P.recalculateTotal(),P.session.completeCouponCodeChange({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()})}),(async t=>{let s=t?.response;Salla.event.dispatch("payments::apple-pay.coupon.failed",s),"function"==typeof P.detail.onCouponCodeChanged.onFailed&&P.detail.onCouponCodeChanged.onFailed(s),await P.recalculateTotal(),P.session.completeCouponCodeChange({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems(),errors:[new window.ApplePayError("couponCodeInvalid")]})}))),onCancel:(t={},s=null)=>{P.detail.onError(s||salla.lang.get("pages.checkout.payment_failed")),Salla.event.createAndDispatch("payments::apple-pay.canceled",t)},onPaymentAuthorized:async t=>{salla.logger.log("🍏 Pay: onPaymentAuthorized",t.payment);try{await C(P,t.payment.shippingContact,!0)}catch(t){salla.logger.error("🍏 Pay: Failed to update guest contact details",t);const s=t?.response||t,i=s?.data?.error?.fields||{},a=[];return i?.email&&i.email.length>0&&a.push(new window.ApplePayError("shippingContactInvalid","emailAddress",i.email[0])),i?.phone&&i.phone.length>0&&a.push(new window.ApplePayError("shippingContactInvalid","phoneNumber",i.phone[0])),i?.first_name&&i.first_name.length>0?a.push(new window.ApplePayError("shippingContactInvalid","name",i.first_name[0])):i?.last_name&&i.last_name.length>0&&a.push(new window.ApplePayError("shippingContactInvalid","name",i.last_name[0])),0===a.length&&a.push(new window.ApplePayError("shippingContactInvalid","name",s?.data?.error?.message||s?.data?.error?.code||"Invalid shipping contact details")),Salla.event.dispatch("payments::apple-pay.authorized.failed",s),"function"==typeof P.detail.authorized.onFailed&&P.detail.authorized.onFailed(s),void P.session.completePayment({status:ApplePaySession.STATUS_INVALID_SHIPPING_CONTACT,errors:a})}Salla.event.dispatch("payments::apple-pay.authorized.init",t),_.post(P.detail.authorized.url.replace("{id}",P.id),{payment_method:"apple_pay",applepay_token:JSON.stringify(t.payment)},(({data:t})=>{Salla.event.dispatch("payments::apple-pay.authorized.success",t),"function"==typeof P.detail.authorized.onSuccess&&P.detail.authorized.onSuccess(t),P.session.completePayment(ApplePaySession.STATUS_SUCCESS)}),(t=>{let s=t?.response;Salla.event.dispatch("payments::apple-pay.authorized.failed",s),"function"==typeof P.detail.authorized.onFailed&&P.detail.authorized.onFailed(s),P.session.completePayment({status:ApplePaySession.STATUS_FAILURE,errors:[new window.ApplePayError("unknown",void 0,s?.data?.error?.message||s?.data?.error?.code||"Failed to parse authorized response")]})}))},onValidateMerchant:async t=>{try{Salla.event.dispatch("payments::apple-pay.validate-merchant.init",t);const{data:s}=await _.post(P.detail.validateMerchant.url.replace("{id}",P.id),{validation_url:t.validationURL});Salla.event.dispatch("payments::apple-pay.validate-merchant.success",s);const i=t=>{P.session.completeMerchantValidation(t)};if("function"==typeof P.detail.validateMerchant.onSuccess){const t=await P.detail.validateMerchant.onSuccess(s);if(t?.redirect)return window.location=t.redirect,P.abortValidateMerchant(t)}i(s.data)}catch(t){console.error(t),P.abortValidateMerchant(t?.response)}},abortValidateMerchant:(t=null)=>{P.abortSession(),Salla.event.dispatch("payments::apple-pay.validate-merchant.failed",t),"function"==typeof P.detail.validateMerchant.onFailed&&P.detail.validateMerchant.onFailed(t)},onShippingContactSelected:async t=>{salla.logger.log("🍏 Pay: onShippingContactSelected",t.shippingContact),await C(P,t.shippingContact)},onShippingMethodSelected:async t=>{let s=t.shippingMethod.identifier.split(","),i={ship_id:s[0],private_ship_id:void 0===s[1]?null:s[1],type:void 0===s[2]?null:s[2],route_id:void 0===s[3]?null:s[3]};if(salla.logger.log("🍏 Pay: onShippingMethodSelected",{event:t,previous:P.shippingCompany,current:i}),P.shouldUpdateShippingCompany(i))try{await P.selectApplePayShippingMethod(i),await P.recalculateTotal()}catch(t){return salla.logger.warn("🍏 Pay: Failed set the shipping details to api",t),void P.session.completeShippingMethodSelection({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems(),status:P.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}salla.logger.log("🍏 Pay: completeShippingMethodSelection",{newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()}),P.session.completeShippingMethodSelection({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()})},abortSession:()=>{P.session&&P.session.abort()},shouldUpdateShippingCompany:t=>P.shippingCompany?.ship_id!=t?.ship_id||P.shippingCompany?.private_ship_id!=t?.private_ship_id,getApplePaySessionVersion:()=>{if("sallapp"===(navigator.userAgent||navigator.vendor||window.opera))return 5;let t=S.init(),s=parseFloat(t.os.version);if("Macintosh"===t.os.name){if(s<10.142)return 1}else if(s<12.11)return 1;return 5},recalculateTotal:()=>(salla.logger.log("🍏 Pay: recalculate total"),_.get(P.detail.recalculateTotal.url.replace("{id}",P.id),(({data:t})=>{salla.logger.log("🍏 Pay: recalculate total success",t);let s=t.data.initial_data?.cart||t.data.cart,i=t.data.initial_data?.payments||t.data.payments;salla.logger.log("🍏 Pay: recalculate total success",{cart:s,payments:i}),null!=i?.gateways?.applePay?.amount?(P.detail.amount=i.gateways.applePay.amount,P.detail.currency=i.gateways.applePay.currency??P.detail.currency):P.detail.amount=i?.gateways?.applePay?.supportedMultiCurrency?s.total_in_customer_currency:s.total,P.detail.items=(s.totals||s.items).map((t=>({label:t.title,amount:"مجاني"===t.amount||"Free"===t.amount?0:t.amount.toString().replace("+","")}))),P.detail.items.pop(),P.totals=P.detail.items}),(t=>(salla.logger.warn("🍏 Pay: recalculate total failed",t),t?.response?.data?.message)))),selectApplePayShippingMethod:t=>{salla.logger.log("🍏 Pay: select shipping method ",t),P.shippingCompany=t;const s={address_id:P.address_id,company_id:t.ship_id,private_company_id:t.private_ship_id,type:t.type||void 0,route_id:t.route_id||void 0,payment_method:"apple_pay"};return _.post(P.detail.shippingMethodSelected.url.replace("{id}",P.id),s,(({data:t})=>("function"==typeof P.detail.shippingMethodSelected.onSuccess&&P.detail.shippingMethodSelected.onSuccess(t),!0)),(t=>{salla.logger.warn("🍏 Pay: Set shipping method failed",t),"function"==typeof P.detail.shippingMethodSelected.onFailed&&P.detail.shippingMethodSelected.onFailed(t);let s=t?.response?.data?.error;return s?.data?.fields?.address_id?s?.data?.fields?.address_id[0]:s?.data?.message}))},mappingShippingMethods:t=>t.map((t=>({label:t.shipping_title,amount:t.enable_free_shipping?0:t.ship_cost,detail:"",identifier:t.ship_id.toString()+(t.private_ship_id?","+t.private_ship_id.toString():"")+(t.type?","+t.type:"")+(t.route_id?","+t.route_id:"")})))}:{};"undefined"!=typeof window&&(window.SallaApplePay=P),"undefined"!=typeof window&&window.ApplePaySession?.canMakePayments()?P.init():"undefined"!=typeof document&&document.querySelectorAll("data-show-if-apple-pay-supported").forEach((t=>t.style.display="none"));const O=class{constructor(i){t(this,i),this.validationFailed=s(this,"validationFailed"),this.requireLogin=s(this,"requireLogin"),this.type="buy",this.productType="product",this.options={},this.collectedOrderOptions=[],this.optionsResolved=!1,this.applePayAmount=0,this.pendingApplePaySession=null,this.quickBuy=salla.lang.get("pages.products.buy_now"),this.handleApplePaySessionStarted=t=>!!salla.config.get("store.settings.order_options.mandatory",!1)&&!this.optionsResolved&&(this.optionsResolved=!0,this.pendingApplePaySession=t,async function(t){let s;try{s=await salla.api.withoutNotifier((()=>salla.product.api.getOrderOptions([{id:t.productId,quantity:t.quantity}])))}catch(s){return salla?.logger?.warn?.("order-options: fetch failed",s),void t.beginPendingSession()}const i=s?.data?.order_options||[];if(!i.length)return void t.beginPendingSession();t.discardPendingSession();const a=Number(t.amount)>0?Number(t.amount):Number(s?.data?.products?.[0]?.price?.amount)||0,e=function(){let t=document.querySelector("salla-order-options-modal");return t||(t=document.createElement("salla-order-options-modal"),document.body.appendChild(t)),t}();try{await e.open({orderOptions:i,basePrice:a,paymentMode:"apple-pay",onSubmit:t.onSubmit})}catch{}}({productId:this.productId,amount:Number(this.amount),quantity:this.getSelectedQuantity(),beginPendingSession:()=>{this.pendingApplePaySession?.begin(),this.pendingApplePaySession=null},discardPendingSession:()=>{this.pendingApplePaySession=null},onSubmit:(t,s)=>{this.collectedOrderOptions=t,this.applePayAmount=s,this.settlePayment()}}),!0),salla.lang.onLoaded((()=>{this.quickBuy=salla.lang.get("pages.products.buy_now")}))}quickBuyHandler(){if(salla.config.isGuest()&&!this.isGuestCheckout())return this.requireLogin.emit({productId:this.productId}),void salla.api.auth.requireLoginThen("salla-quick-buy::user.logged-in",(()=>this.quickBuyHandler()));this.validatePdpOptionsSync()&&(this.optionsResolved=!1,this.collectedOrderOptions=[],this.applePayAmount=0,this.settlePayment())}validatePdpOptionsSync(){return!!function(t){const s=document.querySelector(`salla-product-options[product-id="${t}"]`);if(!s)return!0;const i=s.querySelectorAll("[required]");let a=!0;return i.forEach((t=>{t.disabled||t.closest(".hidden")||"reportValidity"in t&&!t.reportValidity()&&(a=!1)})),a}(this.productId)||(this.validationFailed.emit({productId:this.productId}),salla.error(salla.lang.get("common.messages.required_fields")),!1)}getSelectedQuantity(){try{const t=this.host.getElementSallaData?.(),s=Number(t instanceof FormData?t.get("quantity"):t?.quantity);return Number.isFinite(s)&&s>0?s:1}catch{return 1}}async settlePayment(){let t=this.host.getElementSallaData();if(function(t,s){s.length&&(t&&"function"==typeof t.append?s.forEach(((s,i)=>{t.append(`order_options[${i}][id]`,String(s.id)),t.append(`order_options[${i}][value]`,String(s.value))})):t&&"object"==typeof t&&(t.order_options=s))}(t,this.collectedOrderOptions),!this.isApplePayActive)return salla.api.request("checkout/quick-purchase/"+this.productId,t,"post").then((t=>(t.data.redirect&&(window.location.href=t.data.redirect),t)));t.is_applepay=!0,"append"in t&&t.append("is_applepay",!0),salla.event.dispatch("payments::apple-pay.start-transaction",{amount:this.applePayAmount>0?this.applePayAmount:this.amount,currency:this.currency||salla.config.get("store.settings.buy_now.currency")||"SAR",requiredShippingContactFields:this.getRequiredShippingContactFields(),shippingMethods:this.isRequireShipping?[]:void 0,supportedNetworks:this.isLegacyBuyNowBE()?salla.config.get("store.settings.buy_now.networks"):Array.isArray(this.supportedNetworks)&&this.supportedNetworks.length?this.supportedNetworks:salla.config.get("store.settings.buy_now.supportedNetworks"),supportedCountries:this.isLegacyBuyNowBE()?salla.config.get("store.settings.buy_now.countries"):Array.isArray(this.supportedCountries)&&this.supportedCountries.length?this.supportedCountries:salla.config.get("store.settings.buy_now.supportedCountries"),countryCode:salla.config.get("store.store_country")||"SA",onStartedSession:this.handleApplePaySessionStarted,validateMerchant:{url:this.validateHost?`${this.validateHost}/checkout/applepay/validate`:salla.url.get("checkout/applepay/validate"),onSuccess:s=>this.applePayOnly&&!this.productId?this.cartId?(window.SallaApplePay.id=this.cartId,salla.log("🍏 Pay: create checkout success: with id #"+this.cartId),Promise.resolve(s)):(salla.logger.warn("🍏 Pay: trying to create applePay transaction without cartId/ProductId !"),Promise.resolve(s)):salla.api.request("checkout/quick-purchase/"+this.productId,"object"==typeof t?t:void 0,"post",{}).then((t=>t?.data?.redirect?(salla.log("🍏 Pay: create checkout success: redirect exits, go to checkout page"),window.location.href=t.data.redirect.url,t):t?.data?.id?(window.SallaApplePay.id=t.data.id,void salla.log("🍏 Pay: create checkout success: with id #"+window.SallaApplePay.id)):(salla.logger.warn("🍏 Pay: create checkout success: No id, or redirect"),t)))},authorized:{url:salla.url.get("checkout/{id}/payments/submit"),onFailed:t=>{window.SallaApplePay.onCancel({},t?.data?.error?.message||t?.data?.error?.code||salla.lang.get("pages.checkout.payment_failed"))},onSuccess:t=>{window.location.href=t.redirect.url,salla.log("🍏 Pay: authorized Success:: redirect to thank you page, order placed")}},shippingMethodSelected:this.isRequireShipping?{url:salla.url.get("checkout/{id}/shipping/details")}:void 0,shippingContactSelected:this.isRequireShipping?{url:salla.url.get("checkout/{id}/address/add")}:void 0,guestContactSelected:this.isGuestCheckout()?{url:salla.url.get("checkout/{id}/customer")}:void 0,onCouponCodeChanged:{url:salla.url.get("checkout/{id}/coupons")},recalculateTotal:{url:salla.url.get("checkout/{id}/payments/recalculate?payment_method=apple_pay")},onError:function(t){salla.log(t),salla.notify.error(t)}})}isGuestCheckout(){return salla.config.isGuest()&&salla.config.get("store.features").includes("guest-checkout")&&this.isPhysicalProduct()}getRequiredShippingContactFields(){let t=[];return this.isRequireShipping&&t.push("postalAddress"),this.isGuestCheckout()&&t.push("email","phone","name"),t}isLegacyBuyNowBE(){return null!=salla?.config?.get?.("store.settings.buy_now.multi_currency")}applyBaseCurrencyPrice(t){if(this.isLegacyBuyNowBE())return void(null!=t?.price&&(this.amount=t.price));const s=t?.base_currency_price;null!=s?.amount?(this.amount=s.amount,s?.currency&&(this.currency=s.currency)):null!=t?.price&&(this.amount=t.price,this.currency=salla.config.get("user.currency_code")||this.currency||"SAR")}componentWillLoad(){console.log("🍏 Pay: Quick Buy Component Loaded");const t="undefined"!=typeof window&&!!window.ApplePaySession?.canMakePayments?.(),s=salla?.config?.get?.("store.settings.payments")?.includes?.("apple_pay")??!0,i=salla?.config?.get?.("store.settings.is_salla_gateway",!1)??!0;this.isApplePayActive=t&&s&&i;const a=async()=>{if(this.isLegacyBuyNowBE()&&!this.currency&&salla?.config?.get&&(this.currency=salla.config.get("store.settings.buy_now.multi_currency")?salla.config.get("user.currency_code"):salla.config.get("store.settings.buy_now.currency")||"SAR"),!this.productId&&salla?.config?.get&&salla.url?.is_page&&(this.productId=salla.config.get("page.id")),this.applePayOnly||this.productId){if(this.amount&&this.isRequireShipping||!this.productId||!salla?.product?.getDetails||await salla.product.getDetails(this.productId,[]).then((t=>{this.applyBaseCurrencyPrice(t?.data),this.isRequireShipping=t?.data?.is_require_shipping||!1})).catch((t=>{salla?.logger?.warn?.("🍏 Pay: Failed load the quick buy, get the product details failed: ",t)})),"donate"===this.type&&salla?.event?.on?salla.event.on("product-options::donation-changed",(t=>{String(t.id)===String(this.productId)&&this.applyBaseCurrencyPrice(t)})):salla?.url?.is_page?.("product.single")&&salla?.product?.event?.onPriceUpdated&&salla.product.event.onPriceUpdated((t=>{this.applyBaseCurrencyPrice(t?.data)})),this.isApplePayActive=(salla?.helpers?.hasApplePay?.()??t)&&(salla?.config?.get?.("store.settings.payments")?.includes?.("apple_pay")??s)&&(salla?.config?.get?.("store.settings.is_salla_gateway",!1)??i),!document.getElementById("apple-pay-sdk")&&this.isApplePayActive){const t=document.createElement("script");t.src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js",t.setAttribute("id","apple-pay-sdk"),t.async=!0,document.body.appendChild(t)}}else salla?.logger?.warn?.("🍏 Pay: Failed load the quick buy, the product id is missing")};return new Promise((t=>{"function"==typeof salla?.onReady?salla.onReady((()=>a().then((()=>t(!0))))):a().then((()=>t(!0)))}))}render(){return i(a,{key:"c2ba63eb4fad49f80977d6f1adc836f655524933"},this.quickBuyButton())}quickBuyButton(){return i("apple-pay-button",{locale:salla?.config?.get?.("user.language_code")||"ar",onClick:()=>this.quickBuyHandler(),"data-quick-purchase":"applepay",class:"s-quick-buy-apple-pay","data-is-applepay":"1",buttonstyle:"black",type:this.type})}isPhysicalProduct(){return"product"===this.productType||"group_products"===this.productType||"food"===this.productType}get host(){return e(this)}};O.style=".s-quick-buy-button .s-button-text{display:flex}apple-pay-button{--apple-pay-button-width:100%;--apple-pay-button-height:40px;--apple-pay-button-border-radius:.75rem;--apple-pay-button-box-sizing:content-box}";export{m as salla_add_product_button,y as salla_bought_together,g as salla_product_availability,v as salla_product_options,O as salla_quick_buy}
4
+ import{r as t,c as s,h as i,H as a,a as e,e as o}from"./p-DjOBdfDM.js";import{P as n}from"./p-DY4LZmNP.js";import{H as l}from"./p-XnA1YTjA.js";import{a as r}from"./p-CL7OPpYS.js";import{B as c}from"./p-D3mWkc-3.js";import{D as d}from"./p-CoQJOPRz.js";import{S as h}from"./p-BZp0rKEO.js";import{C as p}from"./p-C6jIkM-X.js";import"./p-CgtvEd63.js";class u{constructor(t,s){this.host=t,this.productId=s,this.collected=!1,this.livePrice=0}static attach(t,s){const i=t.querySelector("salla-mini-checkout-widget");if(!i)return!1;const a=new u(t,String(s));return salla.product?.event?.onPriceUpdated?.((t=>{a.livePrice=Number(t?.data?.price)||a.livePrice})),i.addEventListener("click",(t=>a.handleWidgetClick(t,i)),!0),!0}getSelectedQuantity(){try{const t=document.querySelector("form.product-form"),s=t?.getElementSallaData?.(),i=Number(s instanceof FormData?s.get("quantity"):s?.quantity);if(Number.isFinite(i)&&i>0)return i}catch{}return Number(this.host.getAttribute("quantity"))||1}async handleWidgetClick(t,s){if(this.collected)return void(this.collected=!1);if(t.preventDefault(),t.stopImmediatePropagation(),!await this.validatePdpOptions())return;if(salla.config.isGuest())return void salla.api.auth.requireLoginThen("salla-add-product-button::oo.after-login",(()=>this.handleWidgetClick(t,s)));let i;s.classList.add("s-add-product-button-busy");try{i=await salla.api.withoutNotifier((()=>salla.product.api.getOrderOptions([{id:this.productId,quantity:this.getSelectedQuantity()}])))}catch(t){return salla?.logger?.warn?.("order-options: fetch failed",t),s.classList.remove("s-add-product-button-busy"),void this.resumeWidget(s)}s.classList.remove("s-add-product-button-busy");const a=i?.data?.order_options||[];if(!a.length)return void this.resumeWidget(s);const e=this.livePrice>0?this.livePrice:Number(i?.data?.products?.[0]?.price?.amount)||0,o=this.ensureModal();try{const t=await o.open({orderOptions:a,basePrice:e});this.injectIntoMini(t?.orderOptions||[]),this.resumeWidget(s)}catch{}}async validatePdpOptions(){const t=document.querySelector(`salla-product-options[product-id="${this.productId}"]`);return!t||("function"==typeof t.validateAndScroll?await t.validateAndScroll():"function"!=typeof t.reportValidity||await t.reportValidity())}injectIntoMini(t){if(!t.length)return;const s=this.productId,i=a=>{if(String(a?.id)===String(s))try{a?.payload?.set?.("order_options",t)}finally{salla.event.off("cart::before.add.item",i)}};salla.event.on("cart::before.add.item",i)}ensureModal(){let t=document.querySelector("salla-order-options-modal");return t||(t=document.createElement("salla-order-options-modal"),document.body.appendChild(t)),t}resumeWidget(t){this.collected=!0;const s=t.shadowRoot?.querySelector?.(".s-fast-checkout-button");s?s.click():"function"==typeof t.click&&t.click()}}const m=class{constructor(i){t(this,i),this.success=s(this,"success"),this.failed=s(this,"failed"),this.hostAttributes={},this.hasPreOrder=!1,this.productStatus="sale",this.productType="product",this.selectedOptions=[],this.buyNowText=salla.lang.get("pages.products.buy_now"),this.isDesktopViewport="undefined"==typeof window||window.matchMedia("(min-width: 768px)").matches,this.viewportMediaQuery=null,this.orderOptionsGateAttached=!1,this.onViewportChange=t=>{this.isDesktopViewport=t.matches,this.btn?.setText(t.matches&&this.passedLabel?this.passedLabel:this.getLabel())},salla.lang.onLoaded((()=>{this.buyNowText=salla.lang.get("pages.products.buy_now")}))}getLabel(){return"sale"===this.productStatus&&this.supportStickyBar&&!this.isDesktopViewport&&this.showQuickBuy&&this.isApplePayActive?n:this.hasPreOrder?salla.lang.get("pages.products.pre_order_now"):"sale"===this.productStatus&&"booking"===this.productType?salla.lang.get("pages.cart.book_now"):"sale"===this.productStatus?salla.lang.get("pages.cart.add_to_cart"):"donating"!==this.productType?salla.lang.get("pages.products.out_of_stock"):salla.lang.get("pages.products.donation_exceed")}addProductToCart(t){if("booking"===this.productType)return t.preventDefault(),this.addBookingProduct();if("submit"===this.hostAttributes.type)return!1;t.preventDefault(),this.btn?.disable();const s=document.querySelector(`salla-product-options[product-id="${this.productId}"]`);return s&&"function"==typeof s.validateAndScroll?s.validateAndScroll().then((async t=>{const s={isValid:t,component:this};if(await salla.hooks.call("salla-add-product-button","validate",s),s.isValid)return this._proceedAddToCart();this.btn?.enable()})).catch((()=>{this.btn?.enable()})):this._proceedAddToCart()}async _proceedAddToCart(){const t=this.host.closest("salla-products-list, salla-products-slider")??this.host.closest("salla-product-card, custom-salla-product-card"),s=Object.entries({id:this.productId,donation_amount:this.donatingAmount,quantity:this.quantity,endpoint:"quickAdd",source:l.getProductsSource(t?.getAttribute("source"))}).reduce(((t,[s,i])=>i?(t[s]=i,t):t),{});return salla.cart.addItem(s).then((async t=>(this.selectedOptions=[],this.btn?.enable(),this.success.emit(t),t))).catch((t=>{this.failed.emit(t),this.btn?.enable()}))}addBookingProduct(){return salla.config.isGuest()?(salla.auth.api.setAfterLoginEvent("booking::add",this.productId),void salla.event.dispatch("login::open")):salla.booking.add(this.productId).then((t=>this.success.emit(t))).catch((t=>this.failed.emit(t)))}getBtnAttributes(){for(let t=0;t<this.host.attributes.length;t++)["id","class"].includes(this.host.attributes[t].name)||(this.hostAttributes[this.host.attributes[t].name]=this.host.attributes[t].value);return this.hostAttributes}get notifyChannels(){return this.channels||salla.api.product.getAvailabilityChannels?.()||l.availabilityChannels()}getQuickBuyBtnAttributes(){return{...this.getBtnAttributes(),type:this.supportStickyBar&&!this.isDesktopViewport?"plain":"donating"==this.productType?"donate":"buy"}}miniCheckoutWidget(){let t=salla.config.get("store.id");if(t)return i("salla-mini-checkout-widget",{language:salla.lang.locale,"store-id":t,config:{user:salla.config.get("user"),failure_url:window.location.href},products:[this.productId],api:salla.config.get("store.api"),outline:!0,"form-selector":"form.product-form",class:"s-add-product-button-mini-checkout"},i("div",{slot:"widget-label",class:"s-add-product-button-mini-checkout-content"},i("span",{innerHTML:'\x3c!-- Generated by IcoMoon.io --\x3e\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">\n<title>full-wallet</title>\n<path d="M29 12h-26c-0.668-0.008-1.284-0.226-1.787-0.59l0.009 0.006c-0.744-0.552-1.222-1.428-1.222-2.416 0-1.657 1.343-3 2.999-3h6c0.552 0 1 0.448 1 1s-0.448 1-1 1v0h-6c-0.552 0-1 0.448-1 1 0 0.326 0.156 0.616 0.397 0.798l0.002 0.002c0.167 0.12 0.374 0.194 0.599 0.2l0.001 0h26c0.552 0 1 0.448 1 1s-0.448 1-1 1v0zM27 12c-0.552 0-1-0.448-1-1v0-3h-3c-0.552 0-1-0.448-1-1s0.448-1 1-1v0h4c0.552 0 1 0.448 1 1v0 4c0 0.552-0.448 1-1 1v0zM29 30h-26c-1.657 0-3-1.343-3-3v0-18c0-0.552 0.448-1 1-1s1 0.448 1 1v0 18c0 0.552 0.448 1 1 1v0h25v-5c0-0.552 0.448-1 1-1s1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM29 18c-0.552 0-1-0.448-1-1v0-6c0-0.552 0.448-1 1-1s1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM31 24h-7c-2.209 0-4-1.791-4-4s1.791-4 4-4v0h7c0.552 0 1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM24 18c-1.105 0-2 0.895-2 2s0.895 2 2 2v0h6v-4zM25 12c-0.001 0-0.001 0-0.002 0-0.389 0-0.726-0.222-0.891-0.546l-0.003-0.006-3.552-7.106-2.306 1.152c-0.13 0.066-0.284 0.105-0.447 0.105-0.552 0-1-0.448-1-1 0-0.39 0.223-0.727 0.548-0.892l0.006-0.003 3.2-1.6c0.13-0.067 0.284-0.106 0.447-0.106 0.39 0 0.727 0.223 0.892 0.548l0.003 0.006 4 8c0.067 0.13 0.106 0.285 0.106 0.448 0 0.552-0.448 1-1 1v0zM21 12c-0.001 0-0.001 0-0.002 0-0.389 0-0.726-0.222-0.891-0.546l-0.003-0.006-3.552-7.106-15.104 7.552c-0.13 0.066-0.284 0.105-0.447 0.105-0.552 0-1-0.448-1-1 0-0.39 0.223-0.727 0.548-0.892l0.006-0.003 16-8c0.13-0.067 0.284-0.106 0.447-0.106 0.39 0 0.727 0.223 0.892 0.548l0.003 0.006 4 8c0.067 0.13 0.106 0.285 0.106 0.448 0 0.552-0.448 1-1 1-0.001 0-0.001 0-0.002 0h0z"></path>\n</svg>\n'}),this.buyNowText))}componentWillLoad(){return salla.onReady().then((()=>{if(document.documentElement.classList.add("hydrated"),this.showQuickBuy=this.quickBuy&&salla.config.get("store.settings.buy_now")&&"sale"==this.productStatus&&"booking"!==this.productType,this.isApplePayActive=window.ApplePaySession?.canMakePayments()&&salla.config.get("store.settings.payments")?.includes("apple_pay")&&salla.config.get("store.settings.is_salla_gateway",!1),this.passedLabel=this.host.innerHTML.replace("\x3c!----\x3e","").trim(),this.passedLabel&&this.isDesktopViewport)return this.btn?.setText(this.passedLabel);"submit"===this.host.getAttribute("type")&&this.supportStickyBar&&(this.viewportMediaQuery=window.matchMedia("(min-width: 768px)"),this.viewportMediaQuery.addEventListener("change",this.onViewportChange))}))}render(){return this.host.closest(".swiper-slide")?.classList.contains("swiper-slide-duplicate")?"":this.hasSubscribedOptions?i(a,null,i("salla-product-availability",{...this.getBtnAttributes(),"is-subscribed":!0},i("span",{class:"s-hidden"},i("slot",null)))):"out-and-notify"===this.productStatus&&this.notifyChannels||this.hasOutOfStockOption?i(a,null,i("salla-product-availability",{...this.getBtnAttributes()},i("span",{class:"s-hidden"},i("slot",null)))):i(a,{class:{"s-add-product-button-with-quick-buy":this.showQuickBuy,"s-add-product-button-with-sticky-bar":this.supportStickyBar,"s-add-product-button-with-apple-pay":this.showQuickBuy&&this.isApplePayActive}},i("div",{class:{"s-add-product-button-main":this.showQuickBuy,"w-full":!document.getElementById("fast-checkout-js")||["financial_support","donating"].includes(this.productType)}},i("salla-button",{color:"sale"===this.productStatus?"primary":"light",type:"button",fill:"sale"===this.productStatus?"solid":"outline",ref:t=>this.btn=t,onClick:t=>this.addProductToCart(t),disabled:"sale"!==this.productStatus,...this.getBtnAttributes(),"loader-position":"center"},i("slot",null)),this.showQuickBuy&&document.getElementById("fast-checkout-js")&&!["financial_support","donating"].includes(this.productType)?this.miniCheckoutWidget():""),this.showQuickBuy&&this.isApplePayActive?i("salla-quick-buy",{...this.getQuickBuyBtnAttributes()}):"")}async componentDidLoad(){await Salla.hooks.registerComponent("salla-add-product-button",this),this.notifyOptionsAvailability&&salla.event.on("product-options::change",(async t=>{if(!["thumbnail","color","single-option"].includes(t.option.type))return;this.hasSubscribedOptions=!1,this.selectedOptions=await(document.querySelector(`salla-product-options[product-id="${this.productId}"]`)?.getSelectedOptions()),this.hasOutOfStockOption=await(document.querySelector(`salla-product-options[product-id="${this.productId}"]`)?.hasOutOfStockOption());let s=salla.storage.get(`product-${this.productId}-subscribed-options`);if((s||this.subscribedOptions)&&this.hasOutOfStockOption)if(salla.config.isGuest()){const t=s?s.map((t=>t.split(",").map((t=>parseInt(t))))):[];this.hasSubscribedOptions=t.length>0&&t.some((t=>t.every((t=>this.selectedOptions.some((s=>s.id===t))))))}else this.hasSubscribedOptions=!(!this.subscribedOptions||"null"===this.subscribedOptions||"[]"===this.subscribedOptions)&&JSON.parse(this.subscribedOptions).some((t=>t.every((t=>this.selectedOptions.some((s=>s.id===t))))))}))}componentDidRender(){!this.orderOptionsGateAttached&&this.productId&&salla.config.get("store.settings.order_options.mandatory",!1)&&u.attach(this.host,this.productId)&&(this.orderOptionsGateAttached=!0),!this.passedLabel||this.supportStickyBar&&!this.isDesktopViewport?(this.btn?.setText(this.getLabel()),salla.lang.onLoaded((()=>this.btn?.setText(this.getLabel())))):this.btn?.setText(this.passedLabel)}disconnectedCallback(){this.viewportMediaQuery?.removeEventListener("change",this.onViewportChange)}get host(){return e(this)}};m.style=":host{display:block}salla-add-product-button[width=wide]{width:100%}";const y=class{constructor(s){t(this,s),this.limit=3,this.recommendations=[],this.selectedIds=new Set,this.isLoading=!0,this.canRender=!0,this.isAdding=!1,this.title=salla.lang.get("pages.products.bought_together_title"),this.subtitle=salla.lang.get("pages.products.bought_together_subtitle"),this.buyTogetherFor=salla.lang.get("pages.products.buy_together_for"),this.resolvedProductId=0,this.listViewTracked=!1,salla.lang.onLoaded((()=>{this.title=salla.lang.get("pages.products.bought_together_title"),this.subtitle=salla.lang.get("pages.products.bought_together_subtitle"),this.buyTogetherFor=salla.lang.get("pages.products.buy_together_for")}))}componentWillLoad(){salla.onReady().then((()=>{if(!salla.config.get("store.settings.product.bought_together"))return void(this.canRender=!1);const t=salla.config.get("page.id");if(t)return this.resolvedProductId=t,r(String(t));this.canRender=!1})).then((t=>{if(!t?.length)return void(this.canRender=!1);const s=[String(this.resolvedProductId),...t.slice(0,this.limit)];return salla.product.fetch({source:"selected",source_value:s})})).then((t=>{if(!t)return;const s=t?.data??[];if(!s.length)return void(this.canRender=!1);const i=s.find((t=>String(t.id)===String(this.resolvedProductId))),a=s.filter((t=>String(t.id)!==String(this.resolvedProductId)));a.length?(this.recommendations=i?[i,...a]:a,this.selectedIds=new Set(this.recommendations.map((t=>t.id)))):this.canRender=!1})).catch((()=>{this.canRender=!1})).finally((()=>{this.isLoading=!1}))}componentDidRender(){!this.recommendations.length||this.listViewTracked||this.intersectionObserver||(this.intersectionObserver=new IntersectionObserver((t=>{t.some((t=>t.isIntersecting))&&(this.listViewTracked=!0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.emitListViewed())}),{threshold:.1}),this.intersectionObserver.observe(this.el))}disconnectedCallback(){this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0}emitListViewed(){const t=this.recommendations.filter((t=>!this.isMainProduct(t.id)));salla.event.emit("salla-bought-together::list.viewed",{products:t})}isMainProduct(t){return String(t)===String(this.resolvedProductId)}recommendedPosition(t){const s=this.recommendations.filter((t=>!this.isMainProduct(t.id))).findIndex((s=>String(s.id)===String(t)));return-1===s?-1:s+1}emitProductClicked(t,s){salla.event.emit("salla-bought-together::product.clicked",[{product:t,position:s}])}toggleProduct(t){const s=new Set(this.selectedIds);s.has(t)?s.delete(t):s.add(t),this.selectedIds=s}get totalPrice(){const t=this.recommendations.filter((t=>this.selectedIds.has(t.id))).reduce(((t,s)=>t+(s.price??0)),0),s=salla.config.get("store.currency.decimals")??2,i=Math.pow(10,s);return salla.money(Math.round(t*i)/i)}async addSelectedToCart(){if(this.isAdding||!this.selectedIds.size)return;this.isAdding=!0;let t=!1;try{for(const s of Array.from(this.selectedIds))try{salla.cart?.api&&(salla.cart.api.addToCartSource="pdp_fbt");const t=await salla.cart.addItem({id:s,endpoint:"quickAdd",source:"pdp_fbt"}),i=this.recommendations.find((t=>t.id===s));if(i){const a=this.isMainProduct(s)?0:this.recommendedPosition(s),e=t?.data?.items?.find((t=>String(t.product_id)===String(i.id)))??t?.data?.items?.slice(-1)[0];salla.event.emit("salla-bought-together::product.added",[{product:i,position:a,cartItem:e,cartId:t?.data?.id}])}}catch(s){salla.log(s),t=!0}t&&salla.error(salla.lang.get("common.messages.error"))}finally{this.isAdding=!1}}getSkeletonView(){return i(a,{class:"s-bought-together-entry"},i("div",{class:"s-bought-together-skeleton"},i("div",{class:"s-bought-together-skeleton-header"},i("salla-skeleton",{height:"16px",width:"35%"}),i("salla-skeleton",{height:"10px",width:"60%"})),Array(4).fill(null).map(((t,s)=>i("div",{key:s,class:"s-bought-together-skeleton-item"},i("salla-skeleton",{height:"22px",width:"22px"}),i("salla-skeleton",{height:"48px",width:"48px"}),i("div",{class:"s-bought-together-skeleton-info"},i("salla-skeleton",{height:"12px",width:"55%",style:{marginBottom:"3px"}}),i("salla-skeleton",{height:"10px",width:"25%"}))))),i("salla-skeleton",{height:"44px",width:"100%"})))}render(){return this.canRender?this.isLoading?this.getSkeletonView():this.recommendations.length?i(a,{class:"s-bought-together-entry"},i("div",{class:"s-bought-together-header"},i("h3",{class:"s-bought-together-title"},this.title),i("p",{class:"s-bought-together-subtitle"},this.subtitle)),i("div",{class:"s-bought-together-list"},this.recommendations.map((t=>i("div",{key:t.id,class:"s-bought-together-item"+(this.selectedIds.has(t.id)?"":" s-bought-together-item--unchecked")},i("label",{class:"s-bought-together-checkbox-label"},i("input",{type:"checkbox",class:"s-bought-together-checkbox",checked:this.selectedIds.has(t.id),onChange:()=>this.toggleProduct(t.id)}),i("span",{class:"s-bought-together-checkmark"})),i("a",{class:"s-bought-together-item-link",href:t.url,onClick:()=>!this.isMainProduct(t.id)&&this.emitProductClicked(t,this.recommendedPosition(t.id))},i("img",{class:"s-bought-together-item-img",src:t.image?.url||salla.url.cdn("images/s-empty.png"),alt:t.image?.alt||t.name,loading:"lazy",decoding:"async",onError:t=>{t.currentTarget.onerror=null,t.currentTarget.src=salla.url.cdn("images/s-empty.png")}}),i("span",{class:"s-bought-together-item-name"},t.name)),i("span",{class:"s-bought-together-item-price",innerHTML:null!=t.price?salla.money(t.price):""}))))),i("salla-button",{class:"s-bought-together-btn",disabled:!this.selectedIds.size||this.isAdding,loading:this.isAdding,onClick:()=>this.addSelectedToCart()},i("span",{innerHTML:`${this.buyTogetherFor} ${this.totalPrice}`}))):null:null}get el(){return e(this)}};y.style=':host{display:block}.s-bought-together-checkbox:checked~.s-bought-together-checkmark{background-color:var(--color-primary, #2ECC71);border-color:var(--color-primary, #2ECC71)}.s-bought-together-checkbox:checked~.s-bought-together-checkmark::after{content:"";display:block;width:5px;height:9px;border:solid #fff;border-width:0 2px 2px 0;transform:rotate(45deg);margin-top:-2px}';const g=class{constructor(s){t(this,s),this.isUser=salla.config.isUser(),this.translationLoaded=!1,this.notifyOptionsAvailability=!1,this.isSubscribed=!1,this.handleSubmitOptions=async()=>{let t={id:this.productId};if(!this.notifyOptionsAvailability)return t;let s=document.querySelector(`salla-product-options[product-id="${this.productId}"]`),i=Object.values(await(s?.getSelectedOptionsData())||{});if(i.length&&!await(s?.reportValidity())){let t=salla.lang.get("common.messages.required_fields");throw salla.error(t),t}return t.options=[],i.forEach((s=>{s&&!isNaN(s)&&t.options.push(Number(s))})),t},this.typing=t=>{const s=t.target.nextElementSibling;t.target.classList.remove("s-has-error"),s?.classList.contains("s-product-availability-error-msg")&&(s.innerText=""),13===t.keyCode&&this.submit()},salla.lang.onLoaded((()=>{this.translationLoaded=!0,this.title_=this.host.title||salla.lang.get("pages.products.notify_availability_title"),this.modal?.setTitle(this.title_)})),this.productId||(this.productId=salla.config.get("page.id")),this.isUser||(this.channelsWatcher(this.channels),this.title_=this.host.title||salla.lang.get("pages.products.notify_availability_title"),this.host.removeAttribute("title"))}channelsWatcher(t){let s=t||salla.api.product.getAvailabilityChannels?.()||l.availabilityChannels();this.channels_=s?s.split(","):[]}get isSubscribedToProduct(){return this.isSubscribed||!this.notifyOptionsAvailability&&(!!salla.api.product.isSubscribedToAvailability?.(this.productId)||!!salla.storage.get(`product-${this.productId}-subscribed`))}openModel(){this.handleSubmitOptions().then((t=>t?this.modal.open():null))}async submit(){let t=await this.handleSubmitOptions();if(this.isUser)return salla.api.product.availabilitySubscribe(t).then((()=>this.isSubscribed=!0));if(this.channels_.includes("sms")||this.channels_.includes("whatsapp")){let{phone:s,countryCode:i}=await this.mobileInput.getValues();t.country_code=i,t.phone=s}return this.channels_.includes("email")&&""!==this.email.value&&(t.email=this.email.value),await this.validateform(),this.btn.load().then((()=>this.btn.disable())).then((()=>salla.api.product.availabilitySubscribe(t))).then((()=>{if(this.notifyOptionsAvailability){if(t.options.length){let s=salla.storage.get(`product-${this.productId}-subscribed-options`)||[],i=t.options.join(",");s.includes(i)?salla.log("already subscribed to this options"):(s.push(i),salla.storage.set(`product-${this.productId}-subscribed-options`,s),this.isSubscribed=!0)}}else this.isSubscribed=!0})).then((()=>this.btn.stop())).then((()=>this.modal.close())).catch((()=>this.btn.stop()&&this.btn.enable()))}async validateform(){try{if(this.channels_.includes("email")){const t=l.isValidEmail(this.email.value);if(t)return;!t&&this.validateField(this.email,salla.lang.get("common.elements.email_is_valid"))}if((this.channels_.includes("sms")||this.channels_.includes("whatsapp"))&&await this.mobileInput.isValid())return}catch(t){throw"Please insert required fields"}}validateField(t,s){t.classList.add("s-has-error"),t.nextElementSibling.innerText="* "+s}render(){return i(a,{key:"ccb098126e7809a6386ff38c74dfa0f00f64deeb",class:"s-product-availability-wrap"},this.isSubscribedToProduct?i("div",{class:"s-product-availability-subscribed"},i("span",{innerHTML:c,class:"s-product-availability-subs-icon"}),salla.lang.get("pages.products.notify_availability_success")):i("salla-button",{width:"wide",onClick:()=>this.isUser?this.submit():this.openModel()},salla.lang.get("pages.products.notify_availability")),this.isUser||this.isSubscribedToProduct?"":this.renderModal())}renderModal(){return i("salla-modal",{ref:t=>this.modal=t,"modal-title":this.title_,subTitle:salla.lang.get("pages.products.notify_availability_subtitle"),width:"sm"},i("span",{slot:"icon",class:"s-product-availability-header-icon",innerHTML:c}),i("div",{class:"s-product-availability-body"},this.channels_.includes("email")?[i("label",{class:"s-product-availability-label"},salla.lang.get("common.elements.email")),i("input",{class:"s-product-availability-input",onKeyDown:t=>this.typing(t),placeholder:salla.lang.get("common.elements.email_placeholder")||"your@email.com",ref:t=>this.email=t,type:"email"}),i("span",{class:"s-product-availability-error-msg"})]:"",this.channels_.includes("sms")||this.channels_.includes("whatsapp")?[i("label",{class:"s-product-availability-label"},salla.lang.get("common.elements.mobile")),i("salla-tel-input",{ref:t=>this.mobileInput=t,onKeyDown:t=>this.typing(t)})]:""),i("div",{slot:"footer",class:"s-product-availability-footer"},i("salla-button",{class:"modal-cancel-btn",width:"wide",color:"light",fill:"outline",onClick:()=>this.modal.close()},salla.lang.get("common.elements.cancel")),i("salla-button",{class:"submit-btn","loader-position":"center",width:"wide",ref:t=>this.btn=t,onClick:()=>this.submit()},salla.lang.get("common.elements.submit"))))}get host(){return e(this)}static get watchers(){return{channels:["channelsWatcher"]}}};var f,b,w;g.style="",function(t){t[t.INIT=1]="INIT",t[t.IDLE=2]="IDLE",t[t.PROCESSING_QUEUED=9]="PROCESSING_QUEUED",t[t.PROCESSING=3]="PROCESSING",t[t.PROCESSING_COMPLETE=5]="PROCESSING_COMPLETE",t[t.PROCESSING_ERROR=6]="PROCESSING_ERROR",t[t.PROCESSING_REVERT_ERROR=10]="PROCESSING_REVERT_ERROR",t[t.LOADING=7]="LOADING",t[t.LOAD_ERROR=8]="LOAD_ERROR"}(f||(f={})),function(t){t[t.EMPTY=0]="EMPTY",t[t.IDLE=1]="IDLE",t[t.ERROR=2]="ERROR",t[t.BUSY=3]="BUSY",t[t.READY=4]="READY"}(b||(b={})),function(t){t[t.INPUT=1]="INPUT",t[t.LIMBO=2]="LIMBO",t[t.LOCAL=3]="LOCAL"}(w||(w={}));const v=class{constructor(a){if(t(this,a),this.changed=s(this,"changed"),this.fileTypes={pdf:"application/pdf",png:"image/png",jpg:"image/jpeg",word:"application/doc,application/ms-doc,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",exl:"application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",txt:"text/plain"},this.outOfStockText="",this.donationAmount=salla.lang.get("pages.products.donation_amount"),this.selectDonationAmount=salla.lang.getWithDefault("pages.products.select_donation_amount","تحديد مبلغ التبرع"),this.selectAmount=salla.lang.getWithDefault("pages.products.select_amount","اختر المبلغ"),this.isCustomDonation=!1,this.selectedOptions=[],this.canDisabled=!1,this.disableCardValue=!0,this.availableDigitalCardValues=[],this.userInitiatedValidation=!1,this.isCartMode=!1,this.availabilityMap={},this.productAvailable=!1,this.outSkus=[],this.ignoreDefaultCardValue=!1,this.productId=salla.config.get("page.id"),this.noPadding=!1,this.handleDonationOptions=(t,s,i)=>{if("custom"===s&&"input"===i){const s=t.target;return salla.helpers.inputDigitsOnly(s),salla.event.emit("product-options::donation-changed",{id:this.productId,price:s.value}),void s.dispatchEvent(new window.Event("change",{bubbles:!0}))}const a="option"===i?String(t.target?.value??""):"";if("option"===i&&"custom"===s&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()),this.isCustomDonation="custom"===a,this.donationInput){if("custom"===a?(this.donationInput.value="",this.donationInput.focus()):this.donationInput.value=a,"custom"===s)return;salla.event.emit("product-options::donation-changed",{id:this.productId,price:a})}},this.hideLabel=t=>!(t.type!==d.DONATION||!t.donation||t.donation.can_donate),this.getExpireDonationMessage=t=>{if(!t.donation)return;const s=t.donation.target_amount<=t.donation.collected_amount;return i("div",{class:{"s-product-options-donation-message":!0,"s-product-options-donation-completed":s,"s-product-options-donation-expired":!s}},i("p",null,t.donation.target_message),i("span",{innerHTML:s?salla.money(t.donation.target_amount):""}))},salla.lang.onLoaded((()=>{this.outOfStockText=salla.lang.get("pages.products.out_of_stock"),this.donationAmount=salla.lang.get("pages.products.donation_amount"),this.selectDonationAmount=salla.lang.getWithDefault("pages.products.select_donation_amount","تحديد مبلغ التبرع"),this.selectAmount=salla.lang.getWithDefault("pages.products.select_amount","اختر المبلغ")})),this.options)try{return void this.setOptionsData(Array.isArray(this.options)?this.options:JSON.parse(this.options))}catch(t){salla.log("Bad json passed via options prop")}Array.isArray(this.optionsData)||(salla.log("Options is not an array[] ---\x3e ",this.optionsData),this.setOptionsData([])),this.productId&&!salla.url.is_page("cart")&&salla.api.product.getDetails(this.productId,["options"]).then((t=>{this.productAvailable=!t.data.is_out_of_stock,this.setOptionsData(t.data.options)}))}async setOptionsData(t){this.optionsData=t,this.outSkus=[],this.optionsData[0]?.details?.forEach((t=>{Object.entries(t.skus_availability||{}).filter((([,t])=>!t)).forEach((([t])=>this.outSkus.push(Number(t))))})),this.fillSelectedOptions(),this.computeAvailability()}async getOptionsData(){return this.optionsData}async getSelectedOptionsData(){const t={},s=this.host.getElementSallaData(),i=void 0!==this.bundleContext?this.bundleContext:null;return s.forEach(((s,a)=>{if(i){if(a.startsWith("bundle[")&&a.includes("[options][")){const i=a.split("[options][")[1].replace("]","");t[i]=s}}else a.startsWith("options[")&&(t[a.replace("options[","").replace("]","")]=s)})),t}async reportValidity(){const t=this.host.querySelectorAll("[required]");let s=!0;for(let i=0;i<t.length;i++){const a=t[i];a.disabled||a.closest(".hidden")||"reportValidity"in a&&!a.reportValidity()&&(s=!1)}return s}async hasOutOfStockOption(){return this.selectedOptions.some((t=>t.is_out))||this.selectedSkus?.length&&this.selectedSkus?.every((t=>this.outSkus.includes(t)))}async getSelectedOptions(){return this.selectedOptions}async getOption(t){return this.optionsData.find((s=>s.id===t))}invalidHandler(t,s){const i=t.target.closest(".s-product-options-option");i.classList.contains("s-product-options-option-error")||i.classList.add("s-product-options-option-error"),!this.userInitiatedValidation&&!salla.helpers.isIOSDevice()||salla.url.is_page("cart")||this.host.querySelector(".s-product-options-option-error")===i&&this.scrollToElement(i)}scrollToElement(t){t&&t.scrollIntoView({behavior:"smooth",block:"center"})}changedHandler(t,s,i=!0){const a={event:t,option:s,detail:null,productId:this.productId};if(s.details){const i=s.details.find((s=>Number(s.id)===Number(t.target.value)));a.detail=i}"country"===s.type&&this.handleCountryOptionChange(t,a.detail);const e=t.target.closest(".s-product-options-option");(t.target.value||(s.type===d.FILE||s.type===d.IMAGE)&&"added"===t.type||s.type===d.MAP&&"selected"===t.type&&t.target.lat&&t.target.lng)&&setTimeout((()=>{e.classList.remove("s-product-options-option-error")}),200),s.type===d.DONATION&&salla.event.emit("product-options::donation-changed",{id:this.productId,price:t.target.value}),this.setSelectedSkus(),this.handleRequiredMultipleOptions(s);const o=this.selectedOptions.findIndex((t=>t.option_id===a.option.id));if(a.option.type===d.MULTIPLE_OPTIONS){const t=this.selectedOptions.findIndex((t=>t.option_id===a.option.id&&t?.id===a.detail?.id));t>-1?this.selectedOptions.splice(t,1):this.selectedOptions.push({...a.detail,option_id:a.option.id})}else a.detail&&0!==Object.keys(a.detail).length?o>-1?this.selectedOptions[o]={...a.detail,option_id:a.option.id}:this.selectedOptions.push({...a.detail,option_id:a.option.id}):o>-1&&this.selectedOptions.splice(o,1);this.optionsData=this.optionsData.map((t=>t.id===a.option.id?{...t,details:t.details.map((t=>({...t,is_selected:a.option.type===d.MULTIPLE_OPTIONS?this.selectedOptions.some((s=>s.id===t.id)):Number(t.id)===Number(a.detail?.id),value:a.detail?.value})))}:t)),this.pruneInvisibleConditionalSelections(),this.setSelectedSkus(),requestAnimationFrame((()=>{this.optionsData?.filter((t=>t.type===d.MULTIPLE_OPTIONS&&t.required)).forEach((t=>this.handleRequiredMultipleOptions(t)))})),i&&(this.changed.emit(a),salla.event.emit("product-options::change",a))}setSelectedSkus(){this.selectedSkus=this.selectedOptions.map((t=>Object.keys(t.skus_availability||{}))).reduce(((t,s)=>t.filter((t=>s.includes(t)))),[]).map((t=>Number(t))),this.computeAvailability()}handleRequiredMultipleOptions(t){if(t.type!==d.MULTIPLE_OPTIONS||!t.required)return;const s=this.host.querySelector(`[data-option-id="${t.id}"]`);if(!s)return;const i=s.querySelectorAll("input:checked").length;s.querySelectorAll("input").forEach((t=>t.toggleAttribute("required",!i)))}pruneInvisibleConditionalSelections(){const t=Math.max(1,this.optionsData.length);for(let s=0;s<t;s++){let t=!1;for(const s of this.optionsData){const i=s.visibility_condition;if(!i)continue;const a=this.selectedOptions.filter((t=>t.option_id===i.option)).map((t=>String(t.id))).includes(String(i.value));("="===i.operator?a:!a)||this.clearStaleOption(s.id)&&(t=!0)}if(!t)break}}clearStaleOption(t){const s=this.optionsData.find((s=>s.id===t));if(!s)return!1;const i=this.selectedOptions.length;this.selectedOptions=this.selectedOptions.filter((s=>s.option_id!==t));const a=this.selectedOptions.length!==i,e=null!=s.value&&String(s.value).length>0,o=s.details?.some((t=>t.is_selected))??!1;return!!(a||e||o)&&(this.optionsData=this.optionsData.map((s=>s.id!==t?s:{...s,value:void 0,details:s.details?.map((t=>({...t,is_selected:!1})))??s.details})),!0)}getLatLng(t,s){return t?t.split(",")["lat"===s?0:1]:""}getDisplayForType(t){return this[`${t.type}Option`]?this[`${t.type}Option`](t):t.type===d.COLOR_PICKER?this.colorPickerOption(t):t.type===d.MULTIPLE_OPTIONS?this.multipleOptions(t):t.type===d.SINGLE_OPTION?this.singleOption(t):t.type===d.RADIO?this.radioOption(t):t.type===d.DIGITAL_CARD_VALUE?this.digitalCardValuesOption(t):t.type===d.COUNTRY?this.countryOption(t):t.type===d.BOOKING&&salla.url.is_page("cart")?i("salla-booking-field",{onInvalidInput:s=>this.invalidHandler(s,t),option:t,productId:t.value}):(salla.log(`Couldn't find options type(${t.type})😢`),"")}getOptionShownWhen(t){return t.visibility_condition?{"data-show-when":`options[${t.visibility_condition.option}] ${t.visibility_condition.operator} ${t.visibility_condition.value}`}:{}}getAvailableDigitalCardSKUs(t){const s=this.optionsData.find((({type:t})=>"digital-code-value"===t));if(!s)throw new Error("product-options:: No digital card options found");const i=Object.keys(t.skus_availability).filter((s=>!1===t.skus_availability[s]));this.availableDigitalCardValues=s.details.filter((t=>!Object.keys(t.skus_availability).filter((t=>i.includes(t))).length))}handleCountryOptionChange(t,s){t.stopImmediatePropagation(),this.ignoreDefaultCardValue=!0;const i=this.host.querySelector("input[data-code-value]:checked");if(i&&(i.checked=!1),!this.optionsData.find((({type:t})=>"digital-code-value"===t)))throw new Error("product-options:: No digital card options found");this.getAvailableDigitalCardSKUs(s)}getSelectedDigitalCardOptions(t){const s=t.details.find((t=>t.is_selected)),i=t.details.find((t=>!!t.is_default))||t.details[0];if(["digital-code-value","country"].includes(t.type))return s||i}async componentWillLoad(){if(salla.url.is_page("cart")&&(this.disableCardValue=!1,this.fillSelectedOptions()),this.config)try{this.optionConfig="string"==typeof this.config?JSON.parse(this.config):this.config}catch(t){console.error("Failed to parse JSON in config prop:",t)}if(this.optionsData.filter((({type:t})=>["country","digital-card-value"].includes(t))).length>0&&salla.url.is_page("cart")){const t=this.optionsData.find((t=>"country"===t.type)),s=t&&this.getSelectedDigitalCardOptions(t);s&&this.getAvailableDigitalCardSKUs(s)}return this.outOfStockText=salla.lang.get("pages.products.out_of_stock"),this.computeAvailability(),await salla.onReady(),this.canDisabled=!salla.config.get("store.settings.product.notify_options_availability")||salla.url.is_page("cart"),this.pasteHandler=this.handlePaste.bind(this),document.addEventListener("paste",this.pasteHandler),!salla.storage.get("cart.id")&&this.optionsData.some((t=>["file","image"].includes(t.type)))?salla.api.cart.getCurrentCartId(!1,"salla-product-options"):null}disconnectedCallback(){this.pasteHandler&&document.removeEventListener("paste",this.pasteHandler)}handlePaste(t){const s=t.target;if(!(Salla.helpers.isAppleDevice()&&(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement)&&s.classList.contains("s-form-control")&&this.host.contains(s)))return;t.preventDefault();const i=t.clipboardData?.getData("text")||"",a=s.selectionStart,e=s.selectionEnd,o=s.value.slice(0,a)+i+s.value.slice(e);s.value=o,s.setSelectionRange(a+i.length,a+i.length);try{s.dispatchEvent(new window.Event("change",{bubbles:!0}))}catch(t){Salla.log("Error on change")}}hideDigitalCardsOptions(t){return this.disableCardValue&&t.type===d.DIGITAL_CARD_VALUE&&!salla.url.is_page("cart")}render(){if(0!==this.optionsData?.length)return i(a,{class:{"s-product-options-wrapper":!0,"s-product-options-no-padding":this.noPadding}},i("salla-conditional-fields",null,this.optionsData.map((t=>i("div",{key:t.id,class:"s-product-options-option-container"+(t.visibility_condition||this.hideDigitalCardsOptions(t)?" hidden":""),"data-option-id":t.id,...this.getOptionShownWhen(t)},"splitter"===t.name?this.splitterOption():i("div",{class:{"s-product-options-option":!0,"s-product-options-option-booking":t.type===d.BOOKING&&salla.url.is_page("cart")},"data-option-type":t.type,"data-option-required":`${t.required}`},i("label",{htmlFor:this.generateInputId(t.id),class:"s-product-options-option-label "+(this.hideLabel(t)?"s-product-options-option-label-hidden":"")},i("b",null,t.name,t.required&&i("span",null," * ")," "),i("small",null,t.placeholder)),i("div",{class:"s-product-options-option-content "+(this.hideLabel(t)||t.type===d.BOOKING&&salla.url.is_page("cart")?"s-product-options-option-content-full-width":"")},this.getDisplayForType(t))))))))}generateUniqueKey(t){const s=this.bundleContext;let i=this.uniqueKey?`${t}-${this.uniqueKey}`:t;if(s)try{const t="string"==typeof s?JSON.parse(s):s,{sectionId:a,productId:e}=t;i=`${i}-bundle-${a}-${e}`}catch(t){}return i}generateInputId(t){return this.generateUniqueKey(`option-${t}`)}generateInputName(t){const s=this.bundleContext,i=t.toString();if(s)try{const t="string"==typeof s?JSON.parse(s):s,{sectionId:a,productId:e}=t;return`bundle[${a}][${e}][options][${i}]`}catch(t){return`options[${i}]`}return`options[${i}]`}fillSelectedOptions(){this.selectedOptions=this.optionsData.reduce(((t,s)=>{const i=(s.details??[]).filter((t=>t.is_selected)).map((t=>({...t,option_id:s.id})));return t.concat(i)}),[])}async seedSelectedOptions(){this.fillSelectedOptions(),requestAnimationFrame((()=>{this.optionsData?.filter((t=>t.type===d.MULTIPLE_OPTIONS&&t.required)).forEach((t=>this.handleRequiredMultipleOptions(t)))}))}async componentDidLoad(){if(!this.optionsData?.length)return;await Salla.hooks.registerComponent("salla-product-options",this);const t=this.optionsData.find((t=>t.type===d.DONATION))?.details?.find((t=>t.is_selected));if(t&&setTimeout((()=>{salla.event.emit("product-options::donation-changed",{id:this.productId,price:t.additional_price})}),1e3),!salla.url.is_page("cart")&&!this.isCartMode){const t=[d.SINGLE_OPTION,d.MULTIPLE_OPTIONS,d.COLOR,d.THUMBNAIL,d.DONATION,d.DIGITAL_CARD_VALUE,d.COUNTRY];this.optionsData.some((s=>t.includes(s.type)&&s.details?.some((t=>t.is_selected))))&&requestAnimationFrame((()=>{try{const t=this.host.closest("form");if(!t)return;const s=new FormData(t),i=s.get("id")||s.get("product_id");if(i&&String(i)!==String(this.productId))return;salla.product.getPrice(s)}catch(t){salla.log("Error updating price for pre-selected options:",t)}}))}}async enterCartMode(){this.isCartMode=!0,this.disableCardValue=!1,this.canDisabled=!0,this.fillSelectedOptions(),this.computeAvailability()}async enableUserInitiatedValidation(){this.userInitiatedValidation=!0}async validateAndScroll(){return await this.enableUserInitiatedValidation(),this.reportValidity()}donationOption(t,s){return i("div",{class:"s-product-options-donation-wrapper"},t.donation?.can_donate?[t.donation?i("div",{key:t.id,class:"s-product-options-donation-progress"},i("salla-progress-bar",{donation:t.donation})):"",t.details.length?[i("h4",{key:t.id},this.selectAmount),i("div",{key:t.id,class:"s-product-options-donation-options"},t.details.map(((s,a)=>i("div",{key:t.id,class:"s-product-options-donation-options-item"},i("input",{id:this.generateUniqueKey(`donation-option-${a}`),type:"radio",name:"donating_option",checked:s.is_selected,value:s.additional_price,onChange:i=>this.handleDonationOptions(i,s,"option",t)}),i("label",{htmlFor:this.generateUniqueKey(`donation-option-${a}`)},i("span",{innerHTML:salla.money(s.name)}))))),t.donation?.custom_amount_enabled?i("div",{class:"s-product-options-donation-options-item"},i("input",{id:this.generateUniqueKey("donation-option-custom"),type:"radio",name:"donating_option",value:"custom",onChange:s=>this.handleDonationOptions(s,"custom","option",t)}),i("label",{htmlFor:this.generateUniqueKey("donation-option-custom")},i("span",null," ",this.selectDonationAmount," "))):"")]:"",i("div",{key:t.id,class:{"s-product-options-donation-input-group":!0,shown:!t.details.length||t.details.length&&this.isCustomDonation}},i("input",{type:"text",id:"donating-amount",name:"donation_amount",class:"s-form-control",ref:t=>{this.donationInput=t},value:t.details.length&&t.details.some((t=>t.is_selected))?t.details.find((t=>t.is_selected)).additional_price:t.value,placeholder:t.placeholder,onInput:s=>this.handleDonationOptions(s,"custom","input",t),onBlur:s=>this.changedHandler(s,t),onInvalid:s=>this.invalidHandler(s,t)}),i("span",{class:"s-product-options-donation-amount-currency"},salla.config.currency(salla.config.get("user.currency_code")).symbol))]:this.getExpireDonationMessage(t))}fileUploader(t,s=null){return i("salla-file-upload",{...s||{},"payload-name":"file",value:t.value,"instant-upload":!0,name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,height:"120px",onAdded:s=>{this.changedHandler(s,t,!(s.detail?.file?.origin===w.LOCAL))},url:salla.cart.api.getUploadImageEndpoint(),"form-data":{cart_item_id:this.productId,product_id:this.productId},onInvalidInput:s=>this.invalidHandler(s,t),class:{"s-product-options-image-input":!0,required:t.required}},i("div",{class:"s-product-options-filepond-placeholder"},i("span",{class:"s-product-options-filepond-placeholder-icon",innerHTML:s.accept?.split(",").every((t=>t.includes("image")))?p:'\x3c!-- Generated by IcoMoon.io --\x3e\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">\n<title>file-upload</title>\n<path d="M21.333 24c0.341 0 0.683-0.131 0.943-0.391 0.521-0.521 0.521-1.364 0-1.885l-5.333-5.333c-0.123-0.123-0.271-0.22-0.433-0.288-0.327-0.135-0.693-0.135-1.019 0-0.163 0.068-0.311 0.165-0.433 0.288l-5.333 5.333c-0.521 0.521-0.521 1.364 0 1.885s1.364 0.521 1.885 0l3.057-3.057v10.115c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-10.115l3.057 3.057c0.26 0.26 0.601 0.391 0.943 0.391zM28.943 9.724l-9.333-9.333c-0.249-0.251-0.589-0.391-0.943-0.391h-12c-2.205 0-4 1.795-4 4v24c0 2.205 1.795 4 4 4h4c0.736 0 1.333-0.597 1.333-1.333s-0.597-1.333-1.333-1.333h-4c-0.735 0-1.333-0.599-1.333-1.333v-24c0-0.735 0.599-1.333 1.333-1.333h11.448l8.552 8.552v16.781c0 0.735-0.599 1.333-1.333 1.333h-4c-0.736 0-1.333 0.597-1.333 1.333s0.597 1.333 1.333 1.333h4c2.205 0 4-1.795 4-4v-17.333c0-0.353-0.14-0.693-0.391-0.943z"></path>\n</svg>\n'}),i("p",{class:"s-product-options-filepond-placeholder-text"},salla.lang.get("common.uploader.drag_and_drop")),i("span",{class:"filepond--label-action"},salla.lang.get("common.uploader.browse"))))}imageOption(t){return this.fileUploader(t,{accept:"image/png,image/jpeg,image/jpg,image/gif"})}fileOption(t){const s=t.details.map((t=>this.fileTypes[t.name])).filter(Boolean);return s?.length?this.fileUploader(t,{accept:s.join(",")}):"File types not selected."}numberOption(t){return i("input",{type:"text",value:t.value,class:"s-form-control",required:!t.visibility_condition&&t.required,id:this.generateInputId(t.id),name:this.generateInputName(t.id),placeholder:t.placeholder,onBlur:s=>this.changedHandler(s,t),onInvalid:s=>this.invalidHandler(s,t),onInput:t=>salla.helpers.inputDigitsOnly(t.target)})}splitterOption(){return i("div",{class:"s-product-options-splitter"})}textOption(t){return i("div",{class:"s-product-options-text"},i("input",{type:"text",value:t.value,maxLength:t?.length,class:"s-form-control",required:!t.visibility_condition&&t.required,id:this.generateInputId(t.id),name:this.generateInputName(t.id),placeholder:t.placeholder,onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t)}))}textareaOption(t){return i("div",{class:"s-product-options-textarea"},i("div",{class:"mt-1"},i("textarea",{rows:4,value:t.value,maxLength:t?.length,class:"s-form-control",required:!t.visibility_condition&&t.required,id:this.generateInputId(t.id),name:this.generateInputName(t.id),placeholder:t.placeholder,onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t)})))}mapOption(t){return i("salla-map",{zoom:15,lat:this.getLatLng(t.value,"lat"),lng:this.getLatLng(t.value,"lng"),name:this.generateInputName(t.id),searchable:!0,required:t.required,onInvalidInput:s=>this.invalidHandler(s,t),onSelected:s=>this.changedHandler(s,t)})}colorPickerOption(t){return i("salla-color-picker",{onSubmitted:s=>this.changedHandler(s,t),name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,onInvalidInput:s=>this.invalidHandler(s,t),color:t.value})}timeOption(t){return i("salla-datetime-picker",{noCalendar:!0,enableTime:!0,dateFormat:"h:i K",value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,name:this.generateInputName(t.id),class:"s-product-options-time-element",onInvalidInput:s=>this.invalidHandler(s,t),onPicked:s=>this.changedHandler(s,t)})}dateOption(t){return i("div",{class:"s-product-options-date-element"},i("salla-datetime-picker",{value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,minDate:new Date,name:this.generateInputName(t.id),onInvalidInput:s=>this.invalidHandler(s,t),onPicked:s=>this.changedHandler(s,t)}))}datetimeOption(t){return i("div",{class:"s-product-options-datetime-element"},i("salla-datetime-picker",{enableTime:!0,value:t.value,dateFormat:"Y-m-d G:i:K",placeholder:t.name,required:!t.visibility_condition&&t.required,name:this.generateInputName(t.id),maxDate:t.to_date_time,minDate:t.from_date_time,onInvalidInput:s=>this.invalidHandler(s,t),onPicked:s=>this.changedHandler(s,t)}))}getOptionDetailName(t,s=!0,i,a){let e;if(i&&i===d.COLOR&&(e=t.name+(s&&this.isOptionDetailOut(t)&&!salla.url.is_page("cart")&&!this.hideOutLabel?` <br/> <p> ${this.outOfStockText} </p>`:"")+(t.additional_price?` <p> (${salla.money(t.additional_price,!1)}) </p>`:"")),!e){const i=(s&&this.isOptionDetailOut(t)&&!salla.url.is_page("cart")&&!this.hideOutLabel?` - ${this.outOfStockText}`:"")+(t.additional_price?` (${salla.money(t.additional_price,!1)})`:"");if("price"===a){const s=salla.helpers.digitsOnly(t.name),a=Number(s);return s&&Number.isFinite(a)?salla.money(a,!0)+i:i}e=t.name+i}return e.replace("<i class=sicon-sar></i>",salla.config.currency()?.symbol||"ر.س")}computeAvailability(){this.availabilityMap=function(t,s,i=!0){const a={};if(!t?.length)return a;const e=t.filter((t=>t.details?.some((t=>t.skus_availability&&Object.keys(t.skus_availability).length>0)))),o=e.length<=1,n=new Set(t.filter((t=>!1===t.is_advance)).map((t=>t.id)));if(0===e.length){for(const s of t)for(const t of s.details)a[t.id]=t.is_out?"out_of_stock":"available";return a}const l=e.some((t=>t.details?.some((t=>t.skus_availability&&Object.values(t.skus_availability).some(Boolean))))),r=i&&!l;for(const t of e){const i=s.filter((s=>s.option_id!==t.id));for(const s of t.details){const t=s.skus_availability;if(!t||!Object.keys(t).length){a[s.id]=s.is_out?"out_of_stock":"available";continue}const e=Object.keys(t).map(Number),l=e.some((s=>t[s]));if(o||0===i.length){a[s.id]=!l&&r||l?"available":"out_of_stock";continue}let c=e;for(const t of i){if(n.has(t.option_id))continue;const s=new Set(Object.keys(t.skus_availability||{}).map(Number));c=c.filter((t=>s.has(t)))}if(!c.length){a[s.id]=r?"available":"impossible";continue}const d=c.some((s=>t[s]));a[s.id]=!d&&r||d?"available":"out_of_stock"}}return a}(this.optionsData||[],this.selectedOptions||[],this.productAvailable)}isOptionDetailOut(t){const s=this.availabilityMap[t.id];return void 0!==s?"available"!==s:!!t.is_out}renderInput(t,s,a,e,o,n){const l=this.generateUniqueKey(`${t}-${a.id}-${s.id}`),r=this.isOptionDetailOut(s),c=this.getOptionDetailName(s,!0,a.type,a.format),d={"s-product-options-grid-mode-span":n,"s-product-options-disabled":this.canDisabled&&r};return i("label",{class:{"s-product-options-disabled":this.canDisabled&&r,"s-product-options-option-stock-out":r}},i("input",{id:l,type:t,name:o,value:s.id,disabled:this.canDisabled&&r,required:e,checked:s.is_selected,onInvalid:t=>this.invalidHandler(t,a),onChange:t=>this.changedHandler(t,a)}),"price"===a.format?i("div",{class:d,innerHTML:c}):i("div",{class:d},c))}renderOptionDetails(t,s,i,a=!1){const e=this.generateInputName(s.id),o="radio"===t?e:`${e}[]`;return s?.details.map((e=>this.renderInput(t,e,s,i,o,a)))}renderSelect(t){return i("div",null,i("select",{id:this.generateInputId(t.id),name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,class:"s-form-control",onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t)},i("option",{value:""},t.placeholder),t?.details.map((t=>i("option",{key:t.id,value:t.id,disabled:this.canDisabled&&this.isOptionDetailOut(t),selected:t.is_selected},this.getOptionDetailName(t))))))}renderButtonStyle(t,s,a){return i("div",{class:"s-product-options-grid-mode"},this.renderOptionDetails(t,s,a,!0))}singleOption(t){return"button"===this.optionConfig?.["single-option"]?.type||t.type===d.SINGLE_OPTION&&"price"===t.format?this.renderButtonStyle("radio",t,!t.visibility_condition&&t.required):this.renderSelect(t)}multipleOptions(t){const s="button"===this.optionConfig?.["multiple-option"]?.type,a=t.required&&!t.details.some((t=>t.is_selected))&&!t.visibility_condition;return s?this.renderButtonStyle("checkbox",t,a):i("div",{class:{"s-product-options-multiple-options-wrapper":!0,required:t.required}},this.renderOptionDetails("checkbox",t,a))}radioOption(t){return this.singleOption(t)}colorOption(t){return i("fieldset",{class:"s-product-options-colors-wrapper"},t?.details.map((s=>{const a=this.isOptionDetailOut(s);return i("div",{class:{"s-product-options-colors-item":!0,"s-product-options-option-stock-out":a},key:s.id},i("input",{type:"radio",value:s.id,required:!t.visibility_condition&&t.required,checked:s.is_selected,name:this.generateInputName(t.id),disabled:this.canDisabled&&a,id:this.generateUniqueKey(`color-${this.productId}-${t.id}-${s.id}`),onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t),"data-img-id":s.option_value}),i("label",{htmlFor:this.generateUniqueKey(`color-${this.productId}-${t.id}-${s.id}`),"data-img-id":s.option_value},i("span",{style:{backgroundColor:s.color}}),i("div",{innerHTML:this.getOptionDetailName(s,!0,t.type)})))})))}thumbnailOption(t){return i("div",{class:"s-product-options-thumbnails-wrapper"},t.details.map((s=>{const a=this.isOptionDetailOut(s);return i("div",{key:s.id,class:{"s-product-options-option-stock-out":a}},i("input",{type:"radio",value:s.id,"data-itemid":s.id,required:!t.visibility_condition&&t.required,checked:s.is_selected,name:this.generateInputName(t.id),"data-img-id":s.option_value,disabled:this.canDisabled&&a,id:this.generateUniqueKey(`option_${this.productId}-${t.id}_${s.id}`),onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t)}),i("label",{htmlFor:this.generateUniqueKey(`option_${this.productId}-${t.id}_${s.id}`),"data-img-id":s.option_value,class:"go-to-slide"},i("img",{"data-src":s.image,src:s.image,title:s.name,alt:s.name}),i("span",{innerHTML:h,class:"s-product-options-thumbnails-icon"}),a?[i("small",{key:`badge-${s.id}`,class:"s-product-options-thumbnails-stock-badge"},this.outOfStockText),this.canDisabled?i("div",{key:`overlay-${s.id}`,class:"s-product-options-thumbnails-badge-overlay"}):""]:""),i("p",null,this.getOptionDetailName(s,!1)," "))})))}digitalCardValuesOption(t){return i("div",{class:"s-product-options-digital-card-wrapper"},this.availableDigitalCardValues.length>0?this.availableDigitalCardValues.map((s=>{const a=String(s.id);return i("label",{htmlFor:this.generateUniqueKey(a.toString()),key:a,class:"s-product-options-digital-card-option"},i("input",{type:"radio","data-code-value":!0,class:"s-form-control s-product-options-digital-card-input",value:s.id,name:this.generateInputName(t.id),id:this.generateUniqueKey(a.toString()),required:!t.visibility_condition&&t.required,onInvalid:s=>this.invalidHandler(s,t),...this.ignoreDefaultCardValue?{}:{defaultChecked:this.getSelectedDigitalCardOptions(t)?.id===s.id}}),i("span",null,s.name," ",salla.config?.currency()?.symbol))})):i("div",{class:"s-product-options-digital-card-out-of-stock"}))}countryOption(t){return i("div",{class:"s-product-options-digital-card-wrapper"},t.details.map((s=>{const a=this.isOptionDetailOut(s);return i("label",{htmlFor:this.generateUniqueKey(s.id.toString()),key:s.id,class:{"s-product-options-digital-card-option":!0,"s-product-options-digital-card-option-stock-out":a,"s-product-options-option-stock-out":a}},i("input",{id:this.generateUniqueKey(s.id.toString()),type:"radio",class:"s-form-control s-product-options-digital-card-input",value:s.id,name:this.generateInputName(t.id),disabled:this.canDisabled&&a,required:!t.visibility_condition&&t.required,onInvalid:s=>this.invalidHandler(s,t),onChange:s=>this.changedHandler(s,t),onClick:()=>{this.disableCardValue=!1},...salla.url.is_page("cart")?{defaultChecked:this.getSelectedDigitalCardOptions(t)?.id===s.id}:{}}),i("img",{loading:"lazy",alt:s.code,height:24,width:24,class:"s-product-options-country-flag",src:`https://cdn.assets.salla.network/prod/admin/cp/assets/flags/1x1/${String(s.code).toLocaleLowerCase()}.svg`,onError:t=>{t.currentTarget.onerror=null,t.currentTarget.src=salla.url.cdn("images/globe.svg")}}),i("span",null,s.name))})))}get host(){return e(this)}};function k(){o.defaults.headers.common.currency=salla?.config?.get?.("user.currency_code")}v.style="";var _={request:(t,s,i,a=null,e=null)=>(k(),o.request({url:s,data:i,method:t.toLowerCase(),responseType:"json"}).then(a).catch(e)),get:(t,s=null,i=null,a)=>(k(),o.get(t,{params:a}).then(s).catch(i)),post(t,s,i=null,a=null){return this.request("post",t,s,i,a)},put(t,s,i=null,a=null){return this.request("put",t,s,i,a)},delete(t,s,i=null,a=null){return this.request("delete",t,s,i,a)},requestWithSupportAjax(t,s,i="post"){return new Promise(((a,e)=>{if(!window?.isLegacyTheme)return this.request(i,t,s,(({data:t})=>a(t)),(({response:t})=>e(t)));k(),$.ajax({url:t,method:i.toUpperCase(),data:s,headers:{currency:o.defaults.headers.common.currency},async:!1,success:function({data:t}){return a(t)},error:function({response:t}){return e(t)}})}))}},S={options:[],header:"undefined"!=typeof navigator&&"undefined"!=typeof window?[navigator.platform,navigator.userAgent,navigator.appVersion,navigator.vendor,window.opera]:[],dataos:[{name:"Windows Phone",value:"Windows Phone",version:"OS"},{name:"Windows",value:"Win",version:"NT"},{name:"iPhone",value:"iPhone",version:"OS"},{name:"iPad",value:"iPad",version:"OS"},{name:"Kindle",value:"Silk",version:"Silk"},{name:"Android",value:"Android",version:"Android"},{name:"PlayBook",value:"PlayBook",version:"OS"},{name:"BlackBerry",value:"BlackBerry",version:"/"},{name:"Macintosh",value:"Mac",version:"OS X"},{name:"Linux",value:"Linux",version:"rv"},{name:"Palm",value:"Palm",version:"PalmOS"}],databrowser:[{name:"Chrome",value:"Chrome",version:"Chrome"},{name:"Firefox",value:"Firefox",version:"Firefox"},{name:"Safari",value:"Safari",version:"Version"},{name:"Internet Explorer",value:"MSIE",version:"MSIE"},{name:"Opera",value:"Opera",version:"Opera"},{name:"BlackBerry",value:"CLDC",version:"CLDC"},{name:"Mozilla",value:"Mozilla",version:"Mozilla"}],init:function(){var t=this.header.join(" ");return{os:this.matchItem(t,this.dataos),browser:this.matchItem(t,this.databrowser)}},matchItem:function(t,s){var i,a,e,o=0,n=0;for(o=0;o<s.length;o+=1)if(new RegExp(s[o].value,"i").test(t)){if(i=new RegExp(s[o].version+"[- /:;]([\\d._]+)","i"),e="",(a=t.match(i))&&a[1]&&(a=a[1]),a)for(a=a.split(/[._]+/),n=0;n<a.length;n+=1)e+=0===n?a[n]+".":a[n];else e="0";return{name:s[o].name,version:parseFloat(e)}}return{name:"unknown",version:0}}};async function C(t,s,i=!1){if(salla.logger.log("🍏 Pay: mutateShippingContact called",s,i),t.detail.requiredShippingContactFields&&0!=t.detail.requiredShippingContactFields.length)if(i){if(salla.config.isGuest()&&salla.config.get("store.features").includes("guest-checkout")){if(!(s.emailAddress&&s.givenName&&s.familyName&&s.phoneNumber)){salla.logger.warn("🍏 Pay: Guest contact fields are required",s);const i=[];return s.emailAddress||i.push(new window.ApplePayError("shippingContactInvalid","emailAddress","Email address is required")),s.phoneNumber||i.push(new window.ApplePayError("shippingContactInvalid","phoneNumber","Phone number is required")),s.givenName&&s.familyName||i.push(new window.ApplePayError("shippingContactInvalid","name","Name is required")),void t.session.completePayment({status:t.session.STATUS_INVALID_SHIPPING_CONTACT,errors:i})}await async function(t,s){return salla.logger.log("🍏 Pay: Updating guest contact",s),new Promise(((i,a)=>{_.post(t.detail.guestContactSelected.url.replace("{id}",t.id),{email:s.emailAddress||null,first_name:s.givenName||null,last_name:s.familyName||null,phone_number:s.phoneNumber||null,country_code:s.countryCode||null},(async({data:s})=>{"function"==typeof t.detail.guestContactSelected?.onSuccess&&t.detail.guestContactSelected.onSuccess(s),i(s)}),(({response:s})=>{salla.logger.warn("🍏 Pay: Failed to update guest contact via api",s),"function"==typeof t.detail.guestContactSelected?.onFailed&&t.detail.guestContactSelected.onFailed(s),a({response:s})}))}))}(t,s)}}else if(t.detail.requiredShippingContactFields.includes("postalAddress"))return _.post(t.detail.shippingContactSelected.url.replace("{id}",t.id),{country:s.country,city:s.locality,local:s.subLocality||s.administrativeArea||s.locality,description:s.subAdministrativeArea,street:s.addressLines?.join(", ")||s.administrativeArea,country_code:s.countryCode,postal_code:s.postalCode},(async({data:s})=>{if("function"==typeof t.detail.shippingContactSelected.onSuccess&&t.detail.shippingContactSelected.onSuccess(s),t.address_id=s.data.address_id,t.shipping_methods=s.data.shipping_methods,!t.shipping_methods||t.shipping_methods&&!t.shipping_methods.length)return salla.logger.warn("🍏 Pay: We dont found any supported methods",s),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]});try{await t.selectApplePayShippingMethod(t.shipping_methods[0])}catch(s){return salla.logger.warn("Failed set the shipping details to api",s),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}try{await t.recalculateTotal()}catch(s){return salla.logger.warn("🍏 Pay: Failed recalculate total",s),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}const i={newTotal:t.prepareTotal(),newLineItems:t.prepareLineItems(),newShippingMethods:t.mappingShippingMethods(t.shipping_methods)};salla.logger.log("🍏 Pay: completeShippingContactSelection",i),t.session.completeShippingContactSelection(i)}),(({response:s})=>{salla.logger.warn("🍏 Pay: Failed add address via api",s),"function"==typeof t.detail.shippingContactSelected.onFailed&&t.detail.shippingContactSelected.onFailed(s);let i=s?.data?.error?.fields,a=function(t){return Object.entries(t).filter((([t,s])=>s&&s.length>0)).map((([t,s])=>new window.ApplePayError("shippingContactInvalid",t,s[0])))}({countryCode:i?.country_code&&i.country_code.length>0?i.country_code[0]:null,locality:i?.city&&i.city.length>0?i.city[0]:null,country:i?.country&&i.country.length>0?i.country[0]:null});0===a.length&&s?.data?.error?.message&&a.push(new window.ApplePayError("shippingContactInvalid","locality",s?.data?.error?.message)),t.session.completeShippingContactSelection({newTotal:t.prepareTotal(),newLineItems:t.prepareLineItems(),status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:a})}))}"undefined"!=typeof window&&(window.Salla=window.Salla||{},window.Salla.Payments=window.Salla.Payments||{});const P="undefined"!=typeof window?{session:null,detail:null,address_id:null,shipping_methods:[],total:void 0,request:void 0,id:void 0,countryCode:null,totals:[],shippingCompany:null,init:function(){document.removeEventListener("payments::apple-pay.start-transaction",P.startSession),Salla.event.addEventListener("payments::apple-pay.start-transaction",P.startSession)},initDefault:function(){P.detail.onError||(P.detail.onError=function(t){salla.notify.error(t)}),P.detail.authorized.onFailed||(P.detail.authorized.onFailed=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleErrorResponse(t),P.onCancel({},t.data.error.message)}),P.detail.validateMerchant.onFailed||(P.detail.validateMerchant.onFailed=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleErrorResponse({response:t}),P.onCancel({},t.data.error.message)}),P.detail.authorized.onSuccess||(P.detail.authorized.onSuccess=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleAfterResponseActions(t)})},prepareLineItems:function(){return P.detail?.items?.length||(P.detail.items=[{label:salla.lang.get("pages.cart.items_total"),amount:parseFloat(P.detail.amount).toString()}]),P.detail.items},prepareTotal:function(){return{label:window.location.hostname||"Salla",amount:parseFloat(P.detail.amount).toString()}},isPhysical:()=>P.detail?.requiredShippingContactFields?.includes("postalAddress"),startSession:async function(t){P.detail=t.detail||t,salla.log("🍏 Pay: payments::apple-pay.start-transaction",P.detail),P.initDefault();let s,i=P.getApplePaySessionVersion(),a=P.detail.supportedNetworks,e=Array.isArray(a)?[...a]:Object.values(a||{});e.length||(e=["masterCard","visa"]),5!==i||e.includes("mada")||e.push("mada"),P.request={countryCode:P.detail.countryCode||"SA",supportsCouponCode:!0,couponCode:"",currencyCode:P.detail.currency||"SAR",requiredShippingContactFields:P.detail.requiredShippingContactFields?P.detail.requiredShippingContactFields:[],merchantCapabilities:["supports3DS"],supportedNetworks:e,supportedCountries:P.detail.supportedCountries||["SA"],total:P.prepareTotal(),shippingContact:P.detail.shippingContact?P.detail.shippingContact:{},shippingMethods:P.detail.shippingMethods&&P.detail.shippingMethods.length?P.mappingShippingMethods(t.detail.shippingMethods):[],lineItems:P.prepareLineItems()},salla.log("🍏 Pay: init ",P.request),P.session=new ApplePaySession(i,P.request),P.session.onshippingcontactselected=P.onShippingContactSelected,P.session.onshippingmethodselected=P.onShippingMethodSelected,P.session.onvalidatemerchant=P.onValidateMerchant,P.session.onpaymentauthorized=P.onPaymentAuthorized,P.session.oncancel=P.onCancel,P.session.oncouponcodechanged=P.onCouponCodeChanged,P.session.onpaymentmethodselected=P.onPaymentMethodSelected,"function"==typeof P.detail.onStartedSession&&(s=P.detail.onStartedSession(P.session)),s||P.session.begin()},onPaymentMethodSelected:async t=>{if(salla.logger.log("🍏 Pay: onPaymentMethodSelected",t),P.isPhysical())salla.logger.log("🍏 Pay: completePaymentMethodSelection",{newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()}),P.session.completePaymentMethodSelection({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()});else try{await P.recalculateTotal();const t={newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()};salla.logger.log("🍏 Pay: completePaymentMethodSelection",t),P.session.completePaymentMethodSelection(t)}catch(t){salla.logger.warn("🍏 Pay: Failed recalculate total",t),P.session.completePaymentMethodSelection({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems(),status:P.session.STATUS_FAILURE,errors:[new window.ApplePayError("unknown",void 0,t?.response?.data?.error?.message||t?.response?.data?.error?.code||"Failed to recalculate total")]})}},onCouponCodeChanged:t=>(Salla.event.dispatch("payments::apple-pay.coupon.change",t),_.post(P.detail.onCouponCodeChanged.url.replace("{id}",P.id),{coupon:t.couponCode,payment_method:"apple_pay"},(async({data:t})=>{"function"==typeof P.detail.onCouponCodeChanged.onSuccess&&P.detail.onCouponCodeChanged.onSuccess(t),salla.log("🍏 Pay: Coupon applied success"),await P.recalculateTotal(),P.session.completeCouponCodeChange({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()})}),(async t=>{let s=t?.response;Salla.event.dispatch("payments::apple-pay.coupon.failed",s),"function"==typeof P.detail.onCouponCodeChanged.onFailed&&P.detail.onCouponCodeChanged.onFailed(s),await P.recalculateTotal(),P.session.completeCouponCodeChange({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems(),errors:[new window.ApplePayError("couponCodeInvalid")]})}))),onCancel:(t={},s=null)=>{P.detail.onError(s||salla.lang.get("pages.checkout.payment_failed")),Salla.event.createAndDispatch("payments::apple-pay.canceled",t)},onPaymentAuthorized:async t=>{salla.logger.log("🍏 Pay: onPaymentAuthorized",t.payment);try{await C(P,t.payment.shippingContact,!0)}catch(t){salla.logger.error("🍏 Pay: Failed to update guest contact details",t);const s=t?.response||t,i=s?.data?.error?.fields||{},a=[];return i?.email&&i.email.length>0&&a.push(new window.ApplePayError("shippingContactInvalid","emailAddress",i.email[0])),i?.phone&&i.phone.length>0&&a.push(new window.ApplePayError("shippingContactInvalid","phoneNumber",i.phone[0])),i?.first_name&&i.first_name.length>0?a.push(new window.ApplePayError("shippingContactInvalid","name",i.first_name[0])):i?.last_name&&i.last_name.length>0&&a.push(new window.ApplePayError("shippingContactInvalid","name",i.last_name[0])),0===a.length&&a.push(new window.ApplePayError("shippingContactInvalid","name",s?.data?.error?.message||s?.data?.error?.code||"Invalid shipping contact details")),Salla.event.dispatch("payments::apple-pay.authorized.failed",s),"function"==typeof P.detail.authorized.onFailed&&P.detail.authorized.onFailed(s),void P.session.completePayment({status:ApplePaySession.STATUS_INVALID_SHIPPING_CONTACT,errors:a})}Salla.event.dispatch("payments::apple-pay.authorized.init",t),_.post(P.detail.authorized.url.replace("{id}",P.id),{payment_method:"apple_pay",applepay_token:JSON.stringify(t.payment)},(({data:t})=>{Salla.event.dispatch("payments::apple-pay.authorized.success",t),"function"==typeof P.detail.authorized.onSuccess&&P.detail.authorized.onSuccess(t),P.session.completePayment(ApplePaySession.STATUS_SUCCESS)}),(t=>{let s=t?.response;Salla.event.dispatch("payments::apple-pay.authorized.failed",s),"function"==typeof P.detail.authorized.onFailed&&P.detail.authorized.onFailed(s),P.session.completePayment({status:ApplePaySession.STATUS_FAILURE,errors:[new window.ApplePayError("unknown",void 0,s?.data?.error?.message||s?.data?.error?.code||"Failed to parse authorized response")]})}))},onValidateMerchant:async t=>{try{Salla.event.dispatch("payments::apple-pay.validate-merchant.init",t);const{data:s}=await _.post(P.detail.validateMerchant.url.replace("{id}",P.id),{validation_url:t.validationURL});Salla.event.dispatch("payments::apple-pay.validate-merchant.success",s);const i=t=>{P.session.completeMerchantValidation(t)};if("function"==typeof P.detail.validateMerchant.onSuccess){const t=await P.detail.validateMerchant.onSuccess(s);if(t?.redirect)return window.location=t.redirect,P.abortValidateMerchant(t)}i(s.data)}catch(t){console.error(t),P.abortValidateMerchant(t?.response)}},abortValidateMerchant:(t=null)=>{P.abortSession(),Salla.event.dispatch("payments::apple-pay.validate-merchant.failed",t),"function"==typeof P.detail.validateMerchant.onFailed&&P.detail.validateMerchant.onFailed(t)},onShippingContactSelected:async t=>{salla.logger.log("🍏 Pay: onShippingContactSelected",t.shippingContact),await C(P,t.shippingContact)},onShippingMethodSelected:async t=>{let s=t.shippingMethod.identifier.split(","),i={ship_id:s[0],private_ship_id:void 0===s[1]?null:s[1],type:void 0===s[2]?null:s[2],route_id:void 0===s[3]?null:s[3]};if(salla.logger.log("🍏 Pay: onShippingMethodSelected",{event:t,previous:P.shippingCompany,current:i}),P.shouldUpdateShippingCompany(i))try{await P.selectApplePayShippingMethod(i),await P.recalculateTotal()}catch(t){return salla.logger.warn("🍏 Pay: Failed set the shipping details to api",t),void P.session.completeShippingMethodSelection({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems(),status:P.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}salla.logger.log("🍏 Pay: completeShippingMethodSelection",{newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()}),P.session.completeShippingMethodSelection({newTotal:P.prepareTotal(),newLineItems:P.prepareLineItems()})},abortSession:()=>{P.session&&P.session.abort()},shouldUpdateShippingCompany:t=>P.shippingCompany?.ship_id!=t?.ship_id||P.shippingCompany?.private_ship_id!=t?.private_ship_id,getApplePaySessionVersion:()=>{if("sallapp"===(navigator.userAgent||navigator.vendor||window.opera))return 5;let t=S.init(),s=parseFloat(t.os.version);if("Macintosh"===t.os.name){if(s<10.142)return 1}else if(s<12.11)return 1;return 5},recalculateTotal:()=>(salla.logger.log("🍏 Pay: recalculate total"),_.get(P.detail.recalculateTotal.url.replace("{id}",P.id),(({data:t})=>{salla.logger.log("🍏 Pay: recalculate total success",t);let s=t.data.initial_data?.cart||t.data.cart,i=t.data.initial_data?.payments||t.data.payments;salla.logger.log("🍏 Pay: recalculate total success",{cart:s,payments:i}),null!=i?.gateways?.applePay?.amount?(P.detail.amount=i.gateways.applePay.amount,P.detail.currency=i.gateways.applePay.currency??P.detail.currency):P.detail.amount=i?.gateways?.applePay?.supportedMultiCurrency?s.total_in_customer_currency:s.total,P.detail.items=(s.totals||s.items).map((t=>({label:t.title,amount:"مجاني"===t.amount||"Free"===t.amount?0:t.amount.toString().replace("+","")}))),P.detail.items.pop(),P.totals=P.detail.items}),(t=>(salla.logger.warn("🍏 Pay: recalculate total failed",t),t?.response?.data?.message)))),selectApplePayShippingMethod:t=>{salla.logger.log("🍏 Pay: select shipping method ",t),P.shippingCompany=t;const s={address_id:P.address_id,company_id:t.ship_id,private_company_id:t.private_ship_id,type:t.type||void 0,route_id:t.route_id||void 0,payment_method:"apple_pay"};return _.post(P.detail.shippingMethodSelected.url.replace("{id}",P.id),s,(({data:t})=>("function"==typeof P.detail.shippingMethodSelected.onSuccess&&P.detail.shippingMethodSelected.onSuccess(t),!0)),(t=>{salla.logger.warn("🍏 Pay: Set shipping method failed",t),"function"==typeof P.detail.shippingMethodSelected.onFailed&&P.detail.shippingMethodSelected.onFailed(t);let s=t?.response?.data?.error;return s?.data?.fields?.address_id?s?.data?.fields?.address_id[0]:s?.data?.message}))},mappingShippingMethods:t=>t.map((t=>({label:t.shipping_title,amount:t.enable_free_shipping?0:t.ship_cost,detail:"",identifier:t.ship_id.toString()+(t.private_ship_id?","+t.private_ship_id.toString():"")+(t.type?","+t.type:"")+(t.route_id?","+t.route_id:"")})))}:{};"undefined"!=typeof window&&(window.SallaApplePay=P),"undefined"!=typeof window&&window.ApplePaySession?.canMakePayments()?P.init():"undefined"!=typeof document&&document.querySelectorAll("data-show-if-apple-pay-supported").forEach((t=>t.style.display="none"));const O=class{constructor(i){t(this,i),this.validationFailed=s(this,"validationFailed"),this.requireLogin=s(this,"requireLogin"),this.type="buy",this.productType="product",this.options={},this.collectedOrderOptions=[],this.optionsResolved=!1,this.applePayAmount=0,this.pendingApplePaySession=null,this.quickBuy=salla.lang.get("pages.products.buy_now"),this.handleApplePaySessionStarted=t=>!!salla.config.get("store.settings.order_options.mandatory",!1)&&!this.optionsResolved&&(this.optionsResolved=!0,this.pendingApplePaySession=t,async function(t){let s;try{s=await salla.api.withoutNotifier((()=>salla.product.api.getOrderOptions([{id:t.productId,quantity:t.quantity}])))}catch(s){return salla?.logger?.warn?.("order-options: fetch failed",s),void t.beginPendingSession()}const i=s?.data?.order_options||[];if(!i.length)return void t.beginPendingSession();t.discardPendingSession();const a=Number(t.amount)>0?Number(t.amount):Number(s?.data?.products?.[0]?.price?.amount)||0,e=function(){let t=document.querySelector("salla-order-options-modal");return t||(t=document.createElement("salla-order-options-modal"),document.body.appendChild(t)),t}();try{await e.open({orderOptions:i,basePrice:a,paymentMode:"apple-pay",onSubmit:t.onSubmit})}catch{}}({productId:this.productId,amount:Number(this.amount),quantity:this.getSelectedQuantity(),beginPendingSession:()=>{this.pendingApplePaySession?.begin(),this.pendingApplePaySession=null},discardPendingSession:()=>{this.pendingApplePaySession=null},onSubmit:(t,s)=>{this.collectedOrderOptions=t,this.applePayAmount=s,this.settlePayment()}}),!0),salla.lang.onLoaded((()=>{this.quickBuy=salla.lang.get("pages.products.buy_now")}))}quickBuyHandler(){if(salla.config.isGuest()&&!this.isGuestCheckout())return this.requireLogin.emit({productId:this.productId}),void salla.api.auth.requireLoginThen("salla-quick-buy::user.logged-in",(()=>this.quickBuyHandler()));this.validatePdpOptionsSync()&&(this.optionsResolved=!1,this.collectedOrderOptions=[],this.applePayAmount=0,this.settlePayment())}validatePdpOptionsSync(){return!!function(t){const s=document.querySelector(`salla-product-options[product-id="${t}"]`);if(!s)return!0;const i=s.querySelectorAll("[required]");let a=!0;return i.forEach((t=>{t.disabled||t.closest(".hidden")||"reportValidity"in t&&!t.reportValidity()&&(a=!1)})),a}(this.productId)||(this.validationFailed.emit({productId:this.productId}),salla.error(salla.lang.get("common.messages.required_fields")),!1)}getSelectedQuantity(){try{const t=this.host.getElementSallaData?.(),s=Number(t instanceof FormData?t.get("quantity"):t?.quantity);return Number.isFinite(s)&&s>0?s:1}catch{return 1}}async settlePayment(){let t=this.host.getElementSallaData();if(function(t,s){s.length&&(t&&"function"==typeof t.append?s.forEach(((s,i)=>{t.append(`order_options[${i}][id]`,String(s.id)),t.append(`order_options[${i}][value]`,String(s.value))})):t&&"object"==typeof t&&(t.order_options=s))}(t,this.collectedOrderOptions),!this.isApplePayActive)return salla.api.request("checkout/quick-purchase/"+this.productId,t,"post").then((t=>(t.data.redirect&&(window.location.href=t.data.redirect),t)));t.is_applepay=!0,"append"in t&&t.append("is_applepay",!0),salla.event.dispatch("payments::apple-pay.start-transaction",{amount:this.applePayAmount>0?this.applePayAmount:this.amount,currency:this.currency||salla.config.get("store.settings.buy_now.currency")||"SAR",requiredShippingContactFields:this.getRequiredShippingContactFields(),shippingMethods:this.isRequireShipping?[]:void 0,supportedNetworks:this.isLegacyBuyNowBE()?salla.config.get("store.settings.buy_now.networks"):Array.isArray(this.supportedNetworks)&&this.supportedNetworks.length?this.supportedNetworks:salla.config.get("store.settings.buy_now.supportedNetworks"),supportedCountries:this.isLegacyBuyNowBE()?salla.config.get("store.settings.buy_now.countries"):Array.isArray(this.supportedCountries)&&this.supportedCountries.length?this.supportedCountries:salla.config.get("store.settings.buy_now.supportedCountries"),countryCode:salla.config.get("store.store_country")||"SA",onStartedSession:this.handleApplePaySessionStarted,validateMerchant:{url:this.validateHost?`${this.validateHost}/checkout/applepay/validate`:salla.url.get("checkout/applepay/validate"),onSuccess:s=>this.applePayOnly&&!this.productId?this.cartId?(window.SallaApplePay.id=this.cartId,salla.log("🍏 Pay: create checkout success: with id #"+this.cartId),Promise.resolve(s)):(salla.logger.warn("🍏 Pay: trying to create applePay transaction without cartId/ProductId !"),Promise.resolve(s)):salla.api.request("checkout/quick-purchase/"+this.productId,"object"==typeof t?t:void 0,"post",{}).then((t=>t?.data?.redirect?(salla.log("🍏 Pay: create checkout success: redirect exits, go to checkout page"),window.location.href=t.data.redirect.url,t):t?.data?.id?(window.SallaApplePay.id=t.data.id,void salla.log("🍏 Pay: create checkout success: with id #"+window.SallaApplePay.id)):(salla.logger.warn("🍏 Pay: create checkout success: No id, or redirect"),t)))},authorized:{url:salla.url.get("checkout/{id}/payments/submit"),onFailed:t=>{window.SallaApplePay.onCancel({},t?.data?.error?.message||t?.data?.error?.code||salla.lang.get("pages.checkout.payment_failed"))},onSuccess:t=>{window.location.href=t.redirect.url,salla.log("🍏 Pay: authorized Success:: redirect to thank you page, order placed")}},shippingMethodSelected:this.isRequireShipping?{url:salla.url.get("checkout/{id}/shipping/details")}:void 0,shippingContactSelected:this.isRequireShipping?{url:salla.url.get("checkout/{id}/address/add")}:void 0,guestContactSelected:this.isGuestCheckout()?{url:salla.url.get("checkout/{id}/customer")}:void 0,onCouponCodeChanged:{url:salla.url.get("checkout/{id}/coupons")},recalculateTotal:{url:salla.url.get("checkout/{id}/payments/recalculate?payment_method=apple_pay")},onError:function(t){salla.log(t),salla.notify.error(t)}})}isGuestCheckout(){return salla.config.isGuest()&&salla.config.get("store.features").includes("guest-checkout")&&this.isPhysicalProduct()}getRequiredShippingContactFields(){let t=[];return this.isRequireShipping&&t.push("postalAddress"),this.isGuestCheckout()&&t.push("email","phone","name"),t}isLegacyBuyNowBE(){return null!=salla?.config?.get?.("store.settings.buy_now.multi_currency")}applyBaseCurrencyPrice(t){if(this.isLegacyBuyNowBE())return void(null!=t?.price&&(this.amount=t.price));const s=t?.base_currency_price;null!=s?.amount?(this.amount=s.amount,s?.currency&&(this.currency=s.currency)):null!=t?.price&&(this.amount=t.price,this.currency=salla.config.get("user.currency_code")||this.currency||"SAR")}componentWillLoad(){console.log("🍏 Pay: Quick Buy Component Loaded");const t="undefined"!=typeof window&&!!window.ApplePaySession?.canMakePayments?.(),s=salla?.config?.get?.("store.settings.payments")?.includes?.("apple_pay")??!0,i=salla?.config?.get?.("store.settings.is_salla_gateway",!1)??!0;this.isApplePayActive=t&&s&&i;const a=async()=>{if(this.isLegacyBuyNowBE()&&!this.currency&&salla?.config?.get&&(this.currency=salla.config.get("store.settings.buy_now.multi_currency")?salla.config.get("user.currency_code"):salla.config.get("store.settings.buy_now.currency")||"SAR"),!this.productId&&salla?.config?.get&&salla.url?.is_page&&(this.productId=salla.config.get("page.id")),this.applePayOnly||this.productId){if(this.amount&&this.isRequireShipping||!this.productId||!salla?.product?.getDetails||await salla.product.getDetails(this.productId,[]).then((t=>{this.applyBaseCurrencyPrice(t?.data),this.isRequireShipping=t?.data?.is_require_shipping||!1})).catch((t=>{salla?.logger?.warn?.("🍏 Pay: Failed load the quick buy, get the product details failed: ",t)})),"donate"===this.type&&salla?.event?.on?salla.event.on("product-options::donation-changed",(t=>{String(t.id)===String(this.productId)&&this.applyBaseCurrencyPrice(t)})):salla?.url?.is_page?.("product.single")&&salla?.product?.event?.onPriceUpdated&&salla.product.event.onPriceUpdated((t=>{this.applyBaseCurrencyPrice(t?.data)})),this.isApplePayActive=(salla?.helpers?.hasApplePay?.()??t)&&(salla?.config?.get?.("store.settings.payments")?.includes?.("apple_pay")??s)&&(salla?.config?.get?.("store.settings.is_salla_gateway",!1)??i),!document.getElementById("apple-pay-sdk")&&this.isApplePayActive){const t=document.createElement("script");t.src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js",t.setAttribute("id","apple-pay-sdk"),t.async=!0,document.body.appendChild(t)}}else salla?.logger?.warn?.("🍏 Pay: Failed load the quick buy, the product id is missing")};return new Promise((t=>{"function"==typeof salla?.onReady?salla.onReady((()=>a().then((()=>t(!0))))):a().then((()=>t(!0)))}))}render(){return i(a,{key:"c2ba63eb4fad49f80977d6f1adc836f655524933"},this.quickBuyButton())}quickBuyButton(){return i("apple-pay-button",{locale:salla?.config?.get?.("user.language_code")||"ar",onClick:()=>this.quickBuyHandler(),"data-quick-purchase":"applepay",class:"s-quick-buy-apple-pay","data-is-applepay":"1",buttonstyle:"black",type:this.type})}isPhysicalProduct(){return"product"===this.productType||"group_products"===this.productType||"food"===this.productType}get host(){return e(this)}};O.style=".s-quick-buy-button .s-button-text{display:flex}apple-pay-button{--apple-pay-button-width:100%;--apple-pay-button-height:40px;--apple-pay-button-border-radius:.75rem;--apple-pay-button-box-sizing:content-box}";export{m as salla_add_product_button,y as salla_bought_together,g as salla_product_availability,v as salla_product_options,O as salla_quick_buy}