@salla.sa/twilight-components 2.14.365 → 2.14.366

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 (253) hide show
  1. package/dist/cjs/{filepond-5FseaYGO.js → filepond-iKAI8_Ua.js} +1 -1
  2. package/dist/cjs/{filepond-plugin-file-poster-B6jRMST8.js → filepond-plugin-file-poster-DBOuyuqE.js} +1 -1
  3. package/dist/cjs/{filepond-plugin-file-validate-size-B5KYrf7Q.js → filepond-plugin-file-validate-size-3OjivJWc.js} +1 -1
  4. package/dist/cjs/{filepond-plugin-file-validate-type-D6zZbyEw.js → filepond-plugin-file-validate-type-C4wPNa1h.js} +1 -1
  5. package/dist/cjs/{filepond-plugin-image-edit-D9sIYJpS.js → filepond-plugin-image-edit-D06RnDWS.js} +1 -1
  6. package/dist/cjs/{filepond-plugin-image-exif-orientation-DCPv8T5a.js → filepond-plugin-image-exif-orientation-CbwYrnuw.js} +1 -1
  7. package/dist/cjs/{filepond-plugin-image-preview-B6ya_UMz.js → filepond-plugin-image-preview-mOmpKkFJ.js} +1 -1
  8. package/dist/cjs/{index-DaB0o62I.js → index-DL9nqubd.js} +6 -6
  9. package/dist/cjs/{index-DsLCYojB.js → index-TmWujwmX.js} +1 -1
  10. package/dist/cjs/loader.cjs.js +2 -2
  11. package/dist/cjs/salla-accordion-body_3.cjs.entry.js +1 -1
  12. package/dist/cjs/salla-accordion_6.cjs.entry.js +1 -1
  13. package/dist/cjs/salla-add-product-button_4.cjs.entry.js +1 -1
  14. package/dist/cjs/salla-advertisement.cjs.entry.js +1 -1
  15. package/dist/cjs/salla-alert_2.cjs.entry.js +1 -1
  16. package/dist/cjs/salla-app-install-alert.cjs.entry.js +1 -1
  17. package/dist/cjs/salla-apps-icons.cjs.entry.js +1 -1
  18. package/dist/cjs/salla-booking-field_7.cjs.entry.js +10 -10
  19. package/dist/cjs/salla-cart-item-offers_2.cjs.entry.js +1 -1
  20. package/dist/cjs/salla-comment-form_8.cjs.entry.js +1 -1
  21. package/dist/cjs/salla-conditional-offer.cjs.entry.js +1 -1
  22. package/dist/cjs/salla-contacts.cjs.entry.js +1 -1
  23. package/dist/cjs/salla-cookies-bar.cjs.entry.js +1 -1
  24. package/dist/cjs/salla-count-down_2.cjs.entry.js +11 -8
  25. package/dist/cjs/salla-custom-fields.cjs.entry.js +1 -1
  26. package/dist/cjs/salla-filters-widget.cjs.entry.js +1 -1
  27. package/dist/cjs/salla-filters.cjs.entry.js +1 -1
  28. package/dist/cjs/salla-gifting.cjs.entry.js +1 -1
  29. package/dist/cjs/salla-hook.cjs.entry.js +1 -1
  30. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +1 -1
  31. package/dist/cjs/salla-installment.cjs.entry.js +1 -1
  32. package/dist/cjs/salla-list-tile.cjs.entry.js +1 -1
  33. package/dist/cjs/salla-localization-modal.cjs.entry.js +1 -1
  34. package/dist/cjs/salla-login-modal.cjs.entry.js +1 -1
  35. package/dist/cjs/salla-loyalty-prize-item.cjs.entry.js +1 -1
  36. package/dist/cjs/salla-loyalty-program.cjs.entry.js +1 -1
  37. package/dist/cjs/salla-loyalty.cjs.entry.js +1 -1
  38. package/dist/cjs/salla-maintenance-alert.cjs.entry.js +1 -1
  39. package/dist/cjs/salla-menu.cjs.entry.js +1 -1
  40. package/dist/cjs/salla-metadata.cjs.entry.js +1 -1
  41. package/dist/cjs/salla-multiple-bundle-product-cart_2.cjs.entry.js +1 -1
  42. package/dist/cjs/salla-multiple-bundle-product-options-modal_2.cjs.entry.js +1 -1
  43. package/dist/cjs/salla-multiple-bundle-product.cjs.entry.js +1 -1
  44. package/dist/cjs/salla-notification-item.cjs.entry.js +1 -1
  45. package/dist/cjs/salla-notifications.cjs.entry.js +1 -1
  46. package/dist/cjs/salla-offer-modal.cjs.entry.js +1 -1
  47. package/dist/cjs/salla-offer.cjs.entry.js +248 -177
  48. package/dist/cjs/salla-order-details-multiple-bundle-product.cjs.entry.js +1 -1
  49. package/dist/cjs/salla-order-details-options.cjs.entry.js +1 -1
  50. package/dist/cjs/salla-order-details.cjs.entry.js +1 -1
  51. package/dist/cjs/salla-order-summary.cjs.entry.js +1 -1
  52. package/dist/cjs/salla-order-totals-card.cjs.entry.js +1 -1
  53. package/dist/cjs/salla-orders.cjs.entry.js +1 -1
  54. package/dist/cjs/salla-payments.cjs.entry.js +1 -1
  55. package/dist/cjs/salla-placeholder.cjs.entry.js +1 -1
  56. package/dist/cjs/salla-price-range.cjs.entry.js +1 -1
  57. package/dist/cjs/salla-product-size-guide.cjs.entry.js +1 -1
  58. package/dist/cjs/salla-products-list.cjs.entry.js +9 -3
  59. package/dist/cjs/salla-products-slider.cjs.entry.js +1 -1
  60. package/dist/cjs/salla-progress-bar.cjs.entry.js +1 -1
  61. package/dist/cjs/salla-quick-order.cjs.entry.js +1 -1
  62. package/dist/cjs/salla-rating-modal.cjs.entry.js +1 -1
  63. package/dist/cjs/salla-scopes.cjs.entry.js +1 -1
  64. package/dist/cjs/salla-search.cjs.entry.js +1 -1
  65. package/dist/cjs/salla-skeleton.cjs.entry.js +1 -1
  66. package/dist/cjs/salla-slider.cjs.entry.js +1 -1
  67. package/dist/cjs/salla-social-share.cjs.entry.js +1 -1
  68. package/dist/cjs/salla-social.cjs.entry.js +1 -1
  69. package/dist/cjs/salla-tab-content_3.cjs.entry.js +1 -1
  70. package/dist/cjs/salla-tiered-offer.cjs.entry.js +1 -1
  71. package/dist/cjs/salla-tooltip.cjs.entry.js +1 -1
  72. package/dist/cjs/salla-trust-badges.cjs.entry.js +1 -1
  73. package/dist/cjs/salla-user-menu.cjs.entry.js +1 -1
  74. package/dist/cjs/salla-user-profile.cjs.entry.js +1 -1
  75. package/dist/cjs/salla-user-settings.cjs.entry.js +1 -1
  76. package/dist/cjs/salla-verify.cjs.entry.js +1 -1
  77. package/dist/cjs/salla-wallet.cjs.entry.js +1 -1
  78. package/dist/cjs/twilight.cjs.js +2 -2
  79. package/dist/cjs/{vanilla-picker-DE9NaT9j.js → vanilla-picker-DPu_Z0gW.js} +1 -1
  80. package/dist/collection/components/salla-offer/interfaces.js +2 -0
  81. package/dist/collection/components/salla-offer/salla-offer.css +2 -25
  82. package/dist/collection/components/salla-offer/salla-offer.js +256 -181
  83. package/dist/collection/components/salla-product-card/salla-product-card.js +29 -7
  84. package/dist/collection/components/salla-products-list/salla-products-list.js +27 -2
  85. package/dist/components/index.js +2 -2
  86. package/dist/components/salla-offer.js +273 -220
  87. package/dist/components/salla-product-card2.js +11 -7
  88. package/dist/components/salla-products-list2.js +9 -2
  89. package/dist/esm/{filepond-BGPYjCAA.js → filepond-OIAu6i0O.js} +1 -1
  90. package/dist/esm/{filepond-plugin-file-poster-sd-w_Hri.js → filepond-plugin-file-poster-BMvjO1cc.js} +1 -1
  91. package/dist/esm/{filepond-plugin-file-validate-size-CQkfT5sz.js → filepond-plugin-file-validate-size-CMCs88HU.js} +1 -1
  92. package/dist/esm/{filepond-plugin-file-validate-type-Cu8nOdXD.js → filepond-plugin-file-validate-type-Bjpeuqen.js} +1 -1
  93. package/dist/esm/{filepond-plugin-image-edit-CWpBhgby.js → filepond-plugin-image-edit-Fpoh6xBj.js} +1 -1
  94. package/dist/esm/{filepond-plugin-image-exif-orientation-DbSLLg4E.js → filepond-plugin-image-exif-orientation-CPChwYPW.js} +1 -1
  95. package/dist/esm/{filepond-plugin-image-preview-DXgOkLlG.js → filepond-plugin-image-preview-pLwEytag.js} +1 -1
  96. package/dist/esm/{index-DcD0Zbyk.js → index-CV1rqKQz.js} +6 -6
  97. package/dist/esm/{index-BNB-g4_5.js → index-Cs4XvAmW.js} +1 -1
  98. package/dist/esm/loader.js +3 -3
  99. package/dist/esm/salla-accordion-body_3.entry.js +1 -1
  100. package/dist/esm/salla-accordion_6.entry.js +1 -1
  101. package/dist/esm/salla-add-product-button_4.entry.js +1 -1
  102. package/dist/esm/salla-advertisement.entry.js +1 -1
  103. package/dist/esm/salla-alert_2.entry.js +1 -1
  104. package/dist/esm/salla-app-install-alert.entry.js +1 -1
  105. package/dist/esm/salla-apps-icons.entry.js +1 -1
  106. package/dist/esm/salla-booking-field_7.entry.js +10 -10
  107. package/dist/esm/salla-cart-item-offers_2.entry.js +1 -1
  108. package/dist/esm/salla-comment-form_8.entry.js +1 -1
  109. package/dist/esm/salla-conditional-offer.entry.js +1 -1
  110. package/dist/esm/salla-contacts.entry.js +1 -1
  111. package/dist/esm/salla-cookies-bar.entry.js +1 -1
  112. package/dist/esm/salla-count-down_2.entry.js +11 -8
  113. package/dist/esm/salla-custom-fields.entry.js +1 -1
  114. package/dist/esm/salla-filters-widget.entry.js +1 -1
  115. package/dist/esm/salla-filters.entry.js +1 -1
  116. package/dist/esm/salla-gifting.entry.js +1 -1
  117. package/dist/esm/salla-hook.entry.js +1 -1
  118. package/dist/esm/salla-infinite-scroll.entry.js +1 -1
  119. package/dist/esm/salla-installment.entry.js +1 -1
  120. package/dist/esm/salla-list-tile.entry.js +1 -1
  121. package/dist/esm/salla-localization-modal.entry.js +1 -1
  122. package/dist/esm/salla-login-modal.entry.js +1 -1
  123. package/dist/esm/salla-loyalty-prize-item.entry.js +1 -1
  124. package/dist/esm/salla-loyalty-program.entry.js +1 -1
  125. package/dist/esm/salla-loyalty.entry.js +1 -1
  126. package/dist/esm/salla-maintenance-alert.entry.js +1 -1
  127. package/dist/esm/salla-menu.entry.js +1 -1
  128. package/dist/esm/salla-metadata.entry.js +1 -1
  129. package/dist/esm/salla-multiple-bundle-product-cart_2.entry.js +1 -1
  130. package/dist/esm/salla-multiple-bundle-product-options-modal_2.entry.js +1 -1
  131. package/dist/esm/salla-multiple-bundle-product.entry.js +1 -1
  132. package/dist/esm/salla-notification-item.entry.js +1 -1
  133. package/dist/esm/salla-notifications.entry.js +1 -1
  134. package/dist/esm/salla-offer-modal.entry.js +1 -1
  135. package/dist/esm/salla-offer.entry.js +248 -177
  136. package/dist/esm/salla-order-details-multiple-bundle-product.entry.js +1 -1
  137. package/dist/esm/salla-order-details-options.entry.js +1 -1
  138. package/dist/esm/salla-order-details.entry.js +1 -1
  139. package/dist/esm/salla-order-summary.entry.js +1 -1
  140. package/dist/esm/salla-order-totals-card.entry.js +1 -1
  141. package/dist/esm/salla-orders.entry.js +1 -1
  142. package/dist/esm/salla-payments.entry.js +1 -1
  143. package/dist/esm/salla-placeholder.entry.js +1 -1
  144. package/dist/esm/salla-price-range.entry.js +1 -1
  145. package/dist/esm/salla-product-size-guide.entry.js +1 -1
  146. package/dist/esm/salla-products-list.entry.js +9 -3
  147. package/dist/esm/salla-products-slider.entry.js +1 -1
  148. package/dist/esm/salla-progress-bar.entry.js +1 -1
  149. package/dist/esm/salla-quick-order.entry.js +1 -1
  150. package/dist/esm/salla-rating-modal.entry.js +1 -1
  151. package/dist/esm/salla-scopes.entry.js +1 -1
  152. package/dist/esm/salla-search.entry.js +1 -1
  153. package/dist/esm/salla-skeleton.entry.js +1 -1
  154. package/dist/esm/salla-slider.entry.js +1 -1
  155. package/dist/esm/salla-social-share.entry.js +1 -1
  156. package/dist/esm/salla-social.entry.js +1 -1
  157. package/dist/esm/salla-tab-content_3.entry.js +1 -1
  158. package/dist/esm/salla-tiered-offer.entry.js +1 -1
  159. package/dist/esm/salla-tooltip.entry.js +1 -1
  160. package/dist/esm/salla-trust-badges.entry.js +1 -1
  161. package/dist/esm/salla-user-menu.entry.js +1 -1
  162. package/dist/esm/salla-user-profile.entry.js +1 -1
  163. package/dist/esm/salla-user-settings.entry.js +1 -1
  164. package/dist/esm/salla-verify.entry.js +1 -1
  165. package/dist/esm/salla-wallet.entry.js +1 -1
  166. package/dist/esm/twilight.js +3 -3
  167. package/dist/esm/{vanilla-picker-ErWyfb2S.js → vanilla-picker-BASTfXcg.js} +1 -1
  168. package/dist/twilight/{p-eaf91b32.entry.js → p-04664fcb.entry.js} +1 -1
  169. package/dist/twilight/{p-61b073fe.entry.js → p-0c385d73.entry.js} +1 -1
  170. package/dist/twilight/{p-05edd1ae.entry.js → p-0ede455c.entry.js} +1 -1
  171. package/dist/twilight/{p-90375d86.entry.js → p-0f1d7449.entry.js} +1 -1
  172. package/dist/twilight/{p-df475039.entry.js → p-134c9d22.entry.js} +1 -1
  173. package/dist/twilight/{p-37baa677.entry.js → p-15242c87.entry.js} +1 -1
  174. package/dist/twilight/{p-0a33368c.entry.js → p-1aead6d3.entry.js} +1 -1
  175. package/dist/twilight/{p-f0234135.entry.js → p-1f6ead7d.entry.js} +1 -1
  176. package/dist/twilight/{p-05b3f2ba.entry.js → p-215ed586.entry.js} +1 -1
  177. package/dist/twilight/{p-a3b90d18.entry.js → p-22b1bd15.entry.js} +1 -1
  178. package/dist/twilight/{p-e53c695d.entry.js → p-233b89ad.entry.js} +1 -1
  179. package/dist/twilight/{p-cf4c8fc8.entry.js → p-2405c0f7.entry.js} +1 -1
  180. package/dist/twilight/{p-3f99644a.entry.js → p-2c787ba0.entry.js} +1 -1
  181. package/dist/twilight/{p-ca43a3b7.entry.js → p-2dd98664.entry.js} +1 -1
  182. package/dist/twilight/{p-281ca90e.entry.js → p-3c09b198.entry.js} +1 -1
  183. package/dist/twilight/{p-f959adcd.entry.js → p-3c418ff7.entry.js} +1 -1
  184. package/dist/twilight/{p-a916b222.entry.js → p-3c6f9112.entry.js} +1 -1
  185. package/dist/twilight/{p-4b508998.entry.js → p-3f8b06b3.entry.js} +1 -1
  186. package/dist/twilight/{p-ec61d027.entry.js → p-40ec7a33.entry.js} +1 -1
  187. package/dist/twilight/{p-3e62ea6f.entry.js → p-4d35a32b.entry.js} +1 -1
  188. package/dist/twilight/{p-794141e7.entry.js → p-50f5e38d.entry.js} +1 -1
  189. package/dist/twilight/{p-1df500d5.entry.js → p-5485978c.entry.js} +1 -1
  190. package/dist/twilight/{p-eb1ee098.entry.js → p-585a349f.entry.js} +1 -1
  191. package/dist/twilight/{p-d4135be2.entry.js → p-58f562df.entry.js} +1 -1
  192. package/dist/twilight/{p-1db6e42a.entry.js → p-594d219c.entry.js} +1 -1
  193. package/dist/twilight/{p-D94qS2bu.js → p-5mQqqwMU.js} +1 -1
  194. package/dist/twilight/{p-f1865223.entry.js → p-64ac4c0c.entry.js} +1 -1
  195. package/dist/twilight/{p-28fa2261.entry.js → p-6aecc925.entry.js} +1 -1
  196. package/dist/twilight/{p-bac8dfc6.entry.js → p-6b6e2a52.entry.js} +1 -1
  197. package/dist/twilight/{p-5b221eda.entry.js → p-6daa8bd8.entry.js} +1 -1
  198. package/dist/twilight/{p-5ca44db4.entry.js → p-6dbcd99e.entry.js} +1 -1
  199. package/dist/twilight/{p-34690dc4.entry.js → p-6f09b53e.entry.js} +1 -1
  200. package/dist/twilight/{p-a12e53fb.entry.js → p-721bb258.entry.js} +1 -1
  201. package/dist/twilight/{p-43bed278.entry.js → p-75ab49a3.entry.js} +1 -1
  202. package/dist/twilight/{p-22b8f56b.entry.js → p-7bfb9d71.entry.js} +1 -1
  203. package/dist/twilight/{p-0f9b63f1.entry.js → p-7c8c6c47.entry.js} +1 -1
  204. package/dist/twilight/{p-50b01475.entry.js → p-8c2b148a.entry.js} +1 -1
  205. package/dist/twilight/{p-2a8e49ca.entry.js → p-907b40cd.entry.js} +1 -1
  206. package/dist/twilight/{p-7e971fde.entry.js → p-90eea1a9.entry.js} +1 -1
  207. package/dist/twilight/{p-ac4d4de4.entry.js → p-95db0124.entry.js} +1 -1
  208. package/dist/twilight/{p-31e390fc.entry.js → p-965fe2b3.entry.js} +1 -1
  209. package/dist/twilight/{p-3504a127.entry.js → p-9797a552.entry.js} +1 -1
  210. package/dist/twilight/{p-27198dfa.entry.js → p-9d937a82.entry.js} +1 -1
  211. package/dist/twilight/{p-BpwFfwom.js → p-BGB1zYFQ.js} +1 -1
  212. package/dist/twilight/{p-CMeOfINj.js → p-BLbGjdAU.js} +1 -1
  213. package/dist/twilight/{p-DcD0Zbyk.js → p-CV1rqKQz.js} +1 -1
  214. package/dist/twilight/{p-DI8hZjwW.js → p-CofhuO2Z.js} +1 -1
  215. package/dist/twilight/{p-DaQtMKKH.js → p-CvLPGpFQ.js} +1 -1
  216. package/dist/twilight/{p-CfS_Im-l.js → p-D5AsuzfF.js} +1 -1
  217. package/dist/twilight/{p-r4UR1cQJ.js → p-DbzHZVd1.js} +1 -1
  218. package/dist/twilight/p-a08f5eae.entry.js +4 -0
  219. package/dist/twilight/{p-5463603e.entry.js → p-a0a6a255.entry.js} +1 -1
  220. package/dist/twilight/{p-48b8702d.entry.js → p-a386b02a.entry.js} +1 -1
  221. package/dist/twilight/{p-62eecdc3.entry.js → p-a5df57f9.entry.js} +1 -1
  222. package/dist/twilight/{p-3fbb37fc.entry.js → p-ac7f094e.entry.js} +1 -1
  223. package/dist/twilight/{p-14d02ff1.entry.js → p-af3d4d0d.entry.js} +1 -1
  224. package/dist/twilight/{p-7472ce60.entry.js → p-bb0585cc.entry.js} +1 -1
  225. package/dist/twilight/{p-9a2691e8.entry.js → p-c0ab0fc6.entry.js} +1 -1
  226. package/dist/twilight/{p-4fcd9105.entry.js → p-c3f515ae.entry.js} +1 -1
  227. package/dist/twilight/{p-ea2ebd0c.entry.js → p-c7719ce9.entry.js} +1 -1
  228. package/dist/twilight/{p-38fb50ed.entry.js → p-c90a6440.entry.js} +1 -1
  229. package/dist/twilight/{p-eb21f677.entry.js → p-cf64bb24.entry.js} +1 -1
  230. package/dist/twilight/{p-0f733d50.entry.js → p-d64027b9.entry.js} +1 -1
  231. package/dist/twilight/{p-4afcc4e1.entry.js → p-db4f5b38.entry.js} +1 -1
  232. package/dist/twilight/p-de42ef8c.entry.js +4 -0
  233. package/dist/twilight/{p-cad7741c.entry.js → p-dfc75ce2.entry.js} +1 -1
  234. package/dist/twilight/{p-84920a03.entry.js → p-e0ce2c0d.entry.js} +1 -1
  235. package/dist/twilight/{p-bd15fbda.entry.js → p-e0e61f73.entry.js} +1 -1
  236. package/dist/twilight/{p-cacb3ce1.entry.js → p-e1bf6d23.entry.js} +1 -1
  237. package/dist/twilight/{p-3bd66c8c.entry.js → p-e2c6ed54.entry.js} +1 -1
  238. package/dist/twilight/{p-2e1418d2.entry.js → p-f1156ab8.entry.js} +1 -1
  239. package/dist/twilight/{p-d9e1559a.entry.js → p-f1be81ba.entry.js} +1 -1
  240. package/dist/twilight/{p-C6smOZtR.js → p-f2v0udIe.js} +1 -1
  241. package/dist/twilight/{p-049e7629.entry.js → p-f8fb3130.entry.js} +1 -1
  242. package/dist/twilight/{p-62ab3466.entry.js → p-f9fcf183.entry.js} +1 -1
  243. package/dist/twilight/{p-5286e950.entry.js → p-fc6ddedc.entry.js} +1 -1
  244. package/dist/twilight/{p-Ctf313G7.js → p-tacIS_Xg.js} +1 -1
  245. package/dist/twilight/twilight.esm.js +1 -1
  246. package/dist/types/components/salla-offer/interfaces.d.ts +9 -7
  247. package/dist/types/components/salla-offer/salla-offer.d.ts +35 -36
  248. package/dist/types/components/salla-product-card/salla-product-card.d.ts +4 -0
  249. package/dist/types/components/salla-products-list/salla-products-list.d.ts +4 -0
  250. package/dist/types/components.d.ts +18 -2
  251. package/package.json +5 -5
  252. package/dist/twilight/p-f94c1c9a.entry.js +0 -4
  253. package/dist/twilight/p-fbc08feb.entry.js +0 -4
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{d as i}from"./p-DcD0Zbyk.js";function n(i,n){return n.forEach((function(n){n&&"string"!=typeof n&&!Array.isArray(n)&&Object.keys(n).forEach((function(t){if("default"!==t&&!(t in i)){var e=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(i,t,e.get?e:{enumerable:!0,get:function(){return n[t]}})}}))})),Object.freeze(i)}var t,e,o,E={exports:{}},r=t?E.exports:(t=1,E.exports=(e=function(i){return/^image/.test(i.type)},o=function(i){var n=i.addFilter,t=i.utils,o=t.Type,E=t.createRoute,r=t.createItemAPI,l=void 0===r?function(i){return i}:r,_=i.views.fileActionButton;n("SHOULD_REMOVE_ON_REVERT",(function(i,n){var t=n.item,o=n.query;return new Promise((function(i){var n=t.file;i(!(o("GET_ALLOW_IMAGE_EDIT")&&o("GET_IMAGE_EDIT_ALLOW_EDIT")&&e(n)))}))})),n("DID_LOAD_ITEM",(function(i,n){var t=n.query,o=n.dispatch;return new Promise((function(n,E){if(i.origin>1)n(i);else{var r=i.file;if(t("GET_ALLOW_IMAGE_EDIT")&&t("GET_IMAGE_EDIT_INSTANT_EDIT"))if(e(r)){var l=function(i,n,t){return function(e){a.shift(),e?n(i):t(i),o("KICK"),_()}},_=function(){if(a.length){var i=a[0],n=i.item;o("EDIT_ITEM",{id:n.id,handleEditorResponse:l(n,i.resolve,i.reject)})}};u({item:i,resolve:n,reject:E}),1===a.length&&_()}else n(i);else n(i)}}))})),n("DID_CREATE_ITEM",(function(i,n){var t=n.dispatch;i.extend("edit",(function(){t("EDIT_ITEM",{id:i.id})}))}));var a=[],u=function(i){return a.push(i),i};return n("CREATE_VIEW",(function(i){var n=i.is,t=i.view,o=i.query;if(o("GET_ALLOW_IMAGE_EDIT")){var r=o("GET_ALLOW_IMAGE_PREVIEW");if(n("file-info")&&!r||n("file")&&r){var a=o("GET_IMAGE_EDIT_EDITOR");if(a){a.filepondCallbackBridge||(a.outputData=!0,a.outputFile=!1,a.filepondCallbackBridge={onconfirm:a.onconfirm||function(){},oncancel:a.oncancel||function(){}});t.registerDestroyer((function(i){var n=i.root;n.ref.buttonEditItem&&n.ref.buttonEditItem.off("click",n.ref.handleEdit),n.ref.editButton&&n.ref.editButton.removeEventListener("click",n.ref.handleEdit)}));var u={EDIT_ITEM:function(i){var n=i.root,t=i.props.id,e=i.action.handleEditorResponse;a.cropAspectRatio=n.query("GET_IMAGE_CROP_ASPECT_RATIO")||a.cropAspectRatio,a.outputCanvasBackgroundColor=n.query("GET_IMAGE_TRANSFORM_CANVAS_BACKGROUND_COLOR")||a.outputCanvasBackgroundColor;var o=n.query("GET_ITEM",t);if(o){var E=o.file,r=o.getMetadata("crop"),_=o.getMetadata("resize"),u=o.getMetadata("filter")||null,f=o.getMetadata("filters")||null,I=o.getMetadata("colors")||null,c=o.getMetadata("markup")||null,T={crop:r||{center:{x:.5,y:.5},flip:{horizontal:!1,vertical:!1},zoom:1,rotation:0,aspectRatio:null},size:_?{upscale:_.upscale,mode:_.mode,width:_.size.width,height:_.size.height}:null,filter:f?f.id||f.matrix:n.query("GET_ALLOW_IMAGE_FILTER")&&n.query("GET_IMAGE_FILTER_COLOR_MATRIX")&&!I?u:null,color:I,markup:c};a.onconfirm=function(i){var n=i.data,t=n.crop,E=n.size,r=n.filter,_=n.color,u=n.colorMatrix,f=n.markup,I={};if(t&&(I.crop=t),E){var c=(o.getMetadata("resize")||{}).size,T={width:E.width,height:E.height};T.width&&T.height||!c||(T.width=c.width,T.height=c.height),(T.width||T.height)&&(I.resize={upscale:E.upscale,mode:E.mode,size:T})}f&&(I.markup=f),I.colors=_,I.filters=r,I.filter=u,o.setMetadata(I),a.filepondCallbackBridge.onconfirm(n,l(o)),e&&(a.onclose=function(){e(!0),a.onclose=null})},a.oncancel=function(){a.filepondCallbackBridge.oncancel(l(o)),e&&(a.onclose=function(){e(!1),a.onclose=null})},a.open(E,T)}},DID_LOAD_ITEM:function(i){var n=i.root,E=i.props;if(o("GET_IMAGE_EDIT_ALLOW_EDIT")){var l=E.id,a=o("GET_ITEM",l);if(a&&e(a.file))if(n.ref.handleEdit=function(i){i.stopPropagation(),n.dispatch("EDIT_ITEM",{id:l})},r){var u=t.createChildView(_,{label:"edit",icon:o("GET_IMAGE_EDIT_ICON_EDIT"),opacity:0});u.element.classList.add("filepond--action-edit-item"),u.element.dataset.align=o("GET_STYLE_IMAGE_EDIT_BUTTON_EDIT_ITEM_POSITION"),u.on("click",n.ref.handleEdit),n.ref.buttonEditItem=t.appendChildView(u)}else{var f=t.element.querySelector(".filepond--file-info-main"),I=document.createElement("button");I.className="filepond--action-edit-item-alt",I.innerHTML=o("GET_IMAGE_EDIT_ICON_EDIT")+"<span>edit</span>",I.addEventListener("click",n.ref.handleEdit),f.appendChild(I),n.ref.editButton=I}}}};r&&(u.DID_IMAGE_PREVIEW_SHOW=function(i){var n=i.root;n.ref.buttonEditItem&&(n.ref.buttonEditItem.opacity=1)}),t.registerWriter(E(u))}}}})),{options:{allowImageEdit:[!0,o.BOOLEAN],styleImageEditButtonEditItemPosition:["bottom center",o.STRING],imageEditInstantEdit:[!1,o.BOOLEAN],imageEditAllowEdit:[!0,o.BOOLEAN],imageEditIconEdit:['<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M8.5 17h1.586l7-7L15.5 8.414l-7 7V17zm-1.707-2.707l8-8a1 1 0 0 1 1.414 0l3 3a1 1 0 0 1 0 1.414l-8 8A1 1 0 0 1 10.5 19h-3a1 1 0 0 1-1-1v-3a1 1 0 0 1 .293-.707z" fill="currentColor" fill-rule="nonzero"/></svg>',o.STRING],imageEditEditor:[null,o.OBJECT]}}},"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:o})),o)),l=n({__proto__:null,default:i(r)},[r]);
4
+ import{d as i}from"./p-CV1rqKQz.js";function n(i,n){return n.forEach((function(n){n&&"string"!=typeof n&&!Array.isArray(n)&&Object.keys(n).forEach((function(t){if("default"!==t&&!(t in i)){var e=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(i,t,e.get?e:{enumerable:!0,get:function(){return n[t]}})}}))})),Object.freeze(i)}var t,e,o,E={exports:{}},r=t?E.exports:(t=1,E.exports=(e=function(i){return/^image/.test(i.type)},o=function(i){var n=i.addFilter,t=i.utils,o=t.Type,E=t.createRoute,r=t.createItemAPI,l=void 0===r?function(i){return i}:r,_=i.views.fileActionButton;n("SHOULD_REMOVE_ON_REVERT",(function(i,n){var t=n.item,o=n.query;return new Promise((function(i){var n=t.file;i(!(o("GET_ALLOW_IMAGE_EDIT")&&o("GET_IMAGE_EDIT_ALLOW_EDIT")&&e(n)))}))})),n("DID_LOAD_ITEM",(function(i,n){var t=n.query,o=n.dispatch;return new Promise((function(n,E){if(i.origin>1)n(i);else{var r=i.file;if(t("GET_ALLOW_IMAGE_EDIT")&&t("GET_IMAGE_EDIT_INSTANT_EDIT"))if(e(r)){var l=function(i,n,t){return function(e){a.shift(),e?n(i):t(i),o("KICK"),_()}},_=function(){if(a.length){var i=a[0],n=i.item;o("EDIT_ITEM",{id:n.id,handleEditorResponse:l(n,i.resolve,i.reject)})}};u({item:i,resolve:n,reject:E}),1===a.length&&_()}else n(i);else n(i)}}))})),n("DID_CREATE_ITEM",(function(i,n){var t=n.dispatch;i.extend("edit",(function(){t("EDIT_ITEM",{id:i.id})}))}));var a=[],u=function(i){return a.push(i),i};return n("CREATE_VIEW",(function(i){var n=i.is,t=i.view,o=i.query;if(o("GET_ALLOW_IMAGE_EDIT")){var r=o("GET_ALLOW_IMAGE_PREVIEW");if(n("file-info")&&!r||n("file")&&r){var a=o("GET_IMAGE_EDIT_EDITOR");if(a){a.filepondCallbackBridge||(a.outputData=!0,a.outputFile=!1,a.filepondCallbackBridge={onconfirm:a.onconfirm||function(){},oncancel:a.oncancel||function(){}});t.registerDestroyer((function(i){var n=i.root;n.ref.buttonEditItem&&n.ref.buttonEditItem.off("click",n.ref.handleEdit),n.ref.editButton&&n.ref.editButton.removeEventListener("click",n.ref.handleEdit)}));var u={EDIT_ITEM:function(i){var n=i.root,t=i.props.id,e=i.action.handleEditorResponse;a.cropAspectRatio=n.query("GET_IMAGE_CROP_ASPECT_RATIO")||a.cropAspectRatio,a.outputCanvasBackgroundColor=n.query("GET_IMAGE_TRANSFORM_CANVAS_BACKGROUND_COLOR")||a.outputCanvasBackgroundColor;var o=n.query("GET_ITEM",t);if(o){var E=o.file,r=o.getMetadata("crop"),_=o.getMetadata("resize"),u=o.getMetadata("filter")||null,f=o.getMetadata("filters")||null,I=o.getMetadata("colors")||null,c=o.getMetadata("markup")||null,T={crop:r||{center:{x:.5,y:.5},flip:{horizontal:!1,vertical:!1},zoom:1,rotation:0,aspectRatio:null},size:_?{upscale:_.upscale,mode:_.mode,width:_.size.width,height:_.size.height}:null,filter:f?f.id||f.matrix:n.query("GET_ALLOW_IMAGE_FILTER")&&n.query("GET_IMAGE_FILTER_COLOR_MATRIX")&&!I?u:null,color:I,markup:c};a.onconfirm=function(i){var n=i.data,t=n.crop,E=n.size,r=n.filter,_=n.color,u=n.colorMatrix,f=n.markup,I={};if(t&&(I.crop=t),E){var c=(o.getMetadata("resize")||{}).size,T={width:E.width,height:E.height};T.width&&T.height||!c||(T.width=c.width,T.height=c.height),(T.width||T.height)&&(I.resize={upscale:E.upscale,mode:E.mode,size:T})}f&&(I.markup=f),I.colors=_,I.filters=r,I.filter=u,o.setMetadata(I),a.filepondCallbackBridge.onconfirm(n,l(o)),e&&(a.onclose=function(){e(!0),a.onclose=null})},a.oncancel=function(){a.filepondCallbackBridge.oncancel(l(o)),e&&(a.onclose=function(){e(!1),a.onclose=null})},a.open(E,T)}},DID_LOAD_ITEM:function(i){var n=i.root,E=i.props;if(o("GET_IMAGE_EDIT_ALLOW_EDIT")){var l=E.id,a=o("GET_ITEM",l);if(a&&e(a.file))if(n.ref.handleEdit=function(i){i.stopPropagation(),n.dispatch("EDIT_ITEM",{id:l})},r){var u=t.createChildView(_,{label:"edit",icon:o("GET_IMAGE_EDIT_ICON_EDIT"),opacity:0});u.element.classList.add("filepond--action-edit-item"),u.element.dataset.align=o("GET_STYLE_IMAGE_EDIT_BUTTON_EDIT_ITEM_POSITION"),u.on("click",n.ref.handleEdit),n.ref.buttonEditItem=t.appendChildView(u)}else{var f=t.element.querySelector(".filepond--file-info-main"),I=document.createElement("button");I.className="filepond--action-edit-item-alt",I.innerHTML=o("GET_IMAGE_EDIT_ICON_EDIT")+"<span>edit</span>",I.addEventListener("click",n.ref.handleEdit),f.appendChild(I),n.ref.editButton=I}}}};r&&(u.DID_IMAGE_PREVIEW_SHOW=function(i){var n=i.root;n.ref.buttonEditItem&&(n.ref.buttonEditItem.opacity=1)}),t.registerWriter(E(u))}}}})),{options:{allowImageEdit:[!0,o.BOOLEAN],styleImageEditButtonEditItemPosition:["bottom center",o.STRING],imageEditInstantEdit:[!1,o.BOOLEAN],imageEditAllowEdit:[!0,o.BOOLEAN],imageEditIconEdit:['<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M8.5 17h1.586l7-7L15.5 8.414l-7 7V17zm-1.707-2.707l8-8a1 1 0 0 1 1.414 0l3 3a1 1 0 0 1 0 1.414l-8 8A1 1 0 0 1 10.5 19h-3a1 1 0 0 1-1-1v-3a1 1 0 0 1 .293-.707z" fill="currentColor" fill-rule="nonzero"/></svg>',o.STRING],imageEditEditor:[null,o.OBJECT]}}},"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:o})),o)),l=n({__proto__:null,default:i(r)},[r]);
5
5
  /*!
6
6
  * FilePondPluginImageEdit 1.6.3
7
7
  * Licensed under MIT, https://opensource.org/licenses/MIT/
@@ -0,0 +1,4 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ import{r as s,h as t,a as e}from"./p-CV1rqKQz.js";var o,i;!function(s){s.ProductDetail="product.single",s.Cart="cart"}(o||(o={})),function(s){s.Conditional="conditional",s.PercentageOrFixed="fixed",s.DiscountsTable="discounts_table",s.Bank="bank",s.BuyXGetY="buy_x_get_y",s.SpecialPrice="special_price",s.Percentage="percentage",s.FixedAmount="fixed_amount"}(i||(i={}));const r=class{constructor(t){s(this,t),this.productCardComponent="salla-product-card",this.offersList=[],this.canRender=!1,this.showOffer=salla.config.get("store.settings.product.show_special_offers"),this.showAllOffersModal=!1,this.showProductsModal=!1,this.selectedOfferProducts=[],this.collapsedOffers={},this.expandedCategories={},this.productsLoaded=!1,this.offer_with_price_text=salla.lang.get("pages.offer.with_price",{price:""}),this.with_discount_text=salla.lang.get("pages.products.with_a_discount"),this.product_discount_text=salla.lang.get("pages.products.discount"),this.special_offer_text=salla.lang.get("pages.products.special_offer"),this.buy_quantity_text=s=>salla.lang.get("pages.offer.buy_quantity",{quantity:s}),this.products_link_text=salla.lang.get("pages.offer.included_products","المنتجات المشمولة"),this.min_spend_text=(s,t)=>salla.lang.get("pages.offer.min_spend_amount",{amount:s,currency:t},`بحد أدنى ${s} ${t} من مبلغ الشراء`),this.min_items_text=s=>salla.lang.get("pages.offer.min_items",{items:s},`بحد أدنى ${s} منتجات`),this.product_text=salla.lang.get("common.elements.product","منتج"),salla.lang.onLoaded((()=>{this.offer_with_price_text=salla.lang.get("pages.offer.with_price"),this.with_discount_text=salla.lang.get("pages.products.with_a_discount"),this.product_discount_text=salla.lang.get("pages.products.discount"),this.special_offer_text=salla.lang.get("pages.products.special_offer"),this.buy_quantity_text(0),this.products_link_text=salla.lang.get("pages.offer.included_products","المنتجات المشمولة"),this.min_spend_text=(s,t)=>salla.lang.get("pages.offer.min_spend_amount",{amount:s,currency:t},`بحد أدنى ${s} ${t} من مبلغ الشراء`),this.min_items_text=s=>salla.lang.get("pages.offer.min_items",{items:s},`بحد أدنى ${s} منتجات`),this.product_text=salla.lang.get("common.elements.product","منتج")})),salla.onReady((()=>{this.currentPage=salla.config.get("page.slug");const s=salla.config.get("currencies")||{},t=salla.config.get("user.currency_code");this.userCurrency=s[t]||{symbol:"",code:t||"SAR",name:""}}))}async getEndpointByPageName(){return this.currentPage==o.Cart?`offers/cart/${await Salla.cart.getCurrentCartId()}`:this.currentPage==o.ProductDetail?`offers/product/${salla.config.get("page.id")}`:"offers"}emitPromotionViewed(){if(!(this.offersList.length&&this.canRender&&this.showOffer))return;const s=this.offersList.slice(0,5).map(((s,t)=>({id:s.id,name:s.title,creative:s.description||"",position:t+1})));salla.event.emit("salla::offer.promotion.viewed",s)}emitPromotionClicked(s,t=1){if(!(this.offersList.length&&this.canRender&&this.showOffer))return;const e=s||this.offersList[0];salla.event.emit("salla::offer.promotion.clicked",[{id:e.id,name:e.title,creative:e.description||"",position:t}])}componentWillLoad(){return this.hasCustomComponent=!!customElements.get(this.productCardComponent),new Promise((s=>salla.onReady(s))).then((()=>{if(this.showOffer=!salla.url.is_page("product.single")||salla.config.get("store.settings.product.show_special_offers"),!this.showOffer)throw new Error("Merchant disabled showing the offers on product page")})).then((async()=>salla.api.request(await this.getEndpointByPageName()))).then((async s=>{if(!(this.offersList=s.data).length)throw new Error("salla-offers:: There is no offers!");if(this.offersList=this.offersList.filter((s=>[i.SpecialPrice,i.Bank,i.BuyXGetY,i.DiscountsTable,i.PercentageOrFixed,i.Percentage,i.FixedAmount].includes(s.type))),!this.offersList.length)throw new Error("salla-offers:: No supported offer types found!");let t=null;this.offersList.some((s=>{const t=s.details;return"category"===t.apply_to&&t.targets||"categories"===t.apply_to&&t.targets||s.type===i.BuyXGetY&&("categories"===t.get?.source||"category"===t.get?.source)}))&&(t=(await salla.product.api.categories()).data);const e=new Set;for(const s of this.offersList){const t=s.details;"product"!==t.apply_to&&"products"!==t.apply_to||!t.targets||t.targets.forEach((s=>e.add(s))),s.type===i.BuyXGetY&&"products"===t.get?.source&&t.get?.source_value&&t.get.source_value.forEach((s=>e.add(s))),s.type!==i.BuyXGetY||"products"!==t.buy?.source&&"product"!==t.buy?.source||!t.buy?.source_value||t.buy.source_value.forEach((s=>e.add(s)))}let o={};if(e.size>0)try{const s=await salla.product.api.fetch({source:"selected",source_value:Array.from(e)});o=Object.fromEntries(s.data.map((s=>[s.id,s])))}catch(s){o={}}for(const s of this.offersList){const e=s.details;if(("category"===e.apply_to&&e.targets||"categories"===e.apply_to&&e.targets)&&t&&(e.categories=this.findCategories(t,e.targets)),"product"!==e.apply_to&&"products"!==e.apply_to||!e.targets||(e.products=e.targets.map((s=>o[s])).filter(Boolean)),s.type===i.BuyXGetY&&e.get){const s=e.get;"products"===s.source&&s.source_value?s.products=s.source_value.map((s=>o[s])).filter(Boolean):("categories"===s.source||"category"===s.source)&&t&&s.source_value&&(s.categories=this.findCategories(t,s.source_value),e.categories=s.categories)}if(s.type===i.BuyXGetY&&e.buy){const s=e.buy;"products"!==s.source&&"product"!==s.source||!s.source_value||(s.products=s.source_value.map((s=>o[s])).filter(Boolean))}}return this.offersList})).then((()=>{this.canRender=!0})).catch((s=>{salla.logger.warn(s)}))}componentDidLoad(){let s=this.host.querySelector(".s-slider-block__title-nav");s?.classList.add("s-offer-bank-payment-nav"),this.emitPromotionViewed()}findCategories(s,t){let e=[];for(const o of s)t.includes(o.id_||o.id)&&e.push(o),o.sub_categories?.length>0&&(e=e.concat(this.findCategories(o.sub_categories,t)));return e}render(){if(!this.offersList.length||!this.canRender||!this.showOffer)return null;const s=salla.lang.get("pages.offer.offers_title","عروض المنتج"),e=salla.lang.get("pages.offer.offers_subtitle","احصل على المنتج بسعر مخفض مع أفضل العروض");return[t("div",{class:"s-offer-wrapper"},t("salla-slider",{type:"carousel",id:"offers-slider","block-title":s,"block-subTitle":e,"show-controls":this.offersList.length>1},t("div",{slot:"items"},this.offersList.slice(0,5).map(((s,t)=>this.renderOfferCard(s,t+1))),this.offersList.length>5&&this.renderShowMoreCard()))),this.renderAllOffersModal(),this.renderProductsModal()]}renderShowMoreCard(){return t("div",{class:"s-offer-slide-one-fourth swiper-slide",onClick:s=>{s.preventDefault(),s.stopPropagation(),this.openAllOffersModal()}},t("div",{class:"s-offer-card s-offer-show-more-card"},t("i",{class:"sicon-add s-offer-show-more-icon"}),t("h3",{class:"s-offer-show-more-title"},salla.lang.get("pages.offer.show_more_offers","عرض المزيد من العروض"))))}openAllOffersModal(){this.showAllOffersModal=!0}closeAllOffersModal(){this.showAllOffersModal=!1}closeProductsModal(){this.showProductsModal=!1,this.selectedOfferProducts=[],this.productsLoaded=!1}handleAccordionToggle(s,t){this.collapsedOffers={...this.collapsedOffers,[s]:t}}getOfferProducts(s){const t=s.details;return t.products&&t.products.length>0?t.products:s.type===i.BuyXGetY&&t.get?.products?t.get.products:[]}renderProductsLinkForModalCard(s,e){const o=this.getOfferProducts(s);return o&&0!==o.length?t("div",{class:"s-offer-products-link",onClick:s=>{s.stopPropagation(),this.selectedOfferProducts=o,this.showProductsModal=!0}},t("span",{class:"s-offer-products-link-text"},this.products_link_text),e&&t("i",{class:"sicon-keyboard_arrow_down s-offer-products-link-icon"})):null}renderAllOffersModal(){return t("salla-drawer",{visible:this.showAllOffersModal,position:"right",width:"md","no-padding":!0,"drawer-title":salla.lang.get("pages.offer.all_offers_title","جميع العروض"),onDrawerVisibilityChanged:s=>!s.detail&&this.closeAllOffersModal()},t("div",{class:"s-offer-drawer-content"},this.offersList.map(((s,t)=>this.renderModalOfferCard(s,t+1)))))}renderProductsModal(){return t("salla-drawer",{visible:this.showProductsModal,width:"md",position:"right","no-padding":!0,"drawer-title":this.products_link_text,onDrawerVisibilityChanged:s=>!s.detail&&this.closeProductsModal()},t("div",{class:"s-offer-products-drawer-content"},this.selectedOfferProducts?.length>0?t("div",null,!this.productsLoaded&&t("div",{class:"flex items-center justify-center p-8"},t("salla-loading",{size:"24"})),t("salla-products-list",{source:"selected","source-value":JSON.stringify(this.selectedOfferProducts.map((s=>s.id))),"product-card-component":this.productCardComponent,"horizontal-cards":!0,"compact-cards":!0,includes:["images"],onProductsFetched:()=>this.productsLoaded=!0})):t("div",{class:"p-4 text-center text-gray-500"},salla.lang.get("blocks.products.no_products_found","لا توجد منتجات"))))}renderModalOfferCard(s,e=1){const o=this.getOfferProducts(s),r=o&&o.length>0,a=!1!==this.collapsedOffers[s.id];return t("div",{class:"s-offer-drawer-card"},t("div",{class:"s-offer-card-main",onClick:()=>this.emitPromotionClicked(s,e)},t("div",{class:"s-offer-card-icon"},this.getOfferIcon(s.type)),t("div",{class:"s-offer-card-content"},t("h3",{class:"s-offer-card-title",title:s.title},s.title),s.description&&t("p",{class:"s-offer-card-description"},s.description),s.type===i.DiscountsTable?t("div",{class:"s-offer-card-details"},this.renderDiscountTableOfferContent(s)):s.type===i.PercentageOrFixed||s.type===i.Percentage||s.type===i.FixedAmount?t("div",{class:"s-offer-card-details"},this.renderPercentageOrFixedOfferContent(s),this.renderOfferCategories(s)):t("div",{class:"s-offer-card-details"},this.renderOfferCategories(s)))),r&&t("salla-accordion",{collapsed:a,collapsible:!0,size:"sm",onClick:s=>s.stopPropagation(),onAccordionToggle:t=>this.handleAccordionToggle(s.id,t.detail.payload.collapsed)},t("salla-accordion-head",{collapsible:!0,collapsed:a},t("div",{slot:"title",class:"s-offer-products-thumbnails"},t("span",{class:"s-offer-products-title"},this.products_link_text,t("i",{class:`sicon-keyboard_arrow_${a?"down":"up"} s-offer-products-link-icon`})),t("div",{class:"s-offer-products-thumbnails-stack"},o.slice(0,3).map(((s,e)=>t("div",{class:"s-offer-product-thumbnail",style:{zIndex:`${e+1}`}},t("img",{src:s.thumbnail||s.image?.url||salla.url.cdn("images/s-empty.png"),alt:s.name})))),o.length>3&&t("div",{class:"s-offer-products-more-count",style:{zIndex:"7"}},"+",o.length-3)))),t("salla-accordion-body",null,t("div",{class:"s-offer-products-content"},t("salla-products-list",{source:"selected","source-value":JSON.stringify(o.map((s=>s.id))),"product-card-component":this.productCardComponent,"horizontal-cards":!0,"compact-cards":!0,includes:["images"]})))))}renderOfferCard(s,e=1){return t("div",{class:"s-offer-slide-one-fourth swiper-slide",onClick:()=>this.emitPromotionClicked(s,e)},t("div",{class:"s-offer-card"},t("div",{class:"s-offer-card-icon"},this.getOfferIcon(s.type)),t("div",{class:"s-offer-card-content"},t("h3",{class:"s-offer-card-title",title:s.title},s.title),s.description&&t("p",{class:"s-offer-card-description"},s.description),t("div",{class:"s-offer-card-details"},s.type===i.DiscountsTable?this.renderDiscountTableOfferContent(s):s.type===i.PercentageOrFixed||s.type===i.Percentage||s.type===i.FixedAmount?[this.renderPercentageOrFixedOfferContent(s),this.renderOfferCategories(s)]:this.renderOfferCategories(s),this.renderProductsLinkForModalCard(s,!1)))))}getOfferIcon(s){return t("i",{class:{[i.DiscountsTable]:"sicon-discount-calculator",[i.Bank]:"sicon-bank",[i.SpecialPrice]:"sicon-fire",[i.BuyXGetY]:"sicon-gift",[i.PercentageOrFixed]:"sicon-special-discount",[i.Percentage]:"sicon-special-discount",[i.FixedAmount]:"sicon-special-discount"}[s]||"sicon-discount"})}renderDiscountTableOfferContent(s){const e=s.details.discounts||[];return e.length?t("div",null,t("div",{class:"s-offer-card-description"},salla.lang.get("pages.offer.discount_table_subtitle","وفر اكتر بشراء منتجات أكثر")),t("table",{class:"s-offer-discount-table"},t("tbody",null,this.groupDiscountsByRows(e,3).map(((s,e)=>t("tr",{key:e},s.map(((s,e)=>t("td",{key:e},t("div",{class:"s-offer-discount-percentage"},s.percentage,"%"),t("div",{class:"s-offer-discount-condition"},this.formatDiscountCondition(s))))))))))):null}renderPercentageOrFixedOfferContent(s){const e=s.details;return e.discount_value||e.min_spend>0||e.min_items>0?t("div",{class:"s-offer-percentage-fixed-content"},e.min_spend>0&&t("div",{class:"s-offer-min-spend"},this.min_spend_text(e.min_spend,this.userCurrency?.symbol||"")),e.min_items>0&&t("div",{class:"s-offer-min-items"},this.min_items_text(e.min_items))):null}groupDiscountsByRows(s,t){const e=[];for(let o=0;o<s.length;o+=t)e.push(s.slice(o,o+t));return e}formatDiscountCondition(s){return s.discounted_amount?`${s.discounted_amount} ${this.userCurrency?.symbol||""}`:null!=s.quantity?this.buy_quantity_text(s.quantity):`1 ${this.product_text}`}renderOfferCategories(s){const e=s.details;let o=e.categories||[];if(s.type===i.BuyXGetY&&e.get?.categories&&(o=e.get.categories),!o.length)return null;const r=this.expandedCategories[s.id],a=o.length>3,l=r?o:o.slice(0,3);return t("div",{class:"s-offer-categories"},t("div",{class:"s-offer-categories-list"},l.map(((s,e)=>t("a",{key:e,class:"s-offer-category-item",href:s.url||salla.url.create("categories",s.id||s.id_)},s.name))),a&&t("span",{class:"s-offer-categories-toggle",onClick:t=>{t.preventDefault(),t.stopPropagation(),this.toggleCategoryExpansion(s.id)}},r?t("span",null,t("i",{class:"sicon-keyboard_arrow_up"})," ",salla.lang.get("common.elements.hide","إخفاء")):t("span",null,salla.lang.get("common.elements.show","عرض")," ","+"+(o.length-3)," ",t("i",{class:"sicon-keyboard_arrow_down"})))))}toggleCategoryExpansion(s){this.expandedCategories={...this.expandedCategories,[s]:!this.expandedCategories[s]}}get host(){return e(this)}};r.style=":host .s-drawer-close:where([dir=rtl],[dir=rtl] *){left:0}";export{r as salla_offer}
@@ -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,a}from"./p-DcD0Zbyk.js";import{S as c}from"./p-Ctkfc4K-.js";import{l as i}from"./p-BChI23pG.js";import{A as r}from"./p-DCZbpt2a.js";import{P as o}from"./p-DY4LZmNP.js";import{a as n}from"./p-CgtvEd63.js";const l=class{constructor(t){s(this,t),this.internalOffers=[],this.showAll=!1,this.freeLabel="",this.receivedOffer="",this.discountAmountLabel="",this.showMoreOffers="",this.icons={DiscountCouponIcon:'\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>discount-coupon</title>\n<path d="M27 28h-22c-0.552 0-1-0.448-1-1v0c0-1.657-1.343-3-3-3v0c-0.552 0-1-0.448-1-1v0-12c0-0.552 0.448-1 1-1v0c1.657 0 3-1.343 3-3v0c0-0.552 0.448-1 1-1v0h22c0.552 0 1 0.448 1 1v0c0 1.657 1.343 3 3 3v0c0.552 0 1 0.448 1 1v0 12c0 0.552-0.448 1-1 1v0c-1.657 0-3 1.343-3 3v0c0 0.552-0.448 1-1 1v0zM5.9 26h20.2c0.415-1.964 1.936-3.485 3.867-3.894l0.033-0.006v-10.2c-1.964-0.415-3.485-1.936-3.894-3.867l-0.006-0.033h-20.2c-0.415 1.964-1.936 3.485-3.867 3.894l-0.033 0.006v10.2c1.964 0.415 3.485 1.936 3.894 3.867l0.006 0.033zM20 7h2v3h-2v-3zM20 12h2v4h-2v-4zM20 18h2v4h-2v-4zM20 24h2v3h-2v-3zM9 16c-1.657 0-3-1.343-3-3s1.343-3 3-3c1.657 0 3 1.343 3 3v0c0 1.657-1.343 3-3 3v0zM9 12c-0.552 0-1 0.448-1 1s0.448 1 1 1c0.552 0 1-0.448 1-1v0c0-0.552-0.448-1-1-1v0zM15 24c-1.657 0-3-1.343-3-3s1.343-3 3-3c1.657 0 3 1.343 3 3v0c0 1.657-1.343 3-3 3v0zM15 20c-0.552 0-1 0.448-1 1s0.448 1 1 1c0.552 0 1-0.448 1-1v0c0-0.552-0.448-1-1-1v0zM7 24c-0.552-0-1-0.448-1-1 0-0.244 0.088-0.468 0.233-0.642l-0.001 0.002 10-12c0.185-0.221 0.461-0.36 0.769-0.36 0.553 0 1.001 0.448 1.001 1.001 0 0.245-0.088 0.469-0.233 0.643l0.001-0.002-10 12c-0.185 0.22-0.46 0.358-0.767 0.358-0.001 0-0.002 0-0.003 0h0z"></path>\n</svg>\n',GiftIcon:i,FireIcon:'\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>fire</title>\n<path d="M21.56 3.009c-0.052-0.047-0.116-0.065-0.173-0.103-0.073-0.048-0.143-0.1-0.223-0.132-0.083-0.033-0.165-0.047-0.252-0.063-0.081-0.016-0.16-0.035-0.243-0.035-0.089 0-0.172 0.020-0.26 0.037-0.080 0.016-0.159 0.028-0.236 0.059-0.084 0.035-0.157 0.088-0.235 0.14-0.053 0.036-0.115 0.053-0.165 0.097-0.049 0.044-0.988 0.895-2.288 2.255-2.364-2.839-4.476-4.815-4.576-4.908-0.056-0.052-0.127-0.075-0.188-0.115-0.075-0.049-0.143-0.105-0.224-0.137-0.080-0.032-0.163-0.041-0.245-0.057-0.085-0.016-0.167-0.040-0.252-0.040-0.084 0-0.163 0.023-0.245 0.039-0.087 0.016-0.172 0.025-0.253 0.059-0.080 0.032-0.147 0.087-0.22 0.135-0.063 0.041-0.133 0.064-0.189 0.116-0.453 0.423-11.092 10.408-11.092 18.095 0 7.977 4.935 13.549 12 13.549h8.667c6.673 0 11.333-5.115 11.333-12.439 0-7.052-10.013-16.167-10.44-16.552zM20.667 29.333h-7.777c-2.924 0-4.889-2.044-4.889-5.084 0-2.317 2.816-6.441 4.888-8.887 0.76 0.909 2.755 3.397 3.969 5.869 0.212 0.431 0.639 0.715 1.117 0.743 0.489 0.031 0.937-0.203 1.197-0.605 0.552-0.849 1.109-1.596 1.497-2.093 1.491 1.897 3.331 4.78 3.331 6.399 0 2.188-1.34 3.659-3.333 3.659zM26.537 27.052c0.081-0.44 0.129-0.899 0.129-1.377 0-3.269-3.713-7.847-4.46-8.735l-0.523-0.617c-0.507-0.599-1.528-0.599-2.035 0l-0.531 0.627c-0.147 0.175-0.495 0.599-0.936 1.187-1.595-2.597-3.495-4.776-3.595-4.889l-0.697-0.793c-0.507-0.577-1.499-0.577-2.004 0l-0.697 0.795c-0.6 0.684-5.856 6.803-5.856 11.001 0 0.881 0.127 1.712 0.356 2.484-1.896-1.933-3.023-4.821-3.023-8.283 0-4.915 6.073-11.997 9.329-15.255 1.001 1.008 2.692 2.789 4.368 4.927 0.243 0.309 0.609 0.496 1.001 0.509h0.048c0.376 0 0.735-0.159 0.988-0.439 0.889-0.981 1.693-1.795 2.269-2.359 3.051 2.965 8.663 9.323 8.663 13.727 0 3.171-1.031 5.769-2.796 7.491z"></path>\n</svg>\n',SpecialDiscountIcon:c,TagMoneyIcon:'\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>tag-money</title>\n<path d="M20.567 11.433c-0.521-0.521-1.364-0.521-1.885 0l-0.524 0.524c-1.28-0.819-3.091-0.681-4.191 0.419-0.631 0.631-0.976 1.468-0.976 2.359 0 0.889 0.347 1.727 0.976 2.357l0.943 0.943c0.171 0.171 0.195 0.368 0.195 0.472s-0.025 0.301-0.196 0.472c-0.169 0.169-0.367 0.195-0.471 0.195s-0.301-0.025-0.472-0.195l-2.357-2.357c-0.521-0.521-1.364-0.521-1.885 0s-0.521 1.364 0 1.885l0.944 0.941-0.472 0.472c-0.521 0.521-0.521 1.364 0 1.885 0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391l0.519-0.519c0.54 0.359 1.173 0.553 1.837 0.553 0.892 0 1.729-0.348 2.357-0.976 0.631-0.631 0.976-1.467 0.976-2.357s-0.347-1.727-0.976-2.357l-0.943-0.943c-0.26-0.26-0.26-0.684 0-0.944 0.259-0.259 0.683-0.261 0.944 0l1.885 1.887c0.521 0.521 1.364 0.521 1.885 0 0.521-0.52 0.521-1.364 0-1.885l-0.472-0.472 0.472-0.472c0.521-0.521 0.521-1.365 0.001-1.887zM28 0h-9.344c-1.059 0-2.056 0.411-2.809 1.153l-14.673 14.456c-1.56 1.56-1.561 4.097-0.001 5.657l9.56 9.56c0.755 0.755 1.76 1.172 2.828 1.173h0.003c1.068 0 2.072-0.416 2.833-1.179l14.451-14.668c0.743-0.753 1.153-1.751 1.153-2.809v-9.344c0-2.205-1.795-4-4-4zM29.333 13.344c0 0.353-0.137 0.685-0.385 0.937l-14.444 14.661c-0.252 0.252-0.587 0.391-0.941 0.391-0.001 0-0.001 0-0.001 0-0.356-0.001-0.691-0.139-0.943-0.392l-9.561-9.56c-0.52-0.52-0.52-1.365-0.005-1.88l14.667-14.449c0.253-0.248 0.585-0.385 0.937-0.385h9.344c0.736 0 1.333 0.597 1.333 1.333zM24 6.673c-0.737 0-1.333 0.604-1.333 1.341s0.596 1.333 1.333 1.333 1.333-0.596 1.333-1.333v-0.015c0-0.737-0.596-1.327-1.333-1.327z"></path>\n</svg>\n'},this.visibleOffersCount=3,this.handleCartItemUpdated=s=>{const t=s.data.cart.items.find((s=>s.id===this.itemId));t?.id===this.itemId&&(this.internalQuantity=t.quantity,this.internalOffers=t.detailed_offers||[],this.internalProductPrice=t.product_price)},this.toggleShowAll=()=>{this.showAll=!this.showAll}}async componentWillLoad(){await Salla.onReady(),await salla.lang.onLoaded((()=>{this.freeLabel=salla.lang.get("common.elements.freeExclam"),this.receivedOffer=salla.lang.get("pages.cart.received_offer"),this.discountAmountLabel=salla.lang.get("pages.cart.discount_amount"),this.showMoreOffers=salla.lang.get("pages.cart.show_more_offers")})),this.internalQuantity=this.quantity,this.internalOffers=this.parseOffers(this.offers),this.internalProductPrice=this.productPrice}componentDidLoad(){salla.event.on("cart::item.updated",(s=>this.handleCartItemUpdated(s)))}parseOffers(s){try{return"string"!=typeof s?(console.warn("Offers is not a string. Returning as-is.",s),Array.isArray(s)?s:[]):JSON.parse(s||"[]")}catch(s){return console.error("Failed to parse offers",s),[]}}get visibleOffers(){return this.internalOffers.slice(0,this.visibleOffersCount)}get hiddenOffers(){return this.internalOffers.slice(this.visibleOffersCount)}getPaidQty(s,t){return s-t.free_quantity}renderOffer(s,e){const a=this.getPaidQty(s,e);return t("div",{class:"s-cart-item-offers-box"},e.free_quantity>0&&a>0&&t("div",{class:"s-cart-item-offers-paid-free"},t("div",{class:"s-cart-item-offers-line"},salla.helpers.number(a)," × ",t("span",{innerHTML:salla.money(this.internalProductPrice)})),t("div",{class:"s-cart-item-offers-line"},salla.helpers.number(e.free_quantity)," ×",t("span",{class:"s-cart-item-offers-regular-price",innerHTML:salla.money(this.internalProductPrice)}),t("span",{class:"s-cart-item-offers-free-label"},this.freeLabel))),t("div",{class:"s-cart-item-offers-details"},t("span",{class:"s-cart-item-offers-icon",innerHTML:this.icons[e.discount_icon]||""}),t("div",null,t("p",{class:"s-cart-item-offers-title"},this.receivedOffer.replace(":offer",e.offer_name)),t("p",{class:"s-cart-item-offers-discount"},t("span",{innerHTML:this.discountAmountLabel.replace(":amount",salla.money(e.discount_amount.toFixed(2)))})))))}render(){return this.internalOffers?.length?t("div",{class:"s-cart-item-offers-container",id:`offers_list_${this.itemId}`},this.visibleOffers.map((s=>this.renderOffer(this.internalQuantity,s))),this.internalOffers?.length>this.visibleOffersCount&&t("div",{class:"s-cart-item-offers-show-more"},t("button",{class:"s-cart-item-offers-show-more-btn",onClick:this.toggleShowAll,type:"button"},t("span",{class:"s-cart-item-offers-show-more-label"},"+",this.hiddenOffers.length," ",this.showMoreOffers,t("span",{innerHTML:r,class:{"s-cart-item-offers-arrow-icon":!0,"s-cart-item-offers-arrow-open":this.showAll}})))),this.showAll&&t("div",{class:"s-cart-item-offers-collapsed",id:`offers_${this.itemId}`},this.hiddenOffers.map((s=>this.renderOffer(this.internalQuantity,s))))):null}};l.style=":host{display:block}";const h=class{constructor(t){s(this,t),this.cartSummaryCount=salla.storage.get("cart.summary.count")||0,this.cartSummaryTotal=salla.storage.get("cart.summary.total")||0,this.cartLabel="ar"===salla.config.get("user.language_code")?"السلة":"Cart",salla.cart.event.onUpdated((s=>{this.cartSummaryCount=s.count||0,this.cartSummaryTotal=s.total||0}))}async animateToCart(s){if(document.querySelectorAll(".s-cart-thumb").forEach((s=>s.remove())),!s?.src)return void salla.log("Failed to get the img element");let t=this.host.querySelector("#s-cart-icon"),e=t.getBoundingClientRect(),a=e.top+window.scrollY,c=e.left+window.scrollX,i=s.getBoundingClientRect(),r=s.offsetWidth+"px",o=s.offsetHeight+"px",l=i.top,h=i.left,f=document.createElement("img");f.src=s.getAttribute("src"),f.className="s-cart-thumb",f.setAttribute("style","object-fit:cover; width:"+r+"; height:"+o+"; top:"+l+"px; left:"+h+"px;z-index:99999999; "),document.body.append(f);let d=document.querySelector(".s-cart-thumb");t.classList.remove("animated","rubberBand"),(new n.timeline).add({targets:d,width:[150,30],height:[150,30],top:[l,window.scrollY>0?a-window.scrollY-40:a-40],left:[h,c],borderRadius:["20%","50%"],easing:"easeOutExpo",duration:1200},"+=200").add({targets:d,width:[30,0],height:[30,0],opacity:[1,0],easing:"easeOutExpo",top:[window.scrollY>0?a-window.scrollY-40:a-40,window.scrollY>0?a-window.scrollY+10:a+10],left:[c,c+10]},"-=500").add({complete:function(){t.classList.add("animated","rubberBand"),d.remove()}},"-=1700")}componentWillLoad(){return new Promise((s=>salla.onReady(s)))}getCartLink(){let s=salla.url.get("cart");const t=salla.config.get("store.scope",salla.storage.get("scope"));if(t&&t.id)try{const e=new URL(s);return e.searchParams.set("scope",t.id),e.toString()}catch(e){const a=s.includes("?")?"&":"?";return`${s}${a}scope=${encodeURIComponent(t.id)}`}return s}render(){return t(e,{key:"f22c9fc5b6ad2c7b7f026a7b9ad2510a3c27c281"},t("a",{key:"b329fa512839a8dd6d8a1b175e254308c22a9fb0",class:"s-cart-summary-wrapper",href:this.getCartLink()},t("div",{key:"fbe89bcca0f38393a23016cf45358d38a53e5f8f",id:"s-cart-icon"},t("slot",{key:"f2668edcc903f0a8fd112c6449d8cda9113e2ffa",name:"icon"},t("i",{key:"f4a2c742903302b2676c4628961a90a7bcfe43eb",class:"s-cart-summary-icon",innerHTML:o}))),t("span",{key:"49678efeaae684b2da2c238382b014390516db8d",class:"s-cart-summary-count"},salla.helpers.number(this.cartSummaryCount)),t("p",{key:"9a399f82fc90e6c974022b65ea75c3f556f67221",class:"s-cart-summary-content"},this.showCartLabel&&t("span",{key:"879348fe4998f2eb3f26e4bebe486877bc733bff",class:"s-cart-summary-label"},this.cartLabel),t("b",{key:"237d3ee6ebed4203752b6f5c4e2cb962c03cc087",class:"s-cart-summary-total",innerHTML:salla.money(this.cartSummaryTotal)}))))}get host(){return a(this)}};h.style="";export{l as salla_cart_item_offers,h as salla_cart_summary}
4
+ import{r as s,h as t,H as e,a}from"./p-CV1rqKQz.js";import{S as c}from"./p-Ctkfc4K-.js";import{l as i}from"./p-BChI23pG.js";import{A as r}from"./p-DCZbpt2a.js";import{P as o}from"./p-DY4LZmNP.js";import{a as n}from"./p-CgtvEd63.js";const l=class{constructor(t){s(this,t),this.internalOffers=[],this.showAll=!1,this.freeLabel="",this.receivedOffer="",this.discountAmountLabel="",this.showMoreOffers="",this.icons={DiscountCouponIcon:'\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>discount-coupon</title>\n<path d="M27 28h-22c-0.552 0-1-0.448-1-1v0c0-1.657-1.343-3-3-3v0c-0.552 0-1-0.448-1-1v0-12c0-0.552 0.448-1 1-1v0c1.657 0 3-1.343 3-3v0c0-0.552 0.448-1 1-1v0h22c0.552 0 1 0.448 1 1v0c0 1.657 1.343 3 3 3v0c0.552 0 1 0.448 1 1v0 12c0 0.552-0.448 1-1 1v0c-1.657 0-3 1.343-3 3v0c0 0.552-0.448 1-1 1v0zM5.9 26h20.2c0.415-1.964 1.936-3.485 3.867-3.894l0.033-0.006v-10.2c-1.964-0.415-3.485-1.936-3.894-3.867l-0.006-0.033h-20.2c-0.415 1.964-1.936 3.485-3.867 3.894l-0.033 0.006v10.2c1.964 0.415 3.485 1.936 3.894 3.867l0.006 0.033zM20 7h2v3h-2v-3zM20 12h2v4h-2v-4zM20 18h2v4h-2v-4zM20 24h2v3h-2v-3zM9 16c-1.657 0-3-1.343-3-3s1.343-3 3-3c1.657 0 3 1.343 3 3v0c0 1.657-1.343 3-3 3v0zM9 12c-0.552 0-1 0.448-1 1s0.448 1 1 1c0.552 0 1-0.448 1-1v0c0-0.552-0.448-1-1-1v0zM15 24c-1.657 0-3-1.343-3-3s1.343-3 3-3c1.657 0 3 1.343 3 3v0c0 1.657-1.343 3-3 3v0zM15 20c-0.552 0-1 0.448-1 1s0.448 1 1 1c0.552 0 1-0.448 1-1v0c0-0.552-0.448-1-1-1v0zM7 24c-0.552-0-1-0.448-1-1 0-0.244 0.088-0.468 0.233-0.642l-0.001 0.002 10-12c0.185-0.221 0.461-0.36 0.769-0.36 0.553 0 1.001 0.448 1.001 1.001 0 0.245-0.088 0.469-0.233 0.643l0.001-0.002-10 12c-0.185 0.22-0.46 0.358-0.767 0.358-0.001 0-0.002 0-0.003 0h0z"></path>\n</svg>\n',GiftIcon:i,FireIcon:'\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>fire</title>\n<path d="M21.56 3.009c-0.052-0.047-0.116-0.065-0.173-0.103-0.073-0.048-0.143-0.1-0.223-0.132-0.083-0.033-0.165-0.047-0.252-0.063-0.081-0.016-0.16-0.035-0.243-0.035-0.089 0-0.172 0.020-0.26 0.037-0.080 0.016-0.159 0.028-0.236 0.059-0.084 0.035-0.157 0.088-0.235 0.14-0.053 0.036-0.115 0.053-0.165 0.097-0.049 0.044-0.988 0.895-2.288 2.255-2.364-2.839-4.476-4.815-4.576-4.908-0.056-0.052-0.127-0.075-0.188-0.115-0.075-0.049-0.143-0.105-0.224-0.137-0.080-0.032-0.163-0.041-0.245-0.057-0.085-0.016-0.167-0.040-0.252-0.040-0.084 0-0.163 0.023-0.245 0.039-0.087 0.016-0.172 0.025-0.253 0.059-0.080 0.032-0.147 0.087-0.22 0.135-0.063 0.041-0.133 0.064-0.189 0.116-0.453 0.423-11.092 10.408-11.092 18.095 0 7.977 4.935 13.549 12 13.549h8.667c6.673 0 11.333-5.115 11.333-12.439 0-7.052-10.013-16.167-10.44-16.552zM20.667 29.333h-7.777c-2.924 0-4.889-2.044-4.889-5.084 0-2.317 2.816-6.441 4.888-8.887 0.76 0.909 2.755 3.397 3.969 5.869 0.212 0.431 0.639 0.715 1.117 0.743 0.489 0.031 0.937-0.203 1.197-0.605 0.552-0.849 1.109-1.596 1.497-2.093 1.491 1.897 3.331 4.78 3.331 6.399 0 2.188-1.34 3.659-3.333 3.659zM26.537 27.052c0.081-0.44 0.129-0.899 0.129-1.377 0-3.269-3.713-7.847-4.46-8.735l-0.523-0.617c-0.507-0.599-1.528-0.599-2.035 0l-0.531 0.627c-0.147 0.175-0.495 0.599-0.936 1.187-1.595-2.597-3.495-4.776-3.595-4.889l-0.697-0.793c-0.507-0.577-1.499-0.577-2.004 0l-0.697 0.795c-0.6 0.684-5.856 6.803-5.856 11.001 0 0.881 0.127 1.712 0.356 2.484-1.896-1.933-3.023-4.821-3.023-8.283 0-4.915 6.073-11.997 9.329-15.255 1.001 1.008 2.692 2.789 4.368 4.927 0.243 0.309 0.609 0.496 1.001 0.509h0.048c0.376 0 0.735-0.159 0.988-0.439 0.889-0.981 1.693-1.795 2.269-2.359 3.051 2.965 8.663 9.323 8.663 13.727 0 3.171-1.031 5.769-2.796 7.491z"></path>\n</svg>\n',SpecialDiscountIcon:c,TagMoneyIcon:'\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>tag-money</title>\n<path d="M20.567 11.433c-0.521-0.521-1.364-0.521-1.885 0l-0.524 0.524c-1.28-0.819-3.091-0.681-4.191 0.419-0.631 0.631-0.976 1.468-0.976 2.359 0 0.889 0.347 1.727 0.976 2.357l0.943 0.943c0.171 0.171 0.195 0.368 0.195 0.472s-0.025 0.301-0.196 0.472c-0.169 0.169-0.367 0.195-0.471 0.195s-0.301-0.025-0.472-0.195l-2.357-2.357c-0.521-0.521-1.364-0.521-1.885 0s-0.521 1.364 0 1.885l0.944 0.941-0.472 0.472c-0.521 0.521-0.521 1.364 0 1.885 0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391l0.519-0.519c0.54 0.359 1.173 0.553 1.837 0.553 0.892 0 1.729-0.348 2.357-0.976 0.631-0.631 0.976-1.467 0.976-2.357s-0.347-1.727-0.976-2.357l-0.943-0.943c-0.26-0.26-0.26-0.684 0-0.944 0.259-0.259 0.683-0.261 0.944 0l1.885 1.887c0.521 0.521 1.364 0.521 1.885 0 0.521-0.52 0.521-1.364 0-1.885l-0.472-0.472 0.472-0.472c0.521-0.521 0.521-1.365 0.001-1.887zM28 0h-9.344c-1.059 0-2.056 0.411-2.809 1.153l-14.673 14.456c-1.56 1.56-1.561 4.097-0.001 5.657l9.56 9.56c0.755 0.755 1.76 1.172 2.828 1.173h0.003c1.068 0 2.072-0.416 2.833-1.179l14.451-14.668c0.743-0.753 1.153-1.751 1.153-2.809v-9.344c0-2.205-1.795-4-4-4zM29.333 13.344c0 0.353-0.137 0.685-0.385 0.937l-14.444 14.661c-0.252 0.252-0.587 0.391-0.941 0.391-0.001 0-0.001 0-0.001 0-0.356-0.001-0.691-0.139-0.943-0.392l-9.561-9.56c-0.52-0.52-0.52-1.365-0.005-1.88l14.667-14.449c0.253-0.248 0.585-0.385 0.937-0.385h9.344c0.736 0 1.333 0.597 1.333 1.333zM24 6.673c-0.737 0-1.333 0.604-1.333 1.341s0.596 1.333 1.333 1.333 1.333-0.596 1.333-1.333v-0.015c0-0.737-0.596-1.327-1.333-1.327z"></path>\n</svg>\n'},this.visibleOffersCount=3,this.handleCartItemUpdated=s=>{const t=s.data.cart.items.find((s=>s.id===this.itemId));t?.id===this.itemId&&(this.internalQuantity=t.quantity,this.internalOffers=t.detailed_offers||[],this.internalProductPrice=t.product_price)},this.toggleShowAll=()=>{this.showAll=!this.showAll}}async componentWillLoad(){await Salla.onReady(),await salla.lang.onLoaded((()=>{this.freeLabel=salla.lang.get("common.elements.freeExclam"),this.receivedOffer=salla.lang.get("pages.cart.received_offer"),this.discountAmountLabel=salla.lang.get("pages.cart.discount_amount"),this.showMoreOffers=salla.lang.get("pages.cart.show_more_offers")})),this.internalQuantity=this.quantity,this.internalOffers=this.parseOffers(this.offers),this.internalProductPrice=this.productPrice}componentDidLoad(){salla.event.on("cart::item.updated",(s=>this.handleCartItemUpdated(s)))}parseOffers(s){try{return"string"!=typeof s?(console.warn("Offers is not a string. Returning as-is.",s),Array.isArray(s)?s:[]):JSON.parse(s||"[]")}catch(s){return console.error("Failed to parse offers",s),[]}}get visibleOffers(){return this.internalOffers.slice(0,this.visibleOffersCount)}get hiddenOffers(){return this.internalOffers.slice(this.visibleOffersCount)}getPaidQty(s,t){return s-t.free_quantity}renderOffer(s,e){const a=this.getPaidQty(s,e);return t("div",{class:"s-cart-item-offers-box"},e.free_quantity>0&&a>0&&t("div",{class:"s-cart-item-offers-paid-free"},t("div",{class:"s-cart-item-offers-line"},salla.helpers.number(a)," × ",t("span",{innerHTML:salla.money(this.internalProductPrice)})),t("div",{class:"s-cart-item-offers-line"},salla.helpers.number(e.free_quantity)," ×",t("span",{class:"s-cart-item-offers-regular-price",innerHTML:salla.money(this.internalProductPrice)}),t("span",{class:"s-cart-item-offers-free-label"},this.freeLabel))),t("div",{class:"s-cart-item-offers-details"},t("span",{class:"s-cart-item-offers-icon",innerHTML:this.icons[e.discount_icon]||""}),t("div",null,t("p",{class:"s-cart-item-offers-title"},this.receivedOffer.replace(":offer",e.offer_name)),t("p",{class:"s-cart-item-offers-discount"},t("span",{innerHTML:this.discountAmountLabel.replace(":amount",salla.money(e.discount_amount.toFixed(2)))})))))}render(){return this.internalOffers?.length?t("div",{class:"s-cart-item-offers-container",id:`offers_list_${this.itemId}`},this.visibleOffers.map((s=>this.renderOffer(this.internalQuantity,s))),this.internalOffers?.length>this.visibleOffersCount&&t("div",{class:"s-cart-item-offers-show-more"},t("button",{class:"s-cart-item-offers-show-more-btn",onClick:this.toggleShowAll,type:"button"},t("span",{class:"s-cart-item-offers-show-more-label"},"+",this.hiddenOffers.length," ",this.showMoreOffers,t("span",{innerHTML:r,class:{"s-cart-item-offers-arrow-icon":!0,"s-cart-item-offers-arrow-open":this.showAll}})))),this.showAll&&t("div",{class:"s-cart-item-offers-collapsed",id:`offers_${this.itemId}`},this.hiddenOffers.map((s=>this.renderOffer(this.internalQuantity,s))))):null}};l.style=":host{display:block}";const h=class{constructor(t){s(this,t),this.cartSummaryCount=salla.storage.get("cart.summary.count")||0,this.cartSummaryTotal=salla.storage.get("cart.summary.total")||0,this.cartLabel="ar"===salla.config.get("user.language_code")?"السلة":"Cart",salla.cart.event.onUpdated((s=>{this.cartSummaryCount=s.count||0,this.cartSummaryTotal=s.total||0}))}async animateToCart(s){if(document.querySelectorAll(".s-cart-thumb").forEach((s=>s.remove())),!s?.src)return void salla.log("Failed to get the img element");let t=this.host.querySelector("#s-cart-icon"),e=t.getBoundingClientRect(),a=e.top+window.scrollY,c=e.left+window.scrollX,i=s.getBoundingClientRect(),r=s.offsetWidth+"px",o=s.offsetHeight+"px",l=i.top,h=i.left,f=document.createElement("img");f.src=s.getAttribute("src"),f.className="s-cart-thumb",f.setAttribute("style","object-fit:cover; width:"+r+"; height:"+o+"; top:"+l+"px; left:"+h+"px;z-index:99999999; "),document.body.append(f);let d=document.querySelector(".s-cart-thumb");t.classList.remove("animated","rubberBand"),(new n.timeline).add({targets:d,width:[150,30],height:[150,30],top:[l,window.scrollY>0?a-window.scrollY-40:a-40],left:[h,c],borderRadius:["20%","50%"],easing:"easeOutExpo",duration:1200},"+=200").add({targets:d,width:[30,0],height:[30,0],opacity:[1,0],easing:"easeOutExpo",top:[window.scrollY>0?a-window.scrollY-40:a-40,window.scrollY>0?a-window.scrollY+10:a+10],left:[c,c+10]},"-=500").add({complete:function(){t.classList.add("animated","rubberBand"),d.remove()}},"-=1700")}componentWillLoad(){return new Promise((s=>salla.onReady(s)))}getCartLink(){let s=salla.url.get("cart");const t=salla.config.get("store.scope",salla.storage.get("scope"));if(t&&t.id)try{const e=new URL(s);return e.searchParams.set("scope",t.id),e.toString()}catch(e){const a=s.includes("?")?"&":"?";return`${s}${a}scope=${encodeURIComponent(t.id)}`}return s}render(){return t(e,{key:"f22c9fc5b6ad2c7b7f026a7b9ad2510a3c27c281"},t("a",{key:"b329fa512839a8dd6d8a1b175e254308c22a9fb0",class:"s-cart-summary-wrapper",href:this.getCartLink()},t("div",{key:"fbe89bcca0f38393a23016cf45358d38a53e5f8f",id:"s-cart-icon"},t("slot",{key:"f2668edcc903f0a8fd112c6449d8cda9113e2ffa",name:"icon"},t("i",{key:"f4a2c742903302b2676c4628961a90a7bcfe43eb",class:"s-cart-summary-icon",innerHTML:o}))),t("span",{key:"49678efeaae684b2da2c238382b014390516db8d",class:"s-cart-summary-count"},salla.helpers.number(this.cartSummaryCount)),t("p",{key:"9a399f82fc90e6c974022b65ea75c3f556f67221",class:"s-cart-summary-content"},this.showCartLabel&&t("span",{key:"879348fe4998f2eb3f26e4bebe486877bc733bff",class:"s-cart-summary-label"},this.cartLabel),t("b",{key:"237d3ee6ebed4203752b6f5c4e2cb962c03cc087",class:"s-cart-summary-total",innerHTML:salla.money(this.cartSummaryTotal)}))))}get host(){return a(this)}};h.style="";export{l as salla_cart_item_offers,h as salla_cart_summary}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as t,c as a,h as s,H as i,a as e,e as l}from"./p-DcD0Zbyk.js";import{P as o}from"./p-DY4LZmNP.js";import{B as n}from"./p-D3mWkc-3.js";import{H as p}from"./p-CHf8XdiS.js";import{i as r}from"./p-BsXh13x8.js";import{C as d}from"./p-C6jIkM-X.js";import"./p-CgtvEd63.js";const c=class{constructor(s){t(this,s),this.success=a(this,"success"),this.failed=a(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.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?o: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 a=document.querySelector(`salla-product-options[product-id="${this.productId}"]`);return a&&"function"==typeof a.validateAndScroll?a.validateAndScroll().then((async t=>{const a={isValid:t,component:this};if(await salla.hooks.call("salla-add-product-button","validate",a),a.isValid)return this._proceedAddToCart();this.btn?.enable()})).catch((()=>{this.btn?.enable()})):this._proceedAddToCart()}async _proceedAddToCart(){const t=Object.entries({id:this.productId,donation_amount:this.donatingAmount,quantity:this.quantity,endpoint:"quickAdd"}).reduce(((t,[a,s])=>s?(t[a]=s,t):t),{});return salla.cart.addItem(t).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}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 s("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"},s("div",{slot:"widget-label",class:"s-add-product-button-mini-checkout-content"},s("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?s(i,null,s("salla-product-availability",{...this.getBtnAttributes(),"is-subscribed":!0},s("span",{class:"s-hidden"},s("slot",null)))):"out-and-notify"===this.productStatus&&this.channels||this.hasOutOfStockOption?s(i,null,s("salla-product-availability",{...this.getBtnAttributes()},s("span",{class:"s-hidden"},s("slot",null)))):s(i,{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}},s("div",{class:{"s-add-product-button-main":this.showQuickBuy,"w-full":!document.getElementById("fast-checkout-js")||["financial_support","donating"].includes(this.productType)}},s("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"},s("slot",null)),this.showQuickBuy&&document.getElementById("fast-checkout-js")&&!["financial_support","donating"].includes(this.productType)?this.miniCheckoutWidget():""),this.showQuickBuy&&this.isApplePayActive?s("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 a=salla.storage.get(`product-${this.productId}-subscribed-options`);if((a||this.subscribedOptions)&&this.hasOutOfStockOption)if(salla.config.isGuest()){const t=a?a.map((t=>t.split(",").map((t=>parseInt(t))))):[];this.hasSubscribedOptions=t.length>0&&t.some((t=>t.every((t=>this.selectedOptions.some((a=>a.id===t))))))}else this.hasSubscribedOptions=!(!this.subscribedOptions||"null"===this.subscribedOptions||"[]"===this.subscribedOptions)&&JSON.parse(this.subscribedOptions).some((t=>t.every((t=>this.selectedOptions.some((a=>a.id===t))))))}))}componentDidRender(){!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)}};c.style=":host{display:block}salla-add-product-button[width=wide]{width:100%}";const h=class{constructor(a){t(this,a),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 a=document.querySelector(`salla-product-options[product-id="${this.productId}"]`),s=Object.values(await(a?.getSelectedOptionsData())||{});if(s.length&&!await(a?.reportValidity())){let t=salla.lang.get("common.messages.required_fields");throw salla.error(t),t}return t.options=[],s.forEach((a=>{a&&!isNaN(a)&&t.options.push(Number(a))})),t},this.typing=t=>{const a=t.target.nextElementSibling;t.target.classList.remove("s-has-error"),a?.classList.contains("s-product-availability-error-msg")&&(a.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"),this.isVisitorSubscribed=this.notifyOptionsAvailability?"":salla.storage.get(`product-${this.productId}-subscribed`))}channelsWatcher(t){this.channels_=t?t.split(","):[]}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")){let{phone:a,countryCode:s}=await this.mobileInput.getValues();t.country_code=s,t.phone=a}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)return salla.storage.set(`product-${this.productId}-subscribed`,!0),void(this.isSubscribed=!0);if(t.options.length){let a=salla.storage.get(`product-${this.productId}-subscribed-options`)||[],s=t.options.join(",");a.includes(s)?salla.log("already subscribed to this options"):(a.push(s),salla.storage.set(`product-${this.productId}-subscribed-options`,a),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=p.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")&&await this.mobileInput.isValid())return}catch(t){throw"Please insert required fields"}}validateField(t,a){t.classList.add("s-has-error"),t.nextElementSibling.innerText="* "+a}render(){return s(i,{key:"e5b3121a6e352338ff666ba419100150e838e0d2",class:"s-product-availability-wrap"},this.isSubscribed||this.isVisitorSubscribed?s("div",{class:"s-product-availability-subscribed"},s("span",{innerHTML:n,class:"s-product-availability-subs-icon"}),salla.lang.get("pages.products.notify_availability_success")):s("salla-button",{width:"wide",onClick:()=>this.isUser?this.submit():this.openModel()},salla.lang.get("pages.products.notify_availability")),this.isUser||this.isSubscribed||this.isVisitorSubscribed?"":this.renderModal())}renderModal(){return s("salla-modal",{ref:t=>this.modal=t,"modal-title":this.title_,subTitle:salla.lang.get("pages.products.notify_availability_subtitle"),width:"sm"},s("span",{slot:"icon",class:"s-product-availability-header-icon",innerHTML:n}),s("div",{class:"s-product-availability-body"},this.channels_.includes("email")?[s("label",{class:"s-product-availability-label"},salla.lang.get("common.elements.email")),s("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"}),s("span",{class:"s-product-availability-error-msg"})]:"",this.channels_.includes("sms")?[s("label",{class:"s-product-availability-label"},salla.lang.get("common.elements.mobile")),s("salla-tel-input",{ref:t=>this.mobileInput=t,onKeyDown:t=>this.typing(t)})]:""),s("div",{slot:"footer",class:"s-product-availability-footer"},s("salla-button",{class:"modal-cancel-btn",width:"wide",color:"light",fill:"outline",onClick:()=>this.modal.close()},salla.lang.get("common.elements.cancel")),s("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 u,y;h.style="",function(t){t.COLOR="color",t.DATE="date",t.DATETIME="datetime",t.DONATION="donation",t.IMAGE="image",t.MULTIPLE_OPTIONS="multiple-options",t.NUMBER="number",t.SINGLE_OPTION="single-option",t.DIGITAL_CARD_VALUE="digital-code-value",t.COUNTRY="country",t.SPLITTER="splitter",t.TEXT="text",t.TEXTAREA="textarea",t.THUMBNAIL="thumbnail",t.TIME="time",t.RADIO="radio",t.CHECKBOX="checkbox",t.MAP="map",t.FILE="file",t.COLOR_PICKER="color_picker",t.BOOKING="booking"}(u||(u={})),function(t){t.Sar="SAR"}(y||(y={}));const m=class{constructor(i){if(t(this,i),this.changed=a(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.outSkus=[],this.ignoreDefaultCardValue=!1,this.productId=salla.config.get("page.id"),this.handleDonationOptions=(t,a,s)=>{if("custom"===a&&"input"===s){const a=t.target;return salla.helpers.inputDigitsOnly(a),salla.event.emit("product-options::donation-changed",{id:this.productId,price:a.value}),void a.dispatchEvent(new window.Event("change",{bubbles:!0}))}const i="option"===s?String(t.target?.value??""):"";if("option"===s&&"custom"===a&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()),this.isCustomDonation="custom"===i,this.donationInput){if("custom"===i?(this.donationInput.value="",this.donationInput.focus()):this.donationInput.value=i,"custom"===a)return;salla.event.emit("product-options::donation-changed",{id:this.productId,price:i})}},this.hideLabel=t=>!(t.type!==u.DONATION||!t.donation||t.donation.can_donate),this.getExpireDonationMessage=t=>{if(!t.donation)return;const a=t.donation.target_amount<=t.donation.collected_amount;return s("div",{class:{"s-product-options-donation-message":!0,"s-product-options-donation-completed":a,"s-product-options-donation-expired":!a}},s("p",null,t.donation.target_message),s("span",{innerHTML:a?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.setOptionsData(t.data.options)))}async setOptionsData(t){this.optionsData=t;const a=this;this.optionsData[0]?.details?.forEach((function(t){Object.entries(t.skus_availability||{}).filter((t=>!t[1])).map((t=>a.outSkus.push(Number(t[0]))))}))}async getSelectedOptionsData(){const t={},a=this.host.getElementSallaData(),s=void 0!==this.bundleContext?this.bundleContext:null;return a.forEach(((a,i)=>{if(s){if(i.startsWith("bundle[")&&i.includes("[options][")){const s=i.split("[options][")[1].replace("]","");t[s]=a}}else i.startsWith("options[")&&(t[i.replace("options[","").replace("]","")]=a)})),t}async reportValidity(){const t=this.host.querySelectorAll("[required]");let a=!0;for(let s=0;s<t.length;s++)"reportValidity"in t[s]&&!t[s].reportValidity()&&(a=!1);return a}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((a=>a.id===t))}invalidHandler(t,a){const s=t.target.closest(".s-product-options-option");s.classList.contains("s-product-options-option-error")||s.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")===s&&this.scrollToElement(s)}scrollToElement(t){t&&t.scrollIntoView({behavior:"smooth",block:"center"})}changedHandler(t,a,s=!0){const i={event:t,option:a,detail:null,productId:this.productId};if(a.details){const s=a.details.find((a=>Number(a.id)===Number(t.target.value)));i.detail=s}"country"===a.type&&this.handleCountryOptionChange(t,i.detail);const e=t.target.closest(".s-product-options-option");(t.target.value||(a.type===u.FILE||a.type===u.IMAGE)&&"added"===t.type||a.type===u.MAP&&"selected"===t.type&&t.target.lat&&t.target.lng)&&setTimeout((()=>{e.classList.remove("s-product-options-option-error")}),200),a.type===u.DONATION&&salla.event.emit("product-options::donation-changed",{id:this.productId,price:t.target.value}),this.setSelectedSkus(),this.handleRequiredMultipleOptions(a);const l=this.selectedOptions.findIndex((t=>t.option_id===i.option.id));if(i.option.type===u.MULTIPLE_OPTIONS){const t=this.selectedOptions.findIndex((t=>t.option_id===i.option.id&&t?.id===i.detail?.id));t>-1?this.selectedOptions.splice(t,1):this.selectedOptions.push({...i.detail,option_id:i.option.id})}else i.detail&&0!==Object.keys(i.detail).length?l>-1?this.selectedOptions[l]={...i.detail,option_id:i.option.id}:this.selectedOptions.push({...i.detail,option_id:i.option.id}):l>-1&&this.selectedOptions.splice(l,1);this.optionsData=this.optionsData.map((t=>t.id===i.option.id?{...t,details:t.details.map((t=>({...t,is_selected:i.option.type===u.MULTIPLE_OPTIONS?this.selectedOptions.some((a=>a.id===t.id)):Number(t.id)===Number(i.detail?.id),value:i.detail?.value})))}:t)),s&&(this.changed.emit(i),salla.event.emit("product-options::change",i))}setSelectedSkus(){this.selectedSkus=this.selectedOptions.map((t=>Object.keys(t.skus_availability||{}))).reduce(((t,a)=>t.filter((t=>a.includes(t)))),[]).map((t=>Number(t)))}handleRequiredMultipleOptions(t){if(t.type!==u.MULTIPLE_OPTIONS||!t.required)return;const a=this.host.querySelector(`[data-option-id="${t.id}"]`),s=a.querySelectorAll("input:checked").length;a.querySelectorAll("input").forEach((t=>t.toggleAttribute("required",!s)))}getLatLng(t,a){return t?t.split(",")["lat"===a?0:1]:""}getDisplayForType(t){return this[`${t.type}Option`]?this[`${t.type}Option`](t):t.type===u.COLOR_PICKER?this.colorPickerOption(t):t.type===u.MULTIPLE_OPTIONS?this.multipleOptions(t):t.type===u.SINGLE_OPTION?this.singleOption(t):t.type===u.RADIO?this.radioOption(t):t.type===u.DIGITAL_CARD_VALUE?this.digitalCardValuesOption(t):t.type===u.COUNTRY?this.countryOption(t):t.type===u.BOOKING&&salla.url.is_page("cart")?s("salla-booking-field",{onInvalidInput:a=>this.invalidHandler(a,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 a=this.optionsData.find((({type:t})=>"digital-code-value"===t));if(!a)throw new Error("product-options:: No digital card options found");const s=Object.keys(t.skus_availability).filter((a=>!1===t.skus_availability[a]));this.availableDigitalCardValues=a.details.filter((t=>!Object.keys(t.skus_availability).filter((t=>s.includes(t))).length))}handleCountryOptionChange(t,a){t.stopImmediatePropagation(),this.ignoreDefaultCardValue=!0;const s=this.host.querySelector("input[data-code-value]:checked");if(s&&(s.checked=!1),!this.optionsData.find((({type:t})=>"digital-code-value"===t)))throw new Error("product-options:: No digital card options found");this.getAvailableDigitalCardSKUs(a)}getSelectedDigitalCardOptions(t){const a=t.details.find((t=>t.is_selected)),s=t.details.find((t=>!!t.is_default))||t.details[0];if(["digital-code-value","country"].includes(t.type))return a||s}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)),a=t&&this.getSelectedDigitalCardOptions(t);a&&this.getAvailableDigitalCardSKUs(a)}return this.outOfStockText=salla.lang.get("pages.products.out_of_stock"),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 a=t.target;if(!(Salla.helpers.isAppleDevice()&&(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement)&&a.classList.contains("s-form-control")&&this.host.contains(a)))return;t.preventDefault();const s=t.clipboardData?.getData("text")||"",i=a.selectionStart,e=a.selectionEnd,l=a.value.slice(0,i)+s+a.value.slice(e);a.value=l,a.setSelectionRange(i+s.length,i+s.length);try{a.dispatchEvent(new window.Event("change",{bubbles:!0}))}catch(t){Salla.log("Error on change")}}hideDigitalCardsOptions(t){return this.disableCardValue&&t.type===u.DIGITAL_CARD_VALUE&&!salla.url.is_page("cart")}render(){if(0!==this.optionsData?.length)return s(i,{class:"s-product-options-wrapper"},s("salla-conditional-fields",null,this.optionsData.map((t=>s("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():s("div",{class:{"s-product-options-option":!0,"s-product-options-option-booking":t.type===u.BOOKING&&salla.url.is_page("cart")},"data-option-type":t.type,"data-option-required":`${t.required}`},s("label",{htmlFor:this.generateInputId(t.id),class:"s-product-options-option-label "+(this.hideLabel(t)?"s-product-options-option-label-hidden":"")},s("b",null,t.name,t.required&&s("span",null," * ")," "),s("small",null,t.placeholder)),s("div",{class:"s-product-options-option-content "+(this.hideLabel(t)||t.type===u.BOOKING&&salla.url.is_page("cart")?"s-product-options-option-content-full-width":"")},this.getDisplayForType(t))))))))}generateUniqueKey(t){const a=this.bundleContext;let s=this.uniqueKey?`${t}-${this.uniqueKey}`:t;if(a)try{const t="string"==typeof a?JSON.parse(a):a,{sectionId:i,productId:e}=t;s=`${s}-bundle-${i}-${e}`}catch(t){}return s}generateInputId(t){return this.generateUniqueKey(`option-${t}`)}generateInputName(t){const a=this.bundleContext,s=t.toString();if(a)try{const t="string"==typeof a?JSON.parse(a):a,{sectionId:i,productId:e}=t;return`bundle[${i}][${e}][options][${s}]`}catch(t){return`options[${s}]`}return`options[${s}]`}fillSelectedOptions(){this.selectedOptions=this.optionsData.reduce(((t,a)=>{const s=a.details.filter((t=>t.is_selected)).map((t=>({...t,option_id:a.id})));return t.concat(s)}),[])}async componentDidLoad(){if(!this.optionsData?.length)return;await Salla.hooks.registerComponent("salla-product-options",this);const t=this.optionsData.find((t=>t.type===u.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=[u.SINGLE_OPTION,u.MULTIPLE_OPTIONS,u.COLOR,u.THUMBNAIL,u.DONATION,u.DIGITAL_CARD_VALUE,u.COUNTRY];this.optionsData.some((a=>t.includes(a.type)&&a.details?.some((t=>t.is_selected))))&&requestAnimationFrame((()=>{try{const t=this.host.closest("form");if(!t)return;const a=new FormData(t),s=a.get("id")||a.get("product_id");if(s&&String(s)!==String(this.productId))return;salla.product.getPrice(a)}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()}async enableUserInitiatedValidation(){this.userInitiatedValidation=!0}async validateAndScroll(){return await this.enableUserInitiatedValidation(),this.reportValidity()}donationOption(t,a){return s("div",{class:"s-product-options-donation-wrapper"},t.donation?.can_donate?[t.donation?s("div",{key:t.id,class:"s-product-options-donation-progress"},s("salla-progress-bar",{donation:t.donation})):"",t.details.length?[s("h4",{key:t.id},this.selectAmount),s("div",{key:t.id,class:"s-product-options-donation-options"},t.details.map(((a,i)=>s("div",{key:t.id,class:"s-product-options-donation-options-item"},s("input",{id:this.generateUniqueKey(`donation-option-${i}`),type:"radio",name:"donating_option",checked:a.is_selected,value:a.additional_price,onChange:s=>this.handleDonationOptions(s,a,"option",t)}),s("label",{htmlFor:this.generateUniqueKey(`donation-option-${i}`)},s("span",{innerHTML:salla.money(a.name)}))))),t.donation?.custom_amount_enabled?s("div",{class:"s-product-options-donation-options-item"},s("input",{id:this.generateUniqueKey("donation-option-custom"),type:"radio",name:"donating_option",value:"custom",onChange:a=>this.handleDonationOptions(a,"custom","option",t)}),s("label",{htmlFor:this.generateUniqueKey("donation-option-custom")},s("span",null," ",this.selectDonationAmount," "))):"")]:"",s("div",{key:t.id,class:{"s-product-options-donation-input-group":!0,shown:!t.details.length||t.details.length&&this.isCustomDonation}},s("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:a=>this.handleDonationOptions(a,"custom","input",t),onBlur:a=>this.changedHandler(a,t),onInvalid:a=>this.invalidHandler(a,t)}),s("span",{class:"s-product-options-donation-amount-currency"},salla.config.currency(salla.config.get("user.currency_code")).symbol))]:this.getExpireDonationMessage(t))}fileUploader(t,a=null){return s("salla-file-upload",{...a||{},"payload-name":"file",value:t.value,"instant-upload":!0,name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,height:"120px",onAdded:a=>this.changedHandler(a,t),url:salla.cart.api.getUploadImageEndpoint(),"form-data":{cart_item_id:this.productId,product_id:this.productId},onInvalidInput:a=>this.invalidHandler(a,t),class:{"s-product-options-image-input":!0,required:t.required}},s("div",{class:"s-product-options-filepond-placeholder"},s("span",{class:"s-product-options-filepond-placeholder-icon",innerHTML:a.accept?.split(",").every((t=>t.includes("image")))?d:'\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'}),s("p",{class:"s-product-options-filepond-placeholder-text"},salla.lang.get("common.uploader.drag_and_drop")),s("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 a=t.details.map((t=>this.fileTypes[t.name])).filter(Boolean);return a?.length?this.fileUploader(t,{accept:a.join(",")}):"File types not selected."}numberOption(t){return s("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:a=>this.changedHandler(a,t),onInvalid:a=>this.invalidHandler(a,t),onInput:t=>salla.helpers.inputDigitsOnly(t.target)})}splitterOption(){return s("div",{class:"s-product-options-splitter"})}textOption(t){return s("div",{class:"s-product-options-text"},s("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:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)}))}textareaOption(t){return s("div",{class:"s-product-options-textarea"},s("div",{class:"mt-1"},s("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:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)})))}mapOption(t){return s("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:a=>this.invalidHandler(a,t),onSelected:a=>this.changedHandler(a,t)})}colorPickerOption(t){return s("salla-color-picker",{onSubmitted:a=>this.changedHandler(a,t),name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,onInvalidInput:a=>this.invalidHandler(a,t),color:t.value})}timeOption(t){return s("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:a=>this.invalidHandler(a,t),onPicked:a=>this.changedHandler(a,t)})}dateOption(t){return s("div",{class:"s-product-options-date-element"},s("salla-datetime-picker",{value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,minDate:new Date,name:this.generateInputName(t.id),onInvalidInput:a=>this.invalidHandler(a,t),onPicked:a=>this.changedHandler(a,t)}))}datetimeOption(t){return s("div",{class:"s-product-options-datetime-element"},s("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:a=>this.invalidHandler(a,t),onPicked:a=>this.changedHandler(a,t)}))}getOptionDetailName(t,a=!0,s){let i;return s&&s===u.COLOR&&(i=t.name+(a&&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>`:"")),i||(i=t.name+(a&&this.isOptionDetailOut(t)&&!salla.url.is_page("cart")&&!this.hideOutLabel?` - ${this.outOfStockText}`:"")+(t.additional_price?` (${salla.money(t.additional_price,!1)})`:"")),i.replace("<i class=sicon-sar></i>",salla.config.currency()?.symbol||"ر.س")}isOptionDetailOut(t){if(t.is_out||!t.skus_availability||!this.selectedSkus?.length)return t.is_out;const a=this.selectedOptions.filter((a=>a.id===t.id)).length;if(a&&1===this.selectedOptions.length)return!1;if(a){const a=this.selectedSkus.filter((t=>this.outSkus.includes(t)));return Object.keys(t.skus_availability).some((t=>a.includes(Number(t))))}return this.selectedOptions.some((a=>a.is_out&&a.option_id!==t.option_id))}renderInput(t,a,i,e,l,o){const n=this.generateUniqueKey(`${t}-${i.id}-${a.id}`),p=this.isOptionDetailOut(a);return s("label",{class:{"s-product-options-disabled":p}},s("input",{id:n,type:t,name:l,value:a.id,disabled:p,required:e,checked:a.is_selected,onInvalid:t=>this.invalidHandler(t,i),onChange:t=>this.changedHandler(t,i)}),s("div",{class:{"s-product-options-grid-mode-span":o,"s-product-options-disabled":p}},this.getOptionDetailName(a)))}renderOptionDetails(t,a,s,i=!1){const e=this.generateInputName(a.id),l="radio"===t?e:`${e}[]`;return a?.details.map((e=>this.renderInput(t,e,a,s,l,i)))}renderSelect(t){return s("div",null,s("select",{id:this.generateInputId(t.id),name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,class:"s-form-control",onInvalid:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)},s("option",{value:""},t.placeholder),t?.details.map((t=>s("option",{key:t.id,value:t.id,disabled:this.canDisabled&&this.isOptionDetailOut(t),selected:t.is_selected},this.getOptionDetailName(t))))))}renderButtonStyle(t,a,i){return s("div",{class:"s-product-options-grid-mode"},this.renderOptionDetails(t,a,i,!0))}singleOption(t){return"button"===this.optionConfig?.["single-option"]?.type?this.renderButtonStyle("radio",t,!t.visibility_condition&&t.required):this.renderSelect(t)}multipleOptions(t){const a="button"===this.optionConfig?.["multiple-option"]?.type,i=t.required&&!t.details.some((t=>t.is_selected))&&!t.visibility_condition;return a?this.renderButtonStyle("checkbox",t,i):s("div",{class:{"s-product-options-multiple-options-wrapper":!0,required:t.required}},this.renderOptionDetails("checkbox",t,i))}radioOption(t){return this.singleOption(t)}colorOption(t){return s("fieldset",{class:"s-product-options-colors-wrapper"},t?.details.map((a=>s("div",{class:"s-product-options-colors-item",key:a.id},s("input",{type:"radio",value:a.id,required:!t.visibility_condition&&t.required,checked:a.is_selected,name:this.generateInputName(t.id),disabled:this.canDisabled&&this.isOptionDetailOut(a),id:this.generateUniqueKey(`color-${this.productId}-${t.id}-${a.id}`),onInvalid:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)}),s("label",{htmlFor:this.generateUniqueKey(`color-${this.productId}-${t.id}-${a.id}`)},s("span",{style:{backgroundColor:a.color}}),s("div",{innerHTML:this.getOptionDetailName(a,!0,t.type)}))))))}thumbnailOption(t){return s("div",{class:"s-product-options-thumbnails-wrapper"},t.details.map((a=>s("div",{key:a.id},s("input",{type:"radio",value:a.id,"data-itemid":a.id,required:!t.visibility_condition&&t.required,checked:a.is_selected,name:this.generateInputName(t.id),"data-img-id":a.option_value,disabled:this.canDisabled&&this.isOptionDetailOut(a),id:this.generateUniqueKey(`option_${this.productId}-${t.id}_${a.id}`),onInvalid:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)}),s("label",{htmlFor:this.generateUniqueKey(`option_${this.productId}-${t.id}_${a.id}`),"data-img-id":a.option_value,class:"go-to-slide"},s("img",{"data-src":a.image,src:a.image,title:a.name,alt:a.name}),s("span",{innerHTML:r,class:"s-product-options-thumbnails-icon"}),this.isOptionDetailOut(a)?[s("small",{key:a.id,class:"s-product-options-thumbnails-stock-badge"},this.outOfStockText),this.canDisabled?s("div",{key:a.id,class:"s-product-options-thumbnails-badge-overlay"}):""]:""),s("p",null,this.getOptionDetailName(a,!1)," ")))))}digitalCardValuesOption(t){return s("div",{class:"s-product-options-digital-card-wrapper"},this.availableDigitalCardValues.length>0?this.availableDigitalCardValues.map((a=>{const i=String(a.id);return s("label",{htmlFor:this.generateUniqueKey(i.toString()),key:i,class:"s-product-options-digital-card-option"},s("input",{type:"radio","data-code-value":!0,class:"s-form-control s-product-options-digital-card-input",value:a.id,name:this.generateInputName(t.id),id:this.generateUniqueKey(i.toString()),required:!t.visibility_condition&&t.required,onInvalid:a=>this.invalidHandler(a,t),...this.ignoreDefaultCardValue?{}:{defaultChecked:this.getSelectedDigitalCardOptions(t)?.id===a.id}}),s("span",null,a.name," ",salla.config?.currency()?.symbol))})):s("div",{class:"s-product-options-digital-card-out-of-stock"}))}countryOption(t){return s("div",{class:"s-product-options-digital-card-wrapper"},t.details.map((a=>s("label",{htmlFor:this.generateUniqueKey(a.id.toString()),key:a.id,class:{"s-product-options-digital-card-option":!0,"s-product-options-digital-card-option-stock-out":a.is_out}},s("input",{id:this.generateUniqueKey(a.id.toString()),type:"radio",class:"s-form-control s-product-options-digital-card-input",value:a.id,name:this.generateInputName(t.id),disabled:a.is_out,required:!t.visibility_condition&&t.required,onInvalid:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t),onClick:()=>{this.disableCardValue=!1},...salla.url.is_page("cart")?{defaultChecked:this.getSelectedDigitalCardOptions(t)?.id===a.id}:{}}),s("img",{loading:"lazy",alt:a.code,height:24,width:24,class:"s-product-options-country-flag",src:`https://cdn.assets.salla.network/prod/admin/cp/assets/flags/1x1/${String(a.code).toLocaleLowerCase()}.svg`,onError:t=>{t.currentTarget.onerror=null,t.currentTarget.src=salla.url.cdn("images/globe.svg")}}),s("span",null,a.name)))))}get host(){return e(this)}};m.style="";var g={request:(t,a,s,i=null,e=null)=>l.request({url:a,data:s,method:t.toLowerCase(),responseType:"json"}).then(i).catch(e),get:(t,a=null,s=null,i)=>l.get(t,{params:i}).then(a).catch(s),post(t,a,s=null,i=null){return this.request("post",t,a,s,i)},put(t,a,s=null,i=null){return this.request("put",t,a,s,i)},delete(t,a,s=null,i=null){return this.request("delete",t,a,s,i)},requestWithSupportAjax(t,a,s="post"){return new Promise(((i,e)=>{if(!window?.isLegacyTheme)return this.request(s,t,a,(({data:t})=>i(t)),(({response:t})=>e(t)));$.ajax({url:t,method:s.toUpperCase(),data:a,async:!1,success:function({data:t}){return i(t)},error:function({response:t}){return e(t)}})}))}},v={options:[],header:[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,a){var s,i,e,l=0,o=0;for(l=0;l<a.length;l+=1)if(new RegExp(a[l].value,"i").test(t)){if(s=new RegExp(a[l].version+"[- /:;]([\\d._]+)","i"),e="",(i=t.match(s))&&i[1]&&(i=i[1]),i)for(i=i.split(/[._]+/),o=0;o<i.length;o+=1)e+=0===o?i[o]+".":i[o];else e="0";return{name:a[l].name,version:parseFloat(e)}}return{name:"unknown",version:0}}};async function w(t,a,s=!1){if(salla.logger.log("🍏 Pay: mutateShippingContact called",a,s),t.detail.requiredShippingContactFields&&0!=t.detail.requiredShippingContactFields.length)if(s){if(salla.config.isGuest()&&salla.config.get("store.features").includes("guest-checkout")){if(!(a.emailAddress&&a.givenName&&a.familyName&&a.phoneNumber)){salla.logger.warn("🍏 Pay: Guest contact fields are required",a);const s=[];return a.emailAddress||s.push(new window.ApplePayError("shippingContactInvalid","emailAddress","Email address is required")),a.phoneNumber||s.push(new window.ApplePayError("shippingContactInvalid","phoneNumber","Phone number is required")),a.givenName&&a.familyName||s.push(new window.ApplePayError("shippingContactInvalid","name","Name is required")),void t.session.completePayment({status:t.session.STATUS_INVALID_SHIPPING_CONTACT,errors:s})}await async function(t,a){return salla.logger.log("🍏 Pay: Updating guest contact",a),new Promise(((s,i)=>{g.post(t.detail.guestContactSelected.url.replace("{id}",t.id),{email:a.emailAddress||null,first_name:a.givenName||null,last_name:a.familyName||null,phone_number:a.phoneNumber||null,country_code:a.countryCode||null},(async({data:a})=>{"function"==typeof t.detail.guestContactSelected?.onSuccess&&t.detail.guestContactSelected.onSuccess(a),s(a)}),(({response:a})=>{salla.logger.warn("🍏 Pay: Failed to update guest contact via api",a),"function"==typeof t.detail.guestContactSelected?.onFailed&&t.detail.guestContactSelected.onFailed(a),i({response:a})}))}))}(t,a)}}else if(t.detail.requiredShippingContactFields.includes("postalAddress"))return g.post(t.detail.shippingContactSelected.url.replace("{id}",t.id),{country:a.country,city:a.locality,local:a.subLocality||a.administrativeArea||a.locality,description:a.subAdministrativeArea,street:a.addressLines?.join(", ")||a.administrativeArea,country_code:a.countryCode,postal_code:a.postalCode},(async({data:a})=>{if("function"==typeof t.detail.shippingContactSelected.onSuccess&&t.detail.shippingContactSelected.onSuccess(a),t.address_id=a.data.address_id,t.shipping_methods=a.data.shipping_methods,!t.shipping_methods||t.shipping_methods&&!t.shipping_methods.length)return salla.logger.warn("🍏 Pay: We dont found any supported methods",a),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(a){return salla.logger.warn("Failed set the shipping details to api",a),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}try{await t.recalculateTotal()}catch(a){return salla.logger.warn("🍏 Pay: Failed recalculate total",a),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}const s={newTotal:t.prepareTotal(),newLineItems:t.prepareLineItems(),newShippingMethods:t.mappingShippingMethods(t.shipping_methods)};salla.logger.log("🍏 Pay: completeShippingContactSelection",s),t.session.completeShippingContactSelection(s)}),(({response:a})=>{salla.logger.warn("🍏 Pay: Failed add address via api",a),"function"==typeof t.detail.shippingContactSelected.onFailed&&t.detail.shippingContactSelected.onFailed(a);let s=a?.data?.error?.fields,i=function(t){return Object.entries(t).filter((([t,a])=>a&&a.length>0)).map((([t,a])=>new window.ApplePayError("shippingContactInvalid",t,a[0])))}({countryCode:s?.country_code&&s.country_code.length>0?s.country_code[0]:null,locality:s?.city&&s.city.length>0?s.city[0]:null,country:s?.country&&s.country.length>0?s.country[0]:null});0===i.length&&a?.data?.error?.message&&i.push(new window.ApplePayError("shippingContactInvalid","locality",a?.data?.error?.message)),t.session.completeShippingContactSelection({newTotal:t.prepareTotal(),newLineItems:t.prepareLineItems(),status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:i})}))}window.Salla=window.Salla||{},window.Salla.Payments=window.Salla.Payments||{},window.SallaApplePay={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",SallaApplePay.startSession),Salla.event.addEventListener("payments::apple-pay.start-transaction",SallaApplePay.startSession)},initDefault:function(){SallaApplePay.detail.onError||(SallaApplePay.detail.onError=function(t){salla.notify.error(t)}),SallaApplePay.detail.authorized.onFailed||(SallaApplePay.detail.authorized.onFailed=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleErrorResponse(t),SallaApplePay.onCancel({},t.data.error.message)}),SallaApplePay.detail.validateMerchant.onFailed||(SallaApplePay.detail.validateMerchant.onFailed=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleErrorResponse({response:t}),SallaApplePay.onCancel({},t.data.error.message)}),SallaApplePay.detail.authorized.onSuccess||(SallaApplePay.detail.authorized.onSuccess=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleAfterResponseActions(t)})},prepareLineItems:function(){return SallaApplePay.detail?.items?.length||(SallaApplePay.detail.items=[{label:salla.lang.get("pages.cart.items_total"),amount:parseFloat(SallaApplePay.detail.amount).toString()}]),SallaApplePay.detail.items},prepareTotal:function(){return{label:window.location.hostname||"Salla",amount:parseFloat(SallaApplePay.detail.amount).toString()}},isPhysical:()=>SallaApplePay.detail?.requiredShippingContactFields?.includes("postalAddress"),startSession:async function(t){SallaApplePay.detail=t.detail||t,salla.log("🍏 Pay: payments::apple-pay.start-transaction",SallaApplePay.detail),SallaApplePay.initDefault();let a=SallaApplePay.getApplePaySessionVersion(),s=SallaApplePay.detail.supportedNetworks||["masterCard","visa"];5===a&&s.push("mada"),SallaApplePay.request={countryCode:SallaApplePay.detail.countryCode||"SA",supportsCouponCode:!0,couponCode:"",currencyCode:SallaApplePay.detail.currency||"SAR",requiredShippingContactFields:SallaApplePay.detail.requiredShippingContactFields?SallaApplePay.detail.requiredShippingContactFields:[],merchantCapabilities:["supports3DS"],supportedNetworks:s,supportedCountries:SallaApplePay.detail.supportedCountries||["SA"],total:SallaApplePay.prepareTotal(),shippingContact:SallaApplePay.detail.shippingContact?SallaApplePay.detail.shippingContact:{},shippingMethods:SallaApplePay.detail.shippingMethods&&SallaApplePay.detail.shippingMethods.length?SallaApplePay.mappingShippingMethods(t.detail.shippingMethods):[],lineItems:SallaApplePay.prepareLineItems()},salla.log("🍏 Pay: init ",SallaApplePay.request),SallaApplePay.session=new ApplePaySession(a,SallaApplePay.request),SallaApplePay.session.onshippingcontactselected=SallaApplePay.onShippingContactSelected,SallaApplePay.session.onshippingmethodselected=SallaApplePay.onShippingMethodSelected,SallaApplePay.session.onvalidatemerchant=SallaApplePay.onValidateMerchant,SallaApplePay.session.onpaymentauthorized=SallaApplePay.onPaymentAuthorized,SallaApplePay.session.oncancel=SallaApplePay.onCancel,SallaApplePay.session.oncouponcodechanged=SallaApplePay.onCouponCodeChanged,SallaApplePay.session.onpaymentmethodselected=SallaApplePay.onPaymentMethodSelected,SallaApplePay.session.begin()},onPaymentMethodSelected:async t=>{if(salla.logger.log("🍏 Pay: onPaymentMethodSelected",t),SallaApplePay.isPhysical())salla.logger.log("🍏 Pay: completePaymentMethodSelection",{newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()}),SallaApplePay.session.completePaymentMethodSelection({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()});else try{await SallaApplePay.recalculateTotal();const t={newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()};salla.logger.log("🍏 Pay: completePaymentMethodSelection",t),SallaApplePay.session.completePaymentMethodSelection(t)}catch(t){salla.logger.warn("🍏 Pay: Failed recalculate total",t),SallaApplePay.session.completePaymentMethodSelection({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems(),status:SallaApplePay.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),g.post(SallaApplePay.detail.onCouponCodeChanged.url.replace("{id}",SallaApplePay.id),{coupon:t.couponCode,payment_method:"apple_pay"},(async({data:t})=>{"function"==typeof SallaApplePay.detail.onCouponCodeChanged.onSuccess&&SallaApplePay.detail.onCouponCodeChanged.onSuccess(t),salla.log("🍏 Pay: Coupon applied success"),await SallaApplePay.recalculateTotal(),SallaApplePay.session.completeCouponCodeChange({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()})}),(async t=>{let a=t?.response;Salla.event.dispatch("payments::apple-pay.coupon.failed",a),"function"==typeof SallaApplePay.detail.onCouponCodeChanged.onFailed&&SallaApplePay.detail.onCouponCodeChanged.onFailed(a),await SallaApplePay.recalculateTotal(),SallaApplePay.session.completeCouponCodeChange({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems(),errors:[new window.ApplePayError("couponCodeInvalid")]})}))),onCancel:(t={},a=null)=>{SallaApplePay.detail.onError(a||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 w(SallaApplePay,t.payment.shippingContact,!0)}catch(t){salla.logger.error("🍏 Pay: Failed to update guest contact details",t);const a=t?.response||t,s=a?.data?.error?.fields||{},i=[];return s?.email&&s.email.length>0&&i.push(new window.ApplePayError("shippingContactInvalid","emailAddress",s.email[0])),s?.phone&&s.phone.length>0&&i.push(new window.ApplePayError("shippingContactInvalid","phoneNumber",s.phone[0])),s?.first_name&&s.first_name.length>0?i.push(new window.ApplePayError("shippingContactInvalid","name",s.first_name[0])):s?.last_name&&s.last_name.length>0&&i.push(new window.ApplePayError("shippingContactInvalid","name",s.last_name[0])),0===i.length&&i.push(new window.ApplePayError("shippingContactInvalid","name",a?.data?.error?.message||a?.data?.error?.code||"Invalid shipping contact details")),Salla.event.dispatch("payments::apple-pay.authorized.failed",a),"function"==typeof SallaApplePay.detail.authorized.onFailed&&SallaApplePay.detail.authorized.onFailed(a),void SallaApplePay.session.completePayment({status:ApplePaySession.STATUS_INVALID_SHIPPING_CONTACT,errors:i})}Salla.event.dispatch("payments::apple-pay.authorized.init",t),g.post(SallaApplePay.detail.authorized.url.replace("{id}",SallaApplePay.id),{payment_method:"apple_pay",applepay_token:JSON.stringify(t.payment)},(({data:t})=>{Salla.event.dispatch("payments::apple-pay.authorized.success",t),"function"==typeof SallaApplePay.detail.authorized.onSuccess&&SallaApplePay.detail.authorized.onSuccess(t),SallaApplePay.session.completePayment(ApplePaySession.STATUS_SUCCESS)}),(t=>{let a=t?.response;Salla.event.dispatch("payments::apple-pay.authorized.failed",a),"function"==typeof SallaApplePay.detail.authorized.onFailed&&SallaApplePay.detail.authorized.onFailed(a),SallaApplePay.session.completePayment({status:ApplePaySession.STATUS_FAILURE,errors:[new window.ApplePayError("unknown",void 0,a?.data?.error?.message||a?.data?.error?.code||"Failed to parse authorized response")]})}))},onValidateMerchant:async t=>{try{Salla.event.dispatch("payments::apple-pay.validate-merchant.init",t);const{data:a}=await g.post(SallaApplePay.detail.validateMerchant.url.replace("{id}",SallaApplePay.id),{validation_url:t.validationURL});Salla.event.dispatch("payments::apple-pay.validate-merchant.success",a);const s=t=>{SallaApplePay.session.completeMerchantValidation(t)};if("function"==typeof SallaApplePay.detail.validateMerchant.onSuccess){const t=await SallaApplePay.detail.validateMerchant.onSuccess(a);if(t?.redirect)return window.location=t.redirect,SallaApplePay.abortValidateMerchant(t)}s(a.data)}catch(t){console.error(t),SallaApplePay.abortValidateMerchant(t?.response)}},abortValidateMerchant:(t=null)=>{SallaApplePay.abortSession(),Salla.event.dispatch("payments::apple-pay.validate-merchant.failed",t),"function"==typeof SallaApplePay.detail.validateMerchant.onFailed&&SallaApplePay.detail.validateMerchant.onFailed(t)},onShippingContactSelected:async t=>{salla.logger.log("🍏 Pay: onShippingContactSelected",t.shippingContact),await w(SallaApplePay,t.shippingContact)},onShippingMethodSelected:async t=>{let a=t.shippingMethod.identifier.split(","),s={ship_id:a[0],private_ship_id:void 0===a[1]?null:a[1],type:void 0===a[2]?null:a[2],route_id:void 0===a[3]?null:a[3]};if(salla.logger.log("🍏 Pay: onShippingMethodSelected",{event:t,previous:SallaApplePay.shippingCompany,current:s}),SallaApplePay.shouldUpdateShippingCompany(s))try{await SallaApplePay.selectApplePayShippingMethod(s),await SallaApplePay.recalculateTotal()}catch(t){return salla.logger.warn("🍏 Pay: Failed set the shipping details to api",t),void SallaApplePay.session.completeShippingMethodSelection({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems(),status:SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}salla.logger.log("🍏 Pay: completeShippingMethodSelection",{newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()}),SallaApplePay.session.completeShippingMethodSelection({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()})},abortSession:()=>{SallaApplePay.session&&SallaApplePay.session.abort()},shouldUpdateShippingCompany:t=>SallaApplePay.shippingCompany?.ship_id!=t?.ship_id||SallaApplePay.shippingCompany?.private_ship_id!=t?.private_ship_id,getApplePaySessionVersion:()=>{if("sallapp"===(navigator.userAgent||navigator.vendor||window.opera))return 5;let t=v.init(),a=parseFloat(t.os.version);if("Macintosh"===t.os.name){if(a<10.142)return 1}else if(a<12.11)return 1;return 5},recalculateTotal:()=>(salla.logger.log("🍏 Pay: recalculate total"),g.get(SallaApplePay.detail.recalculateTotal.url.replace("{id}",SallaApplePay.id),(({data:t})=>{salla.logger.log("🍏 Pay: recalculate total success",t);let a=t.data.initial_data?.cart||t.data.cart,s=t.data.initial_data?.payments||t.data.payments;salla.logger.log("🍏 Pay: recalculate total success",{cart:a,payments:s}),SallaApplePay.detail.amount=s?.gateways?.applePay?.supportedMultiCurrency?a.total_in_customer_currency:a.total,SallaApplePay.detail.items=(a.totals||a.items).map((t=>({label:t.title,amount:"مجاني"===t.amount||"Free"===t.amount?0:t.amount.toString().replace("+","")}))),SallaApplePay.detail.items.pop(),SallaApplePay.totals=SallaApplePay.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),SallaApplePay.shippingCompany=t;const a={address_id:SallaApplePay.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 g.post(SallaApplePay.detail.shippingMethodSelected.url.replace("{id}",SallaApplePay.id),a,(({data:t})=>("function"==typeof SallaApplePay.detail.shippingMethodSelected.onSuccess&&SallaApplePay.detail.shippingMethodSelected.onSuccess(t),!0)),(t=>{salla.logger.warn("🍏 Pay: Set shipping method failed",t),"function"==typeof SallaApplePay.detail.shippingMethodSelected.onFailed&&SallaApplePay.detail.shippingMethodSelected.onFailed(t);let a=t?.response?.data?.error;return a?.data?.fields?.address_id?a?.data?.fields?.address_id[0]:a?.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:"")})))},window.ApplePaySession?.canMakePayments()?SallaApplePay.init():document.querySelectorAll("data-show-if-apple-pay-supported").forEach((t=>t.style.display="none"));const S=class{constructor(s){t(this,s),this.validationFailed=a(this,"validationFailed"),this.requireLogin=a(this,"requireLogin"),this.type="buy",this.productType="product",this.options={},this.quickBuy=salla.lang.get("pages.products.buy_now"),salla.lang.onLoaded((()=>{this.quickBuy=salla.lang.get("pages.products.buy_now")}))}async quickBuyHandler(){if(salla.config.isGuest()&&!this.isGuestCheckout()){this.requireLogin.emit({productId:this.productId});let t="salla-quick-buy::user.logged-in";return salla.event.on(t,(()=>this.settlePayment())),salla.api.auth.setAfterLoginEvent(t),salla.auth.event.dispatch("login::open",{withoutReload:!0})}await this.settlePayment()}async settlePayment(){let t=document.querySelector(`salla-product-options[product-id="${this.productId}"]`);if(t&&!await t.reportValidity())return this.validationFailed.emit({productId:this.productId}),salla.error(salla.lang.get("common.messages.required_fields"));let a=this.host.getElementSallaData();if(!this.isApplePayActive)return salla.api.request("checkout/quick-purchase/"+this.productId,a,"post").then((t=>(t.data.redirect&&(window.location.href=t.data.redirect),t)));a.is_applepay=!0,"append"in a&&a.append("is_applepay",!0),salla.event.dispatch("payments::apple-pay.start-transaction",{amount:this.amount,currency:this.currency||"SAR",requiredShippingContactFields:this.getRequiredShippingContactFields(),shippingMethods:this.isRequireShipping?[]:void 0,supportedNetworks:salla.config.get("store.settings.buy_now.networks"),supportedCountries:salla.config.get("store.settings.buy_now.countries"),countryCode:salla.config.get("store.store_country")||"SA",validateMerchant:{url:this.validateHost?`${this.validateHost}/checkout/applepay/validate`:salla.url.get("checkout/applepay/validate"),onSuccess:t=>this.applePayOnly&&!this.productId?this.cartId?(window.SallaApplePay.id=this.cartId,salla.log("🍏 Pay: create checkout success: with id #"+this.cartId),Promise.resolve(t)):(salla.logger.warn("🍏 Pay: trying to create applePay transaction without cartId/ProductId !"),Promise.resolve(t)):salla.api.request("checkout/quick-purchase/"+this.productId,"object"==typeof a?a: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}componentWillLoad(){console.log("🍏 Pay: Quick Buy Component Loaded");const t="undefined"!=typeof window&&!!window.ApplePaySession?.canMakePayments?.(),a=salla?.config?.get?.("store.settings.payments")?.includes?.("apple_pay")??!0,s=salla?.config?.get?.("store.settings.is_salla_gateway",!1)??!0;this.isApplePayActive=t&&a&&s;const i=async()=>{if(!this.currency&&salla?.config?.get&&(this.currency=salla.config.get("store.settings.buy_now.multi_currency")?salla.config.get("user.currency_code"):"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.amount=t.data.price,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.amount=t.price)})):salla?.url?.is_page?.("product.single")&&salla?.product?.event?.onPriceUpdated&&salla.product.event.onPriceUpdated((t=>{this.amount=t.data.price})),this.isApplePayActive=(salla?.helpers?.hasApplePay?.()??t)&&(salla?.config?.get?.("store.settings.payments")?.includes?.("apple_pay")??a)&&(salla?.config?.get?.("store.settings.is_salla_gateway",!1)??s),!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((()=>i().then((()=>t(!0))))):i().then((()=>t(!0)))}))}render(){return s(i,{key:"88125eb8c3bb1e1b016f39ea84ce6234267587a4"},this.quickBuyButton())}quickBuyButton(){return s("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)}};S.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{c as salla_add_product_button,h as salla_product_availability,m as salla_product_options,S as salla_quick_buy}
4
+ import{r as t,c as a,h as s,H as i,a as e,e as l}from"./p-CV1rqKQz.js";import{P as o}from"./p-DY4LZmNP.js";import{B as n}from"./p-D3mWkc-3.js";import{H as p}from"./p-CHf8XdiS.js";import{i as r}from"./p-BsXh13x8.js";import{C as d}from"./p-C6jIkM-X.js";import"./p-CgtvEd63.js";const c=class{constructor(s){t(this,s),this.success=a(this,"success"),this.failed=a(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.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?o: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 a=document.querySelector(`salla-product-options[product-id="${this.productId}"]`);return a&&"function"==typeof a.validateAndScroll?a.validateAndScroll().then((async t=>{const a={isValid:t,component:this};if(await salla.hooks.call("salla-add-product-button","validate",a),a.isValid)return this._proceedAddToCart();this.btn?.enable()})).catch((()=>{this.btn?.enable()})):this._proceedAddToCart()}async _proceedAddToCart(){const t=Object.entries({id:this.productId,donation_amount:this.donatingAmount,quantity:this.quantity,endpoint:"quickAdd"}).reduce(((t,[a,s])=>s?(t[a]=s,t):t),{});return salla.cart.addItem(t).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}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 s("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"},s("div",{slot:"widget-label",class:"s-add-product-button-mini-checkout-content"},s("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?s(i,null,s("salla-product-availability",{...this.getBtnAttributes(),"is-subscribed":!0},s("span",{class:"s-hidden"},s("slot",null)))):"out-and-notify"===this.productStatus&&this.channels||this.hasOutOfStockOption?s(i,null,s("salla-product-availability",{...this.getBtnAttributes()},s("span",{class:"s-hidden"},s("slot",null)))):s(i,{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}},s("div",{class:{"s-add-product-button-main":this.showQuickBuy,"w-full":!document.getElementById("fast-checkout-js")||["financial_support","donating"].includes(this.productType)}},s("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"},s("slot",null)),this.showQuickBuy&&document.getElementById("fast-checkout-js")&&!["financial_support","donating"].includes(this.productType)?this.miniCheckoutWidget():""),this.showQuickBuy&&this.isApplePayActive?s("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 a=salla.storage.get(`product-${this.productId}-subscribed-options`);if((a||this.subscribedOptions)&&this.hasOutOfStockOption)if(salla.config.isGuest()){const t=a?a.map((t=>t.split(",").map((t=>parseInt(t))))):[];this.hasSubscribedOptions=t.length>0&&t.some((t=>t.every((t=>this.selectedOptions.some((a=>a.id===t))))))}else this.hasSubscribedOptions=!(!this.subscribedOptions||"null"===this.subscribedOptions||"[]"===this.subscribedOptions)&&JSON.parse(this.subscribedOptions).some((t=>t.every((t=>this.selectedOptions.some((a=>a.id===t))))))}))}componentDidRender(){!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)}};c.style=":host{display:block}salla-add-product-button[width=wide]{width:100%}";const h=class{constructor(a){t(this,a),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 a=document.querySelector(`salla-product-options[product-id="${this.productId}"]`),s=Object.values(await(a?.getSelectedOptionsData())||{});if(s.length&&!await(a?.reportValidity())){let t=salla.lang.get("common.messages.required_fields");throw salla.error(t),t}return t.options=[],s.forEach((a=>{a&&!isNaN(a)&&t.options.push(Number(a))})),t},this.typing=t=>{const a=t.target.nextElementSibling;t.target.classList.remove("s-has-error"),a?.classList.contains("s-product-availability-error-msg")&&(a.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"),this.isVisitorSubscribed=this.notifyOptionsAvailability?"":salla.storage.get(`product-${this.productId}-subscribed`))}channelsWatcher(t){this.channels_=t?t.split(","):[]}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")){let{phone:a,countryCode:s}=await this.mobileInput.getValues();t.country_code=s,t.phone=a}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)return salla.storage.set(`product-${this.productId}-subscribed`,!0),void(this.isSubscribed=!0);if(t.options.length){let a=salla.storage.get(`product-${this.productId}-subscribed-options`)||[],s=t.options.join(",");a.includes(s)?salla.log("already subscribed to this options"):(a.push(s),salla.storage.set(`product-${this.productId}-subscribed-options`,a),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=p.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")&&await this.mobileInput.isValid())return}catch(t){throw"Please insert required fields"}}validateField(t,a){t.classList.add("s-has-error"),t.nextElementSibling.innerText="* "+a}render(){return s(i,{key:"e5b3121a6e352338ff666ba419100150e838e0d2",class:"s-product-availability-wrap"},this.isSubscribed||this.isVisitorSubscribed?s("div",{class:"s-product-availability-subscribed"},s("span",{innerHTML:n,class:"s-product-availability-subs-icon"}),salla.lang.get("pages.products.notify_availability_success")):s("salla-button",{width:"wide",onClick:()=>this.isUser?this.submit():this.openModel()},salla.lang.get("pages.products.notify_availability")),this.isUser||this.isSubscribed||this.isVisitorSubscribed?"":this.renderModal())}renderModal(){return s("salla-modal",{ref:t=>this.modal=t,"modal-title":this.title_,subTitle:salla.lang.get("pages.products.notify_availability_subtitle"),width:"sm"},s("span",{slot:"icon",class:"s-product-availability-header-icon",innerHTML:n}),s("div",{class:"s-product-availability-body"},this.channels_.includes("email")?[s("label",{class:"s-product-availability-label"},salla.lang.get("common.elements.email")),s("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"}),s("span",{class:"s-product-availability-error-msg"})]:"",this.channels_.includes("sms")?[s("label",{class:"s-product-availability-label"},salla.lang.get("common.elements.mobile")),s("salla-tel-input",{ref:t=>this.mobileInput=t,onKeyDown:t=>this.typing(t)})]:""),s("div",{slot:"footer",class:"s-product-availability-footer"},s("salla-button",{class:"modal-cancel-btn",width:"wide",color:"light",fill:"outline",onClick:()=>this.modal.close()},salla.lang.get("common.elements.cancel")),s("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 u,y;h.style="",function(t){t.COLOR="color",t.DATE="date",t.DATETIME="datetime",t.DONATION="donation",t.IMAGE="image",t.MULTIPLE_OPTIONS="multiple-options",t.NUMBER="number",t.SINGLE_OPTION="single-option",t.DIGITAL_CARD_VALUE="digital-code-value",t.COUNTRY="country",t.SPLITTER="splitter",t.TEXT="text",t.TEXTAREA="textarea",t.THUMBNAIL="thumbnail",t.TIME="time",t.RADIO="radio",t.CHECKBOX="checkbox",t.MAP="map",t.FILE="file",t.COLOR_PICKER="color_picker",t.BOOKING="booking"}(u||(u={})),function(t){t.Sar="SAR"}(y||(y={}));const m=class{constructor(i){if(t(this,i),this.changed=a(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.outSkus=[],this.ignoreDefaultCardValue=!1,this.productId=salla.config.get("page.id"),this.handleDonationOptions=(t,a,s)=>{if("custom"===a&&"input"===s){const a=t.target;return salla.helpers.inputDigitsOnly(a),salla.event.emit("product-options::donation-changed",{id:this.productId,price:a.value}),void a.dispatchEvent(new window.Event("change",{bubbles:!0}))}const i="option"===s?String(t.target?.value??""):"";if("option"===s&&"custom"===a&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()),this.isCustomDonation="custom"===i,this.donationInput){if("custom"===i?(this.donationInput.value="",this.donationInput.focus()):this.donationInput.value=i,"custom"===a)return;salla.event.emit("product-options::donation-changed",{id:this.productId,price:i})}},this.hideLabel=t=>!(t.type!==u.DONATION||!t.donation||t.donation.can_donate),this.getExpireDonationMessage=t=>{if(!t.donation)return;const a=t.donation.target_amount<=t.donation.collected_amount;return s("div",{class:{"s-product-options-donation-message":!0,"s-product-options-donation-completed":a,"s-product-options-donation-expired":!a}},s("p",null,t.donation.target_message),s("span",{innerHTML:a?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.setOptionsData(t.data.options)))}async setOptionsData(t){this.optionsData=t;const a=this;this.optionsData[0]?.details?.forEach((function(t){Object.entries(t.skus_availability||{}).filter((t=>!t[1])).map((t=>a.outSkus.push(Number(t[0]))))}))}async getSelectedOptionsData(){const t={},a=this.host.getElementSallaData(),s=void 0!==this.bundleContext?this.bundleContext:null;return a.forEach(((a,i)=>{if(s){if(i.startsWith("bundle[")&&i.includes("[options][")){const s=i.split("[options][")[1].replace("]","");t[s]=a}}else i.startsWith("options[")&&(t[i.replace("options[","").replace("]","")]=a)})),t}async reportValidity(){const t=this.host.querySelectorAll("[required]");let a=!0;for(let s=0;s<t.length;s++)"reportValidity"in t[s]&&!t[s].reportValidity()&&(a=!1);return a}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((a=>a.id===t))}invalidHandler(t,a){const s=t.target.closest(".s-product-options-option");s.classList.contains("s-product-options-option-error")||s.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")===s&&this.scrollToElement(s)}scrollToElement(t){t&&t.scrollIntoView({behavior:"smooth",block:"center"})}changedHandler(t,a,s=!0){const i={event:t,option:a,detail:null,productId:this.productId};if(a.details){const s=a.details.find((a=>Number(a.id)===Number(t.target.value)));i.detail=s}"country"===a.type&&this.handleCountryOptionChange(t,i.detail);const e=t.target.closest(".s-product-options-option");(t.target.value||(a.type===u.FILE||a.type===u.IMAGE)&&"added"===t.type||a.type===u.MAP&&"selected"===t.type&&t.target.lat&&t.target.lng)&&setTimeout((()=>{e.classList.remove("s-product-options-option-error")}),200),a.type===u.DONATION&&salla.event.emit("product-options::donation-changed",{id:this.productId,price:t.target.value}),this.setSelectedSkus(),this.handleRequiredMultipleOptions(a);const l=this.selectedOptions.findIndex((t=>t.option_id===i.option.id));if(i.option.type===u.MULTIPLE_OPTIONS){const t=this.selectedOptions.findIndex((t=>t.option_id===i.option.id&&t?.id===i.detail?.id));t>-1?this.selectedOptions.splice(t,1):this.selectedOptions.push({...i.detail,option_id:i.option.id})}else i.detail&&0!==Object.keys(i.detail).length?l>-1?this.selectedOptions[l]={...i.detail,option_id:i.option.id}:this.selectedOptions.push({...i.detail,option_id:i.option.id}):l>-1&&this.selectedOptions.splice(l,1);this.optionsData=this.optionsData.map((t=>t.id===i.option.id?{...t,details:t.details.map((t=>({...t,is_selected:i.option.type===u.MULTIPLE_OPTIONS?this.selectedOptions.some((a=>a.id===t.id)):Number(t.id)===Number(i.detail?.id),value:i.detail?.value})))}:t)),s&&(this.changed.emit(i),salla.event.emit("product-options::change",i))}setSelectedSkus(){this.selectedSkus=this.selectedOptions.map((t=>Object.keys(t.skus_availability||{}))).reduce(((t,a)=>t.filter((t=>a.includes(t)))),[]).map((t=>Number(t)))}handleRequiredMultipleOptions(t){if(t.type!==u.MULTIPLE_OPTIONS||!t.required)return;const a=this.host.querySelector(`[data-option-id="${t.id}"]`),s=a.querySelectorAll("input:checked").length;a.querySelectorAll("input").forEach((t=>t.toggleAttribute("required",!s)))}getLatLng(t,a){return t?t.split(",")["lat"===a?0:1]:""}getDisplayForType(t){return this[`${t.type}Option`]?this[`${t.type}Option`](t):t.type===u.COLOR_PICKER?this.colorPickerOption(t):t.type===u.MULTIPLE_OPTIONS?this.multipleOptions(t):t.type===u.SINGLE_OPTION?this.singleOption(t):t.type===u.RADIO?this.radioOption(t):t.type===u.DIGITAL_CARD_VALUE?this.digitalCardValuesOption(t):t.type===u.COUNTRY?this.countryOption(t):t.type===u.BOOKING&&salla.url.is_page("cart")?s("salla-booking-field",{onInvalidInput:a=>this.invalidHandler(a,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 a=this.optionsData.find((({type:t})=>"digital-code-value"===t));if(!a)throw new Error("product-options:: No digital card options found");const s=Object.keys(t.skus_availability).filter((a=>!1===t.skus_availability[a]));this.availableDigitalCardValues=a.details.filter((t=>!Object.keys(t.skus_availability).filter((t=>s.includes(t))).length))}handleCountryOptionChange(t,a){t.stopImmediatePropagation(),this.ignoreDefaultCardValue=!0;const s=this.host.querySelector("input[data-code-value]:checked");if(s&&(s.checked=!1),!this.optionsData.find((({type:t})=>"digital-code-value"===t)))throw new Error("product-options:: No digital card options found");this.getAvailableDigitalCardSKUs(a)}getSelectedDigitalCardOptions(t){const a=t.details.find((t=>t.is_selected)),s=t.details.find((t=>!!t.is_default))||t.details[0];if(["digital-code-value","country"].includes(t.type))return a||s}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)),a=t&&this.getSelectedDigitalCardOptions(t);a&&this.getAvailableDigitalCardSKUs(a)}return this.outOfStockText=salla.lang.get("pages.products.out_of_stock"),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 a=t.target;if(!(Salla.helpers.isAppleDevice()&&(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement)&&a.classList.contains("s-form-control")&&this.host.contains(a)))return;t.preventDefault();const s=t.clipboardData?.getData("text")||"",i=a.selectionStart,e=a.selectionEnd,l=a.value.slice(0,i)+s+a.value.slice(e);a.value=l,a.setSelectionRange(i+s.length,i+s.length);try{a.dispatchEvent(new window.Event("change",{bubbles:!0}))}catch(t){Salla.log("Error on change")}}hideDigitalCardsOptions(t){return this.disableCardValue&&t.type===u.DIGITAL_CARD_VALUE&&!salla.url.is_page("cart")}render(){if(0!==this.optionsData?.length)return s(i,{class:"s-product-options-wrapper"},s("salla-conditional-fields",null,this.optionsData.map((t=>s("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():s("div",{class:{"s-product-options-option":!0,"s-product-options-option-booking":t.type===u.BOOKING&&salla.url.is_page("cart")},"data-option-type":t.type,"data-option-required":`${t.required}`},s("label",{htmlFor:this.generateInputId(t.id),class:"s-product-options-option-label "+(this.hideLabel(t)?"s-product-options-option-label-hidden":"")},s("b",null,t.name,t.required&&s("span",null," * ")," "),s("small",null,t.placeholder)),s("div",{class:"s-product-options-option-content "+(this.hideLabel(t)||t.type===u.BOOKING&&salla.url.is_page("cart")?"s-product-options-option-content-full-width":"")},this.getDisplayForType(t))))))))}generateUniqueKey(t){const a=this.bundleContext;let s=this.uniqueKey?`${t}-${this.uniqueKey}`:t;if(a)try{const t="string"==typeof a?JSON.parse(a):a,{sectionId:i,productId:e}=t;s=`${s}-bundle-${i}-${e}`}catch(t){}return s}generateInputId(t){return this.generateUniqueKey(`option-${t}`)}generateInputName(t){const a=this.bundleContext,s=t.toString();if(a)try{const t="string"==typeof a?JSON.parse(a):a,{sectionId:i,productId:e}=t;return`bundle[${i}][${e}][options][${s}]`}catch(t){return`options[${s}]`}return`options[${s}]`}fillSelectedOptions(){this.selectedOptions=this.optionsData.reduce(((t,a)=>{const s=a.details.filter((t=>t.is_selected)).map((t=>({...t,option_id:a.id})));return t.concat(s)}),[])}async componentDidLoad(){if(!this.optionsData?.length)return;await Salla.hooks.registerComponent("salla-product-options",this);const t=this.optionsData.find((t=>t.type===u.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=[u.SINGLE_OPTION,u.MULTIPLE_OPTIONS,u.COLOR,u.THUMBNAIL,u.DONATION,u.DIGITAL_CARD_VALUE,u.COUNTRY];this.optionsData.some((a=>t.includes(a.type)&&a.details?.some((t=>t.is_selected))))&&requestAnimationFrame((()=>{try{const t=this.host.closest("form");if(!t)return;const a=new FormData(t),s=a.get("id")||a.get("product_id");if(s&&String(s)!==String(this.productId))return;salla.product.getPrice(a)}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()}async enableUserInitiatedValidation(){this.userInitiatedValidation=!0}async validateAndScroll(){return await this.enableUserInitiatedValidation(),this.reportValidity()}donationOption(t,a){return s("div",{class:"s-product-options-donation-wrapper"},t.donation?.can_donate?[t.donation?s("div",{key:t.id,class:"s-product-options-donation-progress"},s("salla-progress-bar",{donation:t.donation})):"",t.details.length?[s("h4",{key:t.id},this.selectAmount),s("div",{key:t.id,class:"s-product-options-donation-options"},t.details.map(((a,i)=>s("div",{key:t.id,class:"s-product-options-donation-options-item"},s("input",{id:this.generateUniqueKey(`donation-option-${i}`),type:"radio",name:"donating_option",checked:a.is_selected,value:a.additional_price,onChange:s=>this.handleDonationOptions(s,a,"option",t)}),s("label",{htmlFor:this.generateUniqueKey(`donation-option-${i}`)},s("span",{innerHTML:salla.money(a.name)}))))),t.donation?.custom_amount_enabled?s("div",{class:"s-product-options-donation-options-item"},s("input",{id:this.generateUniqueKey("donation-option-custom"),type:"radio",name:"donating_option",value:"custom",onChange:a=>this.handleDonationOptions(a,"custom","option",t)}),s("label",{htmlFor:this.generateUniqueKey("donation-option-custom")},s("span",null," ",this.selectDonationAmount," "))):"")]:"",s("div",{key:t.id,class:{"s-product-options-donation-input-group":!0,shown:!t.details.length||t.details.length&&this.isCustomDonation}},s("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:a=>this.handleDonationOptions(a,"custom","input",t),onBlur:a=>this.changedHandler(a,t),onInvalid:a=>this.invalidHandler(a,t)}),s("span",{class:"s-product-options-donation-amount-currency"},salla.config.currency(salla.config.get("user.currency_code")).symbol))]:this.getExpireDonationMessage(t))}fileUploader(t,a=null){return s("salla-file-upload",{...a||{},"payload-name":"file",value:t.value,"instant-upload":!0,name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,height:"120px",onAdded:a=>this.changedHandler(a,t),url:salla.cart.api.getUploadImageEndpoint(),"form-data":{cart_item_id:this.productId,product_id:this.productId},onInvalidInput:a=>this.invalidHandler(a,t),class:{"s-product-options-image-input":!0,required:t.required}},s("div",{class:"s-product-options-filepond-placeholder"},s("span",{class:"s-product-options-filepond-placeholder-icon",innerHTML:a.accept?.split(",").every((t=>t.includes("image")))?d:'\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'}),s("p",{class:"s-product-options-filepond-placeholder-text"},salla.lang.get("common.uploader.drag_and_drop")),s("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 a=t.details.map((t=>this.fileTypes[t.name])).filter(Boolean);return a?.length?this.fileUploader(t,{accept:a.join(",")}):"File types not selected."}numberOption(t){return s("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:a=>this.changedHandler(a,t),onInvalid:a=>this.invalidHandler(a,t),onInput:t=>salla.helpers.inputDigitsOnly(t.target)})}splitterOption(){return s("div",{class:"s-product-options-splitter"})}textOption(t){return s("div",{class:"s-product-options-text"},s("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:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)}))}textareaOption(t){return s("div",{class:"s-product-options-textarea"},s("div",{class:"mt-1"},s("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:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)})))}mapOption(t){return s("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:a=>this.invalidHandler(a,t),onSelected:a=>this.changedHandler(a,t)})}colorPickerOption(t){return s("salla-color-picker",{onSubmitted:a=>this.changedHandler(a,t),name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,onInvalidInput:a=>this.invalidHandler(a,t),color:t.value})}timeOption(t){return s("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:a=>this.invalidHandler(a,t),onPicked:a=>this.changedHandler(a,t)})}dateOption(t){return s("div",{class:"s-product-options-date-element"},s("salla-datetime-picker",{value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,minDate:new Date,name:this.generateInputName(t.id),onInvalidInput:a=>this.invalidHandler(a,t),onPicked:a=>this.changedHandler(a,t)}))}datetimeOption(t){return s("div",{class:"s-product-options-datetime-element"},s("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:a=>this.invalidHandler(a,t),onPicked:a=>this.changedHandler(a,t)}))}getOptionDetailName(t,a=!0,s){let i;return s&&s===u.COLOR&&(i=t.name+(a&&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>`:"")),i||(i=t.name+(a&&this.isOptionDetailOut(t)&&!salla.url.is_page("cart")&&!this.hideOutLabel?` - ${this.outOfStockText}`:"")+(t.additional_price?` (${salla.money(t.additional_price,!1)})`:"")),i.replace("<i class=sicon-sar></i>",salla.config.currency()?.symbol||"ر.س")}isOptionDetailOut(t){if(t.is_out||!t.skus_availability||!this.selectedSkus?.length)return t.is_out;const a=this.selectedOptions.filter((a=>a.id===t.id)).length;if(a&&1===this.selectedOptions.length)return!1;if(a){const a=this.selectedSkus.filter((t=>this.outSkus.includes(t)));return Object.keys(t.skus_availability).some((t=>a.includes(Number(t))))}return this.selectedOptions.some((a=>a.is_out&&a.option_id!==t.option_id))}renderInput(t,a,i,e,l,o){const n=this.generateUniqueKey(`${t}-${i.id}-${a.id}`),p=this.isOptionDetailOut(a);return s("label",{class:{"s-product-options-disabled":p}},s("input",{id:n,type:t,name:l,value:a.id,disabled:p,required:e,checked:a.is_selected,onInvalid:t=>this.invalidHandler(t,i),onChange:t=>this.changedHandler(t,i)}),s("div",{class:{"s-product-options-grid-mode-span":o,"s-product-options-disabled":p}},this.getOptionDetailName(a)))}renderOptionDetails(t,a,s,i=!1){const e=this.generateInputName(a.id),l="radio"===t?e:`${e}[]`;return a?.details.map((e=>this.renderInput(t,e,a,s,l,i)))}renderSelect(t){return s("div",null,s("select",{id:this.generateInputId(t.id),name:this.generateInputName(t.id),required:!t.visibility_condition&&t.required,class:"s-form-control",onInvalid:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)},s("option",{value:""},t.placeholder),t?.details.map((t=>s("option",{key:t.id,value:t.id,disabled:this.canDisabled&&this.isOptionDetailOut(t),selected:t.is_selected},this.getOptionDetailName(t))))))}renderButtonStyle(t,a,i){return s("div",{class:"s-product-options-grid-mode"},this.renderOptionDetails(t,a,i,!0))}singleOption(t){return"button"===this.optionConfig?.["single-option"]?.type?this.renderButtonStyle("radio",t,!t.visibility_condition&&t.required):this.renderSelect(t)}multipleOptions(t){const a="button"===this.optionConfig?.["multiple-option"]?.type,i=t.required&&!t.details.some((t=>t.is_selected))&&!t.visibility_condition;return a?this.renderButtonStyle("checkbox",t,i):s("div",{class:{"s-product-options-multiple-options-wrapper":!0,required:t.required}},this.renderOptionDetails("checkbox",t,i))}radioOption(t){return this.singleOption(t)}colorOption(t){return s("fieldset",{class:"s-product-options-colors-wrapper"},t?.details.map((a=>s("div",{class:"s-product-options-colors-item",key:a.id},s("input",{type:"radio",value:a.id,required:!t.visibility_condition&&t.required,checked:a.is_selected,name:this.generateInputName(t.id),disabled:this.canDisabled&&this.isOptionDetailOut(a),id:this.generateUniqueKey(`color-${this.productId}-${t.id}-${a.id}`),onInvalid:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)}),s("label",{htmlFor:this.generateUniqueKey(`color-${this.productId}-${t.id}-${a.id}`)},s("span",{style:{backgroundColor:a.color}}),s("div",{innerHTML:this.getOptionDetailName(a,!0,t.type)}))))))}thumbnailOption(t){return s("div",{class:"s-product-options-thumbnails-wrapper"},t.details.map((a=>s("div",{key:a.id},s("input",{type:"radio",value:a.id,"data-itemid":a.id,required:!t.visibility_condition&&t.required,checked:a.is_selected,name:this.generateInputName(t.id),"data-img-id":a.option_value,disabled:this.canDisabled&&this.isOptionDetailOut(a),id:this.generateUniqueKey(`option_${this.productId}-${t.id}_${a.id}`),onInvalid:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t)}),s("label",{htmlFor:this.generateUniqueKey(`option_${this.productId}-${t.id}_${a.id}`),"data-img-id":a.option_value,class:"go-to-slide"},s("img",{"data-src":a.image,src:a.image,title:a.name,alt:a.name}),s("span",{innerHTML:r,class:"s-product-options-thumbnails-icon"}),this.isOptionDetailOut(a)?[s("small",{key:a.id,class:"s-product-options-thumbnails-stock-badge"},this.outOfStockText),this.canDisabled?s("div",{key:a.id,class:"s-product-options-thumbnails-badge-overlay"}):""]:""),s("p",null,this.getOptionDetailName(a,!1)," ")))))}digitalCardValuesOption(t){return s("div",{class:"s-product-options-digital-card-wrapper"},this.availableDigitalCardValues.length>0?this.availableDigitalCardValues.map((a=>{const i=String(a.id);return s("label",{htmlFor:this.generateUniqueKey(i.toString()),key:i,class:"s-product-options-digital-card-option"},s("input",{type:"radio","data-code-value":!0,class:"s-form-control s-product-options-digital-card-input",value:a.id,name:this.generateInputName(t.id),id:this.generateUniqueKey(i.toString()),required:!t.visibility_condition&&t.required,onInvalid:a=>this.invalidHandler(a,t),...this.ignoreDefaultCardValue?{}:{defaultChecked:this.getSelectedDigitalCardOptions(t)?.id===a.id}}),s("span",null,a.name," ",salla.config?.currency()?.symbol))})):s("div",{class:"s-product-options-digital-card-out-of-stock"}))}countryOption(t){return s("div",{class:"s-product-options-digital-card-wrapper"},t.details.map((a=>s("label",{htmlFor:this.generateUniqueKey(a.id.toString()),key:a.id,class:{"s-product-options-digital-card-option":!0,"s-product-options-digital-card-option-stock-out":a.is_out}},s("input",{id:this.generateUniqueKey(a.id.toString()),type:"radio",class:"s-form-control s-product-options-digital-card-input",value:a.id,name:this.generateInputName(t.id),disabled:a.is_out,required:!t.visibility_condition&&t.required,onInvalid:a=>this.invalidHandler(a,t),onChange:a=>this.changedHandler(a,t),onClick:()=>{this.disableCardValue=!1},...salla.url.is_page("cart")?{defaultChecked:this.getSelectedDigitalCardOptions(t)?.id===a.id}:{}}),s("img",{loading:"lazy",alt:a.code,height:24,width:24,class:"s-product-options-country-flag",src:`https://cdn.assets.salla.network/prod/admin/cp/assets/flags/1x1/${String(a.code).toLocaleLowerCase()}.svg`,onError:t=>{t.currentTarget.onerror=null,t.currentTarget.src=salla.url.cdn("images/globe.svg")}}),s("span",null,a.name)))))}get host(){return e(this)}};m.style="";var g={request:(t,a,s,i=null,e=null)=>l.request({url:a,data:s,method:t.toLowerCase(),responseType:"json"}).then(i).catch(e),get:(t,a=null,s=null,i)=>l.get(t,{params:i}).then(a).catch(s),post(t,a,s=null,i=null){return this.request("post",t,a,s,i)},put(t,a,s=null,i=null){return this.request("put",t,a,s,i)},delete(t,a,s=null,i=null){return this.request("delete",t,a,s,i)},requestWithSupportAjax(t,a,s="post"){return new Promise(((i,e)=>{if(!window?.isLegacyTheme)return this.request(s,t,a,(({data:t})=>i(t)),(({response:t})=>e(t)));$.ajax({url:t,method:s.toUpperCase(),data:a,async:!1,success:function({data:t}){return i(t)},error:function({response:t}){return e(t)}})}))}},v={options:[],header:[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,a){var s,i,e,l=0,o=0;for(l=0;l<a.length;l+=1)if(new RegExp(a[l].value,"i").test(t)){if(s=new RegExp(a[l].version+"[- /:;]([\\d._]+)","i"),e="",(i=t.match(s))&&i[1]&&(i=i[1]),i)for(i=i.split(/[._]+/),o=0;o<i.length;o+=1)e+=0===o?i[o]+".":i[o];else e="0";return{name:a[l].name,version:parseFloat(e)}}return{name:"unknown",version:0}}};async function w(t,a,s=!1){if(salla.logger.log("🍏 Pay: mutateShippingContact called",a,s),t.detail.requiredShippingContactFields&&0!=t.detail.requiredShippingContactFields.length)if(s){if(salla.config.isGuest()&&salla.config.get("store.features").includes("guest-checkout")){if(!(a.emailAddress&&a.givenName&&a.familyName&&a.phoneNumber)){salla.logger.warn("🍏 Pay: Guest contact fields are required",a);const s=[];return a.emailAddress||s.push(new window.ApplePayError("shippingContactInvalid","emailAddress","Email address is required")),a.phoneNumber||s.push(new window.ApplePayError("shippingContactInvalid","phoneNumber","Phone number is required")),a.givenName&&a.familyName||s.push(new window.ApplePayError("shippingContactInvalid","name","Name is required")),void t.session.completePayment({status:t.session.STATUS_INVALID_SHIPPING_CONTACT,errors:s})}await async function(t,a){return salla.logger.log("🍏 Pay: Updating guest contact",a),new Promise(((s,i)=>{g.post(t.detail.guestContactSelected.url.replace("{id}",t.id),{email:a.emailAddress||null,first_name:a.givenName||null,last_name:a.familyName||null,phone_number:a.phoneNumber||null,country_code:a.countryCode||null},(async({data:a})=>{"function"==typeof t.detail.guestContactSelected?.onSuccess&&t.detail.guestContactSelected.onSuccess(a),s(a)}),(({response:a})=>{salla.logger.warn("🍏 Pay: Failed to update guest contact via api",a),"function"==typeof t.detail.guestContactSelected?.onFailed&&t.detail.guestContactSelected.onFailed(a),i({response:a})}))}))}(t,a)}}else if(t.detail.requiredShippingContactFields.includes("postalAddress"))return g.post(t.detail.shippingContactSelected.url.replace("{id}",t.id),{country:a.country,city:a.locality,local:a.subLocality||a.administrativeArea||a.locality,description:a.subAdministrativeArea,street:a.addressLines?.join(", ")||a.administrativeArea,country_code:a.countryCode,postal_code:a.postalCode},(async({data:a})=>{if("function"==typeof t.detail.shippingContactSelected.onSuccess&&t.detail.shippingContactSelected.onSuccess(a),t.address_id=a.data.address_id,t.shipping_methods=a.data.shipping_methods,!t.shipping_methods||t.shipping_methods&&!t.shipping_methods.length)return salla.logger.warn("🍏 Pay: We dont found any supported methods",a),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(a){return salla.logger.warn("Failed set the shipping details to api",a),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}try{await t.recalculateTotal()}catch(a){return salla.logger.warn("🍏 Pay: Failed recalculate total",a),void t.session.completeShippingContactSelection({status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}const s={newTotal:t.prepareTotal(),newLineItems:t.prepareLineItems(),newShippingMethods:t.mappingShippingMethods(t.shipping_methods)};salla.logger.log("🍏 Pay: completeShippingContactSelection",s),t.session.completeShippingContactSelection(s)}),(({response:a})=>{salla.logger.warn("🍏 Pay: Failed add address via api",a),"function"==typeof t.detail.shippingContactSelected.onFailed&&t.detail.shippingContactSelected.onFailed(a);let s=a?.data?.error?.fields,i=function(t){return Object.entries(t).filter((([t,a])=>a&&a.length>0)).map((([t,a])=>new window.ApplePayError("shippingContactInvalid",t,a[0])))}({countryCode:s?.country_code&&s.country_code.length>0?s.country_code[0]:null,locality:s?.city&&s.city.length>0?s.city[0]:null,country:s?.country&&s.country.length>0?s.country[0]:null});0===i.length&&a?.data?.error?.message&&i.push(new window.ApplePayError("shippingContactInvalid","locality",a?.data?.error?.message)),t.session.completeShippingContactSelection({newTotal:t.prepareTotal(),newLineItems:t.prepareLineItems(),status:t.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:i})}))}window.Salla=window.Salla||{},window.Salla.Payments=window.Salla.Payments||{},window.SallaApplePay={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",SallaApplePay.startSession),Salla.event.addEventListener("payments::apple-pay.start-transaction",SallaApplePay.startSession)},initDefault:function(){SallaApplePay.detail.onError||(SallaApplePay.detail.onError=function(t){salla.notify.error(t)}),SallaApplePay.detail.authorized.onFailed||(SallaApplePay.detail.authorized.onFailed=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleErrorResponse(t),SallaApplePay.onCancel({},t.data.error.message)}),SallaApplePay.detail.validateMerchant.onFailed||(SallaApplePay.detail.validateMerchant.onFailed=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleErrorResponse({response:t}),SallaApplePay.onCancel({},t.data.error.message)}),SallaApplePay.detail.authorized.onSuccess||(SallaApplePay.detail.authorized.onSuccess=t=>{salla.logger.log(JSON.stringify(t)),salla.api.handleAfterResponseActions(t)})},prepareLineItems:function(){return SallaApplePay.detail?.items?.length||(SallaApplePay.detail.items=[{label:salla.lang.get("pages.cart.items_total"),amount:parseFloat(SallaApplePay.detail.amount).toString()}]),SallaApplePay.detail.items},prepareTotal:function(){return{label:window.location.hostname||"Salla",amount:parseFloat(SallaApplePay.detail.amount).toString()}},isPhysical:()=>SallaApplePay.detail?.requiredShippingContactFields?.includes("postalAddress"),startSession:async function(t){SallaApplePay.detail=t.detail||t,salla.log("🍏 Pay: payments::apple-pay.start-transaction",SallaApplePay.detail),SallaApplePay.initDefault();let a=SallaApplePay.getApplePaySessionVersion(),s=SallaApplePay.detail.supportedNetworks||["masterCard","visa"];5===a&&s.push("mada"),SallaApplePay.request={countryCode:SallaApplePay.detail.countryCode||"SA",supportsCouponCode:!0,couponCode:"",currencyCode:SallaApplePay.detail.currency||"SAR",requiredShippingContactFields:SallaApplePay.detail.requiredShippingContactFields?SallaApplePay.detail.requiredShippingContactFields:[],merchantCapabilities:["supports3DS"],supportedNetworks:s,supportedCountries:SallaApplePay.detail.supportedCountries||["SA"],total:SallaApplePay.prepareTotal(),shippingContact:SallaApplePay.detail.shippingContact?SallaApplePay.detail.shippingContact:{},shippingMethods:SallaApplePay.detail.shippingMethods&&SallaApplePay.detail.shippingMethods.length?SallaApplePay.mappingShippingMethods(t.detail.shippingMethods):[],lineItems:SallaApplePay.prepareLineItems()},salla.log("🍏 Pay: init ",SallaApplePay.request),SallaApplePay.session=new ApplePaySession(a,SallaApplePay.request),SallaApplePay.session.onshippingcontactselected=SallaApplePay.onShippingContactSelected,SallaApplePay.session.onshippingmethodselected=SallaApplePay.onShippingMethodSelected,SallaApplePay.session.onvalidatemerchant=SallaApplePay.onValidateMerchant,SallaApplePay.session.onpaymentauthorized=SallaApplePay.onPaymentAuthorized,SallaApplePay.session.oncancel=SallaApplePay.onCancel,SallaApplePay.session.oncouponcodechanged=SallaApplePay.onCouponCodeChanged,SallaApplePay.session.onpaymentmethodselected=SallaApplePay.onPaymentMethodSelected,SallaApplePay.session.begin()},onPaymentMethodSelected:async t=>{if(salla.logger.log("🍏 Pay: onPaymentMethodSelected",t),SallaApplePay.isPhysical())salla.logger.log("🍏 Pay: completePaymentMethodSelection",{newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()}),SallaApplePay.session.completePaymentMethodSelection({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()});else try{await SallaApplePay.recalculateTotal();const t={newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()};salla.logger.log("🍏 Pay: completePaymentMethodSelection",t),SallaApplePay.session.completePaymentMethodSelection(t)}catch(t){salla.logger.warn("🍏 Pay: Failed recalculate total",t),SallaApplePay.session.completePaymentMethodSelection({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems(),status:SallaApplePay.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),g.post(SallaApplePay.detail.onCouponCodeChanged.url.replace("{id}",SallaApplePay.id),{coupon:t.couponCode,payment_method:"apple_pay"},(async({data:t})=>{"function"==typeof SallaApplePay.detail.onCouponCodeChanged.onSuccess&&SallaApplePay.detail.onCouponCodeChanged.onSuccess(t),salla.log("🍏 Pay: Coupon applied success"),await SallaApplePay.recalculateTotal(),SallaApplePay.session.completeCouponCodeChange({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()})}),(async t=>{let a=t?.response;Salla.event.dispatch("payments::apple-pay.coupon.failed",a),"function"==typeof SallaApplePay.detail.onCouponCodeChanged.onFailed&&SallaApplePay.detail.onCouponCodeChanged.onFailed(a),await SallaApplePay.recalculateTotal(),SallaApplePay.session.completeCouponCodeChange({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems(),errors:[new window.ApplePayError("couponCodeInvalid")]})}))),onCancel:(t={},a=null)=>{SallaApplePay.detail.onError(a||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 w(SallaApplePay,t.payment.shippingContact,!0)}catch(t){salla.logger.error("🍏 Pay: Failed to update guest contact details",t);const a=t?.response||t,s=a?.data?.error?.fields||{},i=[];return s?.email&&s.email.length>0&&i.push(new window.ApplePayError("shippingContactInvalid","emailAddress",s.email[0])),s?.phone&&s.phone.length>0&&i.push(new window.ApplePayError("shippingContactInvalid","phoneNumber",s.phone[0])),s?.first_name&&s.first_name.length>0?i.push(new window.ApplePayError("shippingContactInvalid","name",s.first_name[0])):s?.last_name&&s.last_name.length>0&&i.push(new window.ApplePayError("shippingContactInvalid","name",s.last_name[0])),0===i.length&&i.push(new window.ApplePayError("shippingContactInvalid","name",a?.data?.error?.message||a?.data?.error?.code||"Invalid shipping contact details")),Salla.event.dispatch("payments::apple-pay.authorized.failed",a),"function"==typeof SallaApplePay.detail.authorized.onFailed&&SallaApplePay.detail.authorized.onFailed(a),void SallaApplePay.session.completePayment({status:ApplePaySession.STATUS_INVALID_SHIPPING_CONTACT,errors:i})}Salla.event.dispatch("payments::apple-pay.authorized.init",t),g.post(SallaApplePay.detail.authorized.url.replace("{id}",SallaApplePay.id),{payment_method:"apple_pay",applepay_token:JSON.stringify(t.payment)},(({data:t})=>{Salla.event.dispatch("payments::apple-pay.authorized.success",t),"function"==typeof SallaApplePay.detail.authorized.onSuccess&&SallaApplePay.detail.authorized.onSuccess(t),SallaApplePay.session.completePayment(ApplePaySession.STATUS_SUCCESS)}),(t=>{let a=t?.response;Salla.event.dispatch("payments::apple-pay.authorized.failed",a),"function"==typeof SallaApplePay.detail.authorized.onFailed&&SallaApplePay.detail.authorized.onFailed(a),SallaApplePay.session.completePayment({status:ApplePaySession.STATUS_FAILURE,errors:[new window.ApplePayError("unknown",void 0,a?.data?.error?.message||a?.data?.error?.code||"Failed to parse authorized response")]})}))},onValidateMerchant:async t=>{try{Salla.event.dispatch("payments::apple-pay.validate-merchant.init",t);const{data:a}=await g.post(SallaApplePay.detail.validateMerchant.url.replace("{id}",SallaApplePay.id),{validation_url:t.validationURL});Salla.event.dispatch("payments::apple-pay.validate-merchant.success",a);const s=t=>{SallaApplePay.session.completeMerchantValidation(t)};if("function"==typeof SallaApplePay.detail.validateMerchant.onSuccess){const t=await SallaApplePay.detail.validateMerchant.onSuccess(a);if(t?.redirect)return window.location=t.redirect,SallaApplePay.abortValidateMerchant(t)}s(a.data)}catch(t){console.error(t),SallaApplePay.abortValidateMerchant(t?.response)}},abortValidateMerchant:(t=null)=>{SallaApplePay.abortSession(),Salla.event.dispatch("payments::apple-pay.validate-merchant.failed",t),"function"==typeof SallaApplePay.detail.validateMerchant.onFailed&&SallaApplePay.detail.validateMerchant.onFailed(t)},onShippingContactSelected:async t=>{salla.logger.log("🍏 Pay: onShippingContactSelected",t.shippingContact),await w(SallaApplePay,t.shippingContact)},onShippingMethodSelected:async t=>{let a=t.shippingMethod.identifier.split(","),s={ship_id:a[0],private_ship_id:void 0===a[1]?null:a[1],type:void 0===a[2]?null:a[2],route_id:void 0===a[3]?null:a[3]};if(salla.logger.log("🍏 Pay: onShippingMethodSelected",{event:t,previous:SallaApplePay.shippingCompany,current:s}),SallaApplePay.shouldUpdateShippingCompany(s))try{await SallaApplePay.selectApplePayShippingMethod(s),await SallaApplePay.recalculateTotal()}catch(t){return salla.logger.warn("🍏 Pay: Failed set the shipping details to api",t),void SallaApplePay.session.completeShippingMethodSelection({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems(),status:SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,errors:[new window.ApplePayError("addressUnserviceable")]})}salla.logger.log("🍏 Pay: completeShippingMethodSelection",{newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()}),SallaApplePay.session.completeShippingMethodSelection({newTotal:SallaApplePay.prepareTotal(),newLineItems:SallaApplePay.prepareLineItems()})},abortSession:()=>{SallaApplePay.session&&SallaApplePay.session.abort()},shouldUpdateShippingCompany:t=>SallaApplePay.shippingCompany?.ship_id!=t?.ship_id||SallaApplePay.shippingCompany?.private_ship_id!=t?.private_ship_id,getApplePaySessionVersion:()=>{if("sallapp"===(navigator.userAgent||navigator.vendor||window.opera))return 5;let t=v.init(),a=parseFloat(t.os.version);if("Macintosh"===t.os.name){if(a<10.142)return 1}else if(a<12.11)return 1;return 5},recalculateTotal:()=>(salla.logger.log("🍏 Pay: recalculate total"),g.get(SallaApplePay.detail.recalculateTotal.url.replace("{id}",SallaApplePay.id),(({data:t})=>{salla.logger.log("🍏 Pay: recalculate total success",t);let a=t.data.initial_data?.cart||t.data.cart,s=t.data.initial_data?.payments||t.data.payments;salla.logger.log("🍏 Pay: recalculate total success",{cart:a,payments:s}),SallaApplePay.detail.amount=s?.gateways?.applePay?.supportedMultiCurrency?a.total_in_customer_currency:a.total,SallaApplePay.detail.items=(a.totals||a.items).map((t=>({label:t.title,amount:"مجاني"===t.amount||"Free"===t.amount?0:t.amount.toString().replace("+","")}))),SallaApplePay.detail.items.pop(),SallaApplePay.totals=SallaApplePay.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),SallaApplePay.shippingCompany=t;const a={address_id:SallaApplePay.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 g.post(SallaApplePay.detail.shippingMethodSelected.url.replace("{id}",SallaApplePay.id),a,(({data:t})=>("function"==typeof SallaApplePay.detail.shippingMethodSelected.onSuccess&&SallaApplePay.detail.shippingMethodSelected.onSuccess(t),!0)),(t=>{salla.logger.warn("🍏 Pay: Set shipping method failed",t),"function"==typeof SallaApplePay.detail.shippingMethodSelected.onFailed&&SallaApplePay.detail.shippingMethodSelected.onFailed(t);let a=t?.response?.data?.error;return a?.data?.fields?.address_id?a?.data?.fields?.address_id[0]:a?.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:"")})))},window.ApplePaySession?.canMakePayments()?SallaApplePay.init():document.querySelectorAll("data-show-if-apple-pay-supported").forEach((t=>t.style.display="none"));const S=class{constructor(s){t(this,s),this.validationFailed=a(this,"validationFailed"),this.requireLogin=a(this,"requireLogin"),this.type="buy",this.productType="product",this.options={},this.quickBuy=salla.lang.get("pages.products.buy_now"),salla.lang.onLoaded((()=>{this.quickBuy=salla.lang.get("pages.products.buy_now")}))}async quickBuyHandler(){if(salla.config.isGuest()&&!this.isGuestCheckout()){this.requireLogin.emit({productId:this.productId});let t="salla-quick-buy::user.logged-in";return salla.event.on(t,(()=>this.settlePayment())),salla.api.auth.setAfterLoginEvent(t),salla.auth.event.dispatch("login::open",{withoutReload:!0})}await this.settlePayment()}async settlePayment(){let t=document.querySelector(`salla-product-options[product-id="${this.productId}"]`);if(t&&!await t.reportValidity())return this.validationFailed.emit({productId:this.productId}),salla.error(salla.lang.get("common.messages.required_fields"));let a=this.host.getElementSallaData();if(!this.isApplePayActive)return salla.api.request("checkout/quick-purchase/"+this.productId,a,"post").then((t=>(t.data.redirect&&(window.location.href=t.data.redirect),t)));a.is_applepay=!0,"append"in a&&a.append("is_applepay",!0),salla.event.dispatch("payments::apple-pay.start-transaction",{amount:this.amount,currency:this.currency||"SAR",requiredShippingContactFields:this.getRequiredShippingContactFields(),shippingMethods:this.isRequireShipping?[]:void 0,supportedNetworks:salla.config.get("store.settings.buy_now.networks"),supportedCountries:salla.config.get("store.settings.buy_now.countries"),countryCode:salla.config.get("store.store_country")||"SA",validateMerchant:{url:this.validateHost?`${this.validateHost}/checkout/applepay/validate`:salla.url.get("checkout/applepay/validate"),onSuccess:t=>this.applePayOnly&&!this.productId?this.cartId?(window.SallaApplePay.id=this.cartId,salla.log("🍏 Pay: create checkout success: with id #"+this.cartId),Promise.resolve(t)):(salla.logger.warn("🍏 Pay: trying to create applePay transaction without cartId/ProductId !"),Promise.resolve(t)):salla.api.request("checkout/quick-purchase/"+this.productId,"object"==typeof a?a: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}componentWillLoad(){console.log("🍏 Pay: Quick Buy Component Loaded");const t="undefined"!=typeof window&&!!window.ApplePaySession?.canMakePayments?.(),a=salla?.config?.get?.("store.settings.payments")?.includes?.("apple_pay")??!0,s=salla?.config?.get?.("store.settings.is_salla_gateway",!1)??!0;this.isApplePayActive=t&&a&&s;const i=async()=>{if(!this.currency&&salla?.config?.get&&(this.currency=salla.config.get("store.settings.buy_now.multi_currency")?salla.config.get("user.currency_code"):"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.amount=t.data.price,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.amount=t.price)})):salla?.url?.is_page?.("product.single")&&salla?.product?.event?.onPriceUpdated&&salla.product.event.onPriceUpdated((t=>{this.amount=t.data.price})),this.isApplePayActive=(salla?.helpers?.hasApplePay?.()??t)&&(salla?.config?.get?.("store.settings.payments")?.includes?.("apple_pay")??a)&&(salla?.config?.get?.("store.settings.is_salla_gateway",!1)??s),!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((()=>i().then((()=>t(!0))))):i().then((()=>t(!0)))}))}render(){return s(i,{key:"88125eb8c3bb1e1b016f39ea84ce6234267587a4"},this.quickBuyButton())}quickBuyButton(){return s("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)}};S.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{c as salla_add_product_button,h as salla_product_availability,m as salla_product_options,S as salla_quick_buy}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as e,h as s}from"./p-DcD0Zbyk.js";import{G as l}from"./p-OF8QcbMM.js";const a=class{constructor(s){e(this,s),this.minAge=10,this.isEditable=!0,this.disableAction=!1,this.isLoading=!0,this.first_name_trans=salla.lang.get("pages.profile.first_name"),this.last_name_trans=salla.lang.get("pages.profile.last_name"),this.birthday_trans=salla.lang.get("pages.profile.birthday"),this.birthday_placeholder_trans=salla.lang.get("pages.profile.birthday_placeholder"),this.gender_trans=salla.lang.get("pages.profile.gender"),this.gender_placeholder_trans=salla.lang.get("pages.profile.gender_placeholder"),this.male_trans=salla.lang.get("pages.profile.male"),this.female_trans=salla.lang.get("pages.profile.female"),this.email_trans=salla.lang.get("common.elements.email"),this.mobile_trans=salla.lang.get("common.elements.mobile"),this.save_btn_trans=salla.lang.get("common.elements.save"),this.drag_and_drop_trans=salla.lang.get("common.uploader.drag_and_drop"),this.browse_trans=salla.lang.get("common.uploader.browse"),this.email_required_trans=salla.lang.get("pages.checkout.email_required"),this.invalid_email_trans=salla.lang.get("pages.error.invalid_value",{attribute:"email"}),salla.lang.onLoaded((()=>{this.first_name_trans=salla.lang.get("pages.profile.first_name"),this.last_name_trans=salla.lang.get("pages.profile.last_name"),this.birthday_trans=salla.lang.get("pages.profile.birthday"),this.birthday_placeholder_trans=salla.lang.get("pages.profile.birthday_placeholder"),this.gender_trans=salla.lang.get("pages.profile.gender"),this.gender_placeholder_trans=salla.lang.get("pages.profile.gender_placeholder"),this.male_trans=salla.lang.get("pages.profile.male"),this.female_trans=salla.lang.get("pages.profile.female"),this.email_trans=salla.lang.get("common.elements.email"),this.mobile_trans=salla.lang.get("common.elements.mobile"),this.save_btn_trans=salla.lang.get("common.elements.save"),this.drag_and_drop_trans=salla.lang.get("common.uploader.drag_and_drop"),this.browse_trans=salla.lang.get("common.uploader.browse"),this.email_required_trans=salla.lang.get("pages.checkout.email_required"),this.invalid_email_trans=salla.lang.get("pages.error.invalid_value",{attribute:"email"})}))}phoneNumberFieldEventHandler(e){e.detail.number?(this.userData.phone.number=Number.parseInt(e.detail.number),this.userData.phone.country=e.detail.country_code,this.disableAction=!1):this.disableAction=!0}handleFieldChange(e,s,l=!1){s.target.value?(this.userData[e]=s.target.value,this.disableAction=!1):l&&(this.disableAction=!0)}handleEmailInput(e,s){const l=document.getElementById("email-error"),a=s.target.value;if(!a)return this.disableAction=!0,void(l.textContent=this.email_required_trans);/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(a)||(this.disableAction=!0,l.textContent=this.invalid_email_trans),l.textContent="",this.userData[e]=a,this.disableAction=!1}submitForm(e){e.preventDefault(),this.disableAction=!0;const s=Object.assign({},this.userData);s.phone=void 0,s.phone=this.userData.phone.number,s.country_code=this.userData.phone.country,salla.api.profile.update(s).finally((()=>{this.disableAction=!1}))}getBirthDateRestriction(){const e=new Date,s=e.getFullYear()-this.minAge;return e.setFullYear(s),e}fetchData(){return salla.api.profile.info().then((e=>{this.userData=e.data})).finally((()=>{this.isLoading=!1,this.isEditable=!Salla.config.get("store.features").includes("sso-login")}))}renderLoadingSection(){return s("div",{class:"s-user-profile-skeleton-wrapper"},Array.from({length:6},((e,l)=>s("salla-skeleton",{class:"skeleton-item",width:"100%",height:"50px",key:l}))))}componentWillLoad(){Salla.onReady().then((()=>this.fetchData()))}render(){return this.isLoading?this.renderLoadingSection():s("form",{onSubmit:e=>this.submitForm(e)},s("div",{class:"s-user-profile-wrapper"},s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"first-name",class:"s-user-profile-field-label"},this.first_name_trans),s("input",{disabled:!this.isEditable,type:"text",name:"first_name",value:this.userData.first_name,id:"first-name",required:!0,autocomplete:"first_name",class:"form-input",onChange:e=>this.handleFieldChange("first_name",e)})),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"last-name",class:"s-user-profile-field-label"},this.last_name_trans),s("input",{disabled:!this.isEditable,type:"text",name:"last_name",value:this.userData.last_name,id:"last-name",required:!0,autocomplete:"last_name",class:"form-input",onChange:e=>this.handleFieldChange("last_name",e)})),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"birthday",class:"s-user-profile-field-label"},this.birthday_trans),s("salla-datetime-picker",{disabled:!this.isEditable,dateFormat:"Y-m-d",value:this.userData.birthday,placeholder:this.birthday_placeholder_trans,required:!0,maxDate:this.getBirthDateRestriction(),name:"birthday",onPicked:e=>this.handleFieldChange("birthday",e)})),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"gender",class:"s-user-profile-field-label"},this.gender_trans),s("select",{disabled:!this.isEditable,class:"form-input",name:"gender",required:!0,onChange:e=>this.handleFieldChange("gender",e)},s("option",{value:""},this.gender_placeholder_trans),s("option",{value:l.Male,selected:this.userData.gender===l.Male},this.male_trans),s("option",{value:l.Female,selected:this.userData.gender===l.Female},this.female_trans))),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"email",class:"s-user-profile-field-label"},this.email_trans),s("input",{disabled:!this.isEditable,type:"email",name:"email",value:this.userData.email,id:"email",class:"form-input",required:!0,onInput:e=>this.handleEmailInput("email",e)}),s("p",{id:"email-error",class:"s-user-profile-field-error"})),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"international-mobile",class:"s-user-profile-field-label"},this.mobile_trans),s("salla-tel-input",{disabled:!this.isEditable,name:"international-mobile","country-code":this.userData.phone.country,phone:`${this.userData.phone.number}`,onPhoneEntered:e=>this.phoneNumberFieldEventHandler(e)}))),s("salla-button",{type:"submit",loading:this.disableAction,disabled:this.disableAction||!this.isEditable,"loader-position":"end",class:"s-user-profile-submit"},this.save_btn_trans))}};a.style=":host{display:block}";export{a as salla_user_profile}
4
+ import{r as e,h as s}from"./p-CV1rqKQz.js";import{G as l}from"./p-OF8QcbMM.js";const a=class{constructor(s){e(this,s),this.minAge=10,this.isEditable=!0,this.disableAction=!1,this.isLoading=!0,this.first_name_trans=salla.lang.get("pages.profile.first_name"),this.last_name_trans=salla.lang.get("pages.profile.last_name"),this.birthday_trans=salla.lang.get("pages.profile.birthday"),this.birthday_placeholder_trans=salla.lang.get("pages.profile.birthday_placeholder"),this.gender_trans=salla.lang.get("pages.profile.gender"),this.gender_placeholder_trans=salla.lang.get("pages.profile.gender_placeholder"),this.male_trans=salla.lang.get("pages.profile.male"),this.female_trans=salla.lang.get("pages.profile.female"),this.email_trans=salla.lang.get("common.elements.email"),this.mobile_trans=salla.lang.get("common.elements.mobile"),this.save_btn_trans=salla.lang.get("common.elements.save"),this.drag_and_drop_trans=salla.lang.get("common.uploader.drag_and_drop"),this.browse_trans=salla.lang.get("common.uploader.browse"),this.email_required_trans=salla.lang.get("pages.checkout.email_required"),this.invalid_email_trans=salla.lang.get("pages.error.invalid_value",{attribute:"email"}),salla.lang.onLoaded((()=>{this.first_name_trans=salla.lang.get("pages.profile.first_name"),this.last_name_trans=salla.lang.get("pages.profile.last_name"),this.birthday_trans=salla.lang.get("pages.profile.birthday"),this.birthday_placeholder_trans=salla.lang.get("pages.profile.birthday_placeholder"),this.gender_trans=salla.lang.get("pages.profile.gender"),this.gender_placeholder_trans=salla.lang.get("pages.profile.gender_placeholder"),this.male_trans=salla.lang.get("pages.profile.male"),this.female_trans=salla.lang.get("pages.profile.female"),this.email_trans=salla.lang.get("common.elements.email"),this.mobile_trans=salla.lang.get("common.elements.mobile"),this.save_btn_trans=salla.lang.get("common.elements.save"),this.drag_and_drop_trans=salla.lang.get("common.uploader.drag_and_drop"),this.browse_trans=salla.lang.get("common.uploader.browse"),this.email_required_trans=salla.lang.get("pages.checkout.email_required"),this.invalid_email_trans=salla.lang.get("pages.error.invalid_value",{attribute:"email"})}))}phoneNumberFieldEventHandler(e){e.detail.number?(this.userData.phone.number=Number.parseInt(e.detail.number),this.userData.phone.country=e.detail.country_code,this.disableAction=!1):this.disableAction=!0}handleFieldChange(e,s,l=!1){s.target.value?(this.userData[e]=s.target.value,this.disableAction=!1):l&&(this.disableAction=!0)}handleEmailInput(e,s){const l=document.getElementById("email-error"),a=s.target.value;if(!a)return this.disableAction=!0,void(l.textContent=this.email_required_trans);/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(a)||(this.disableAction=!0,l.textContent=this.invalid_email_trans),l.textContent="",this.userData[e]=a,this.disableAction=!1}submitForm(e){e.preventDefault(),this.disableAction=!0;const s=Object.assign({},this.userData);s.phone=void 0,s.phone=this.userData.phone.number,s.country_code=this.userData.phone.country,salla.api.profile.update(s).finally((()=>{this.disableAction=!1}))}getBirthDateRestriction(){const e=new Date,s=e.getFullYear()-this.minAge;return e.setFullYear(s),e}fetchData(){return salla.api.profile.info().then((e=>{this.userData=e.data})).finally((()=>{this.isLoading=!1,this.isEditable=!Salla.config.get("store.features").includes("sso-login")}))}renderLoadingSection(){return s("div",{class:"s-user-profile-skeleton-wrapper"},Array.from({length:6},((e,l)=>s("salla-skeleton",{class:"skeleton-item",width:"100%",height:"50px",key:l}))))}componentWillLoad(){Salla.onReady().then((()=>this.fetchData()))}render(){return this.isLoading?this.renderLoadingSection():s("form",{onSubmit:e=>this.submitForm(e)},s("div",{class:"s-user-profile-wrapper"},s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"first-name",class:"s-user-profile-field-label"},this.first_name_trans),s("input",{disabled:!this.isEditable,type:"text",name:"first_name",value:this.userData.first_name,id:"first-name",required:!0,autocomplete:"first_name",class:"form-input",onChange:e=>this.handleFieldChange("first_name",e)})),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"last-name",class:"s-user-profile-field-label"},this.last_name_trans),s("input",{disabled:!this.isEditable,type:"text",name:"last_name",value:this.userData.last_name,id:"last-name",required:!0,autocomplete:"last_name",class:"form-input",onChange:e=>this.handleFieldChange("last_name",e)})),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"birthday",class:"s-user-profile-field-label"},this.birthday_trans),s("salla-datetime-picker",{disabled:!this.isEditable,dateFormat:"Y-m-d",value:this.userData.birthday,placeholder:this.birthday_placeholder_trans,required:!0,maxDate:this.getBirthDateRestriction(),name:"birthday",onPicked:e=>this.handleFieldChange("birthday",e)})),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"gender",class:"s-user-profile-field-label"},this.gender_trans),s("select",{disabled:!this.isEditable,class:"form-input",name:"gender",required:!0,onChange:e=>this.handleFieldChange("gender",e)},s("option",{value:""},this.gender_placeholder_trans),s("option",{value:l.Male,selected:this.userData.gender===l.Male},this.male_trans),s("option",{value:l.Female,selected:this.userData.gender===l.Female},this.female_trans))),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"email",class:"s-user-profile-field-label"},this.email_trans),s("input",{disabled:!this.isEditable,type:"email",name:"email",value:this.userData.email,id:"email",class:"form-input",required:!0,onInput:e=>this.handleEmailInput("email",e)}),s("p",{id:"email-error",class:"s-user-profile-field-error"})),s("div",{class:"s-user-profile-field"},s("label",{htmlFor:"international-mobile",class:"s-user-profile-field-label"},this.mobile_trans),s("salla-tel-input",{disabled:!this.isEditable,name:"international-mobile","country-code":this.userData.phone.country,phone:`${this.userData.phone.number}`,onPhoneEntered:e=>this.phoneNumberFieldEventHandler(e)}))),s("salla-button",{type:"submit",loading:this.disableAction,disabled:this.disableAction||!this.isEditable,"loader-position":"end",class:"s-user-profile-submit"},this.save_btn_trans))}};a.style=":host{display:block}";export{a as salla_user_profile}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as a,h as t,H as s,a as e}from"./p-DcD0Zbyk.js";const i=class{constructor(t){if(a(this,t),this.entity="product",this.specs=[],this.download=salla.lang.get("pages.thank_you.download"),this.entityId)try{return void(this.entityId=Array.isArray(this.entityId)?this.entityId:JSON.parse(this.entityId))}catch(a){salla.log("Bad json passed via entityId prop")}}getValue(a){if("file"===a.type)return`<a href="${a.value}" class="text-primary" target="_blank"><span class="sicon-download"></span> ${this.download}</a>`;if("url"===a.type)return`<a href="${a.value}" class="text-blue-700 underline" target="_blank">${a.value}</a>`;if("date"===a.type){const t=new Date(a.value);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}return a.value}async componentWillLoad(){if(await salla.onReady(),!salla.config.get("store.features")?.includes("custom-fields"))return salla.logger.error("feature custom-fields is not activated");if(this.entityId||!salla.url.is_page("product.single")&&!salla.url.is_page("product.showNewUrls")||(this.entityId=salla.config.get("page.id")),!this.entityId)return salla.logger.error("can't render salla-metadata without enity-id prop!");await salla.lang.onLoaded(),this.download=salla.lang.get("pages.thank_you.download");const a=await Salla.api.metadata.fetchValues(this.entity,this.entityId);this.specs=a.data[0]?.sections}render(){if(this.specs.length)return t(s,{class:"s-metadata-wrapper"},this.specs.map((a=>t("div",{class:"s-metadata-box"},t("div",{class:"s-metadata-box-header"},t("i",{class:"sicon-list"}),a.name),a.fields.map((a=>t("div",{class:"s-metadata-row"},t("p",{class:"s-metadata-row-name"},a.name),t("p",{class:"s-metadata-row-value",innerHTML:this.getValue(a)}))))))))}get host(){return e(this)}};i.style="";export{i as salla_metadata}
4
+ import{r as a,h as t,H as s,a as e}from"./p-CV1rqKQz.js";const i=class{constructor(t){if(a(this,t),this.entity="product",this.specs=[],this.download=salla.lang.get("pages.thank_you.download"),this.entityId)try{return void(this.entityId=Array.isArray(this.entityId)?this.entityId:JSON.parse(this.entityId))}catch(a){salla.log("Bad json passed via entityId prop")}}getValue(a){if("file"===a.type)return`<a href="${a.value}" class="text-primary" target="_blank"><span class="sicon-download"></span> ${this.download}</a>`;if("url"===a.type)return`<a href="${a.value}" class="text-blue-700 underline" target="_blank">${a.value}</a>`;if("date"===a.type){const t=new Date(a.value);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}return a.value}async componentWillLoad(){if(await salla.onReady(),!salla.config.get("store.features")?.includes("custom-fields"))return salla.logger.error("feature custom-fields is not activated");if(this.entityId||!salla.url.is_page("product.single")&&!salla.url.is_page("product.showNewUrls")||(this.entityId=salla.config.get("page.id")),!this.entityId)return salla.logger.error("can't render salla-metadata without enity-id prop!");await salla.lang.onLoaded(),this.download=salla.lang.get("pages.thank_you.download");const a=await Salla.api.metadata.fetchValues(this.entity,this.entityId);this.specs=a.data[0]?.sections}render(){if(this.specs.length)return t(s,{class:"s-metadata-wrapper"},this.specs.map((a=>t("div",{class:"s-metadata-box"},t("div",{class:"s-metadata-box-header"},t("i",{class:"sicon-list"}),a.name),a.fields.map((a=>t("div",{class:"s-metadata-row"},t("p",{class:"s-metadata-row-name"},a.name),t("p",{class:"s-metadata-row-value",innerHTML:this.getValue(a)}))))))))}get host(){return e(this)}};i.style="";export{i as salla_metadata}
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as s,h as t}from"./p-DcD0Zbyk.js";const r=class{constructor(t){s(this,t),this.height="10px";try{if(this.donation){let s="string"==typeof this.donation?JSON.parse(this.donation):this.donation;s.can_donate&&s.target_amount?(s.target_end_date="0000-00-00"==s.target_end_date?null:s.target_end_date,this.value=s.collected_amount,this.target=s.target_amount,this.header=salla.lang.get("pages.products.target"),this.message=s.target_end_date?salla.lang.get("pages.products.donation_target_date")+" "+s.target_end_date:""):this.message=s.target_amount?s.target_message:""}}catch(s){salla.log("Wrong donation json")}salla.lang.onLoaded((()=>{this.header=this.header?.replace("pages.products.target",salla.lang.get("pages.products.target")),this.message=this.message?.replace("pages.products.donation_target_date",salla.lang.get("pages.products.donation_target_date"))})),salla.onReady((()=>{this.color=this.color||salla.config.get("theme.color.primary","#ffd5c4"),this.unit||(this.unit=salla.config.currency().symbol)}))}getPercentage(){return this.value/this.target*100}render(){return this.target||this.message?t("div",{class:"s-progress-bar-container"},this.header?t("div",{class:"s-progress-bar-header"},this.header):"",this.getProgressBar(),this.message?t("span",{class:"s-progress-bar-message"},this.message):""):""}getProgressBar(){return this.target?[this.hideUnits?null:t("div",{class:"s-progress-bar-target-section"},t("span",{innerHTML:`${salla.helpers.number(this.value)} ${this.unit}`}),t("span",{innerHTML:`${salla.helpers.number(this.target)} ${this.unit}`})),t("div",{class:"s-progress-bar-wrapper",style:{height:this.height}},t("div",{class:{"s-progress-bar-progress":!0,"s-progress-bar-progress-stripped":this.stripped},style:{width:`${this.getPercentage()}%`,backgroundColor:this.color}}))]:null}};r.style="";export{r as salla_progress_bar}
4
+ import{r as s,h as t}from"./p-CV1rqKQz.js";const r=class{constructor(t){s(this,t),this.height="10px";try{if(this.donation){let s="string"==typeof this.donation?JSON.parse(this.donation):this.donation;s.can_donate&&s.target_amount?(s.target_end_date="0000-00-00"==s.target_end_date?null:s.target_end_date,this.value=s.collected_amount,this.target=s.target_amount,this.header=salla.lang.get("pages.products.target"),this.message=s.target_end_date?salla.lang.get("pages.products.donation_target_date")+" "+s.target_end_date:""):this.message=s.target_amount?s.target_message:""}}catch(s){salla.log("Wrong donation json")}salla.lang.onLoaded((()=>{this.header=this.header?.replace("pages.products.target",salla.lang.get("pages.products.target")),this.message=this.message?.replace("pages.products.donation_target_date",salla.lang.get("pages.products.donation_target_date"))})),salla.onReady((()=>{this.color=this.color||salla.config.get("theme.color.primary","#ffd5c4"),this.unit||(this.unit=salla.config.currency().symbol)}))}getPercentage(){return this.value/this.target*100}render(){return this.target||this.message?t("div",{class:"s-progress-bar-container"},this.header?t("div",{class:"s-progress-bar-header"},this.header):"",this.getProgressBar(),this.message?t("span",{class:"s-progress-bar-message"},this.message):""):""}getProgressBar(){return this.target?[this.hideUnits?null:t("div",{class:"s-progress-bar-target-section"},t("span",{innerHTML:`${salla.helpers.number(this.value)} ${this.unit}`}),t("span",{innerHTML:`${salla.helpers.number(this.target)} ${this.unit}`})),t("div",{class:"s-progress-bar-wrapper",style:{height:this.height}},t("div",{class:{"s-progress-bar-progress":!0,"s-progress-bar-progress-stripped":this.stripped},style:{width:`${this.getPercentage()}%`,backgroundColor:this.color}}))]:null}};r.style="";export{r as salla_progress_bar}