@salla.sa/twilight-components 2.14.296 → 2.14.298

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 (147) hide show
  1. package/dist/cjs/{filepond-E7NOvLwV.js → filepond-Dn-jnnWy.js} +1 -1
  2. package/dist/cjs/{filepond-plugin-file-poster-D3bKYBq5.js → filepond-plugin-file-poster-4K4RC5sx.js} +1 -1
  3. package/dist/cjs/{filepond-plugin-file-validate-size-D4sJa2nT.js → filepond-plugin-file-validate-size-B85pytvJ.js} +1 -1
  4. package/dist/cjs/{filepond-plugin-file-validate-type-DDz99ei0.js → filepond-plugin-file-validate-type-vWh-hrFq.js} +1 -1
  5. package/dist/cjs/{filepond-plugin-image-edit-yDHuyk0R.js → filepond-plugin-image-edit-B3-_-hIs.js} +1 -1
  6. package/dist/cjs/{filepond-plugin-image-exif-orientation-hj89JJI_.js → filepond-plugin-image-exif-orientation-Cbkb7_k1.js} +1 -1
  7. package/dist/cjs/{filepond-plugin-image-preview-UoTioUkG.js → filepond-plugin-image-preview-CqcNMHtt.js} +1 -1
  8. package/dist/cjs/{index-BfEIQrIk.js → index-DENUwtYT.js} +2 -2
  9. package/dist/cjs/{index-BZQAN2JT.js → index-Z2nWod3c.js} +1 -1
  10. package/dist/cjs/loader.cjs.js +2 -2
  11. package/dist/cjs/salla-accordion_62.cjs.entry.js +41 -32
  12. package/dist/cjs/salla-advertisement.cjs.entry.js +28 -6
  13. package/dist/cjs/salla-app-install-alert.cjs.entry.js +1 -1
  14. package/dist/cjs/salla-apps-icons.cjs.entry.js +1 -1
  15. package/dist/cjs/salla-cart-item-offers.cjs.entry.js +1 -1
  16. package/dist/cjs/salla-conditional-offer.cjs.entry.js +1 -1
  17. package/dist/cjs/salla-contacts.cjs.entry.js +1 -1
  18. package/dist/cjs/salla-custom-fields.cjs.entry.js +1 -1
  19. package/dist/cjs/salla-filters-widget.cjs.entry.js +1 -1
  20. package/dist/cjs/salla-filters.cjs.entry.js +1 -1
  21. package/dist/cjs/salla-installment.cjs.entry.js +1 -1
  22. package/dist/cjs/salla-loyalty-prize-item.cjs.entry.js +1 -1
  23. package/dist/cjs/salla-loyalty-program.cjs.entry.js +1 -1
  24. package/dist/cjs/salla-metadata.cjs.entry.js +1 -1
  25. package/dist/cjs/salla-notification-item.cjs.entry.js +1 -1
  26. package/dist/cjs/salla-notifications.cjs.entry.js +1 -1
  27. package/dist/cjs/salla-offer.cjs.entry.js +1 -1
  28. package/dist/cjs/salla-order-details-multiple-bundle-product.cjs.entry.js +1 -1
  29. package/dist/cjs/salla-order-details-options.cjs.entry.js +1 -1
  30. package/dist/cjs/salla-order-details.cjs.entry.js +1 -1
  31. package/dist/cjs/salla-order-summary.cjs.entry.js +1 -1
  32. package/dist/cjs/salla-order-totals-card.cjs.entry.js +1 -1
  33. package/dist/cjs/salla-orders.cjs.entry.js +1 -1
  34. package/dist/cjs/salla-payments.cjs.entry.js +1 -1
  35. package/dist/cjs/salla-price-range.cjs.entry.js +1 -1
  36. package/dist/cjs/salla-review-card.cjs.entry.js +1 -1
  37. package/dist/cjs/salla-reviews-page.cjs.entry.js +1 -1
  38. package/dist/cjs/salla-reviews.cjs.entry.js +1 -1
  39. package/dist/cjs/salla-social.cjs.entry.js +1 -1
  40. package/dist/cjs/salla-tiered-offer.cjs.entry.js +1 -1
  41. package/dist/cjs/salla-tooltip.cjs.entry.js +1 -1
  42. package/dist/cjs/salla-trust-badges.cjs.entry.js +1 -1
  43. package/dist/cjs/salla-verify.cjs.entry.js +1 -1
  44. package/dist/cjs/salla-wallet.cjs.entry.js +1 -1
  45. package/dist/cjs/twilight.cjs.js +2 -2
  46. package/dist/collection/components/salla-advertisement/salla-advertisement.js +27 -5
  47. package/dist/collection/components/salla-multiple-bundle-product/components/salla-multiple-bundle-product-details.js +4 -4
  48. package/dist/collection/components/salla-multiple-bundle-product/components/salla-multiple-bundle-product-slider.js +12 -9
  49. package/dist/collection/components/salla-user-menu/salla-user-menu.js +17 -10
  50. package/dist/components/index.js +2 -2
  51. package/dist/components/salla-advertisement.js +27 -5
  52. package/dist/components/salla-multiple-bundle-product-details2.js +4 -4
  53. package/dist/components/salla-multiple-bundle-product-slider2.js +12 -9
  54. package/dist/components/salla-user-menu.js +17 -10
  55. package/dist/esm/{filepond-plugin-file-poster-B7t9aVVy.js → filepond-plugin-file-poster-CAkqJrqM.js} +1 -1
  56. package/dist/esm/{filepond-plugin-file-validate-size-DFkfdHfo.js → filepond-plugin-file-validate-size-lHUJVKW0.js} +1 -1
  57. package/dist/esm/{filepond-plugin-file-validate-type-CU-RnplM.js → filepond-plugin-file-validate-type-FHDAVW2X.js} +1 -1
  58. package/dist/esm/{filepond-plugin-image-edit-Dz3oYXef.js → filepond-plugin-image-edit-drdbdxxE.js} +1 -1
  59. package/dist/esm/{filepond-plugin-image-exif-orientation-DJrUnj97.js → filepond-plugin-image-exif-orientation-Kqs0PJBo.js} +1 -1
  60. package/dist/esm/{filepond-plugin-image-preview-BCWlifYd.js → filepond-plugin-image-preview-BZGs88rC.js} +1 -1
  61. package/dist/esm/{filepond-BEN4Pt87.js → filepond-q8kfR-qI.js} +1 -1
  62. package/dist/esm/{index-bXg2F_NN.js → index-Bh2SK07N.js} +2 -2
  63. package/dist/esm/{index-fxSENfiU.js → index-CPlWMNOm.js} +1 -1
  64. package/dist/esm/loader.js +3 -3
  65. package/dist/esm/salla-accordion_62.entry.js +41 -32
  66. package/dist/esm/salla-advertisement.entry.js +28 -6
  67. package/dist/esm/salla-app-install-alert.entry.js +1 -1
  68. package/dist/esm/salla-apps-icons.entry.js +1 -1
  69. package/dist/esm/salla-cart-item-offers.entry.js +1 -1
  70. package/dist/esm/salla-conditional-offer.entry.js +1 -1
  71. package/dist/esm/salla-contacts.entry.js +1 -1
  72. package/dist/esm/salla-custom-fields.entry.js +1 -1
  73. package/dist/esm/salla-filters-widget.entry.js +1 -1
  74. package/dist/esm/salla-filters.entry.js +1 -1
  75. package/dist/esm/salla-installment.entry.js +1 -1
  76. package/dist/esm/salla-loyalty-prize-item.entry.js +1 -1
  77. package/dist/esm/salla-loyalty-program.entry.js +1 -1
  78. package/dist/esm/salla-metadata.entry.js +1 -1
  79. package/dist/esm/salla-notification-item.entry.js +1 -1
  80. package/dist/esm/salla-notifications.entry.js +1 -1
  81. package/dist/esm/salla-offer.entry.js +1 -1
  82. package/dist/esm/salla-order-details-multiple-bundle-product.entry.js +1 -1
  83. package/dist/esm/salla-order-details-options.entry.js +1 -1
  84. package/dist/esm/salla-order-details.entry.js +1 -1
  85. package/dist/esm/salla-order-summary.entry.js +1 -1
  86. package/dist/esm/salla-order-totals-card.entry.js +1 -1
  87. package/dist/esm/salla-orders.entry.js +1 -1
  88. package/dist/esm/salla-payments.entry.js +1 -1
  89. package/dist/esm/salla-price-range.entry.js +1 -1
  90. package/dist/esm/salla-review-card.entry.js +1 -1
  91. package/dist/esm/salla-reviews-page.entry.js +1 -1
  92. package/dist/esm/salla-reviews.entry.js +1 -1
  93. package/dist/esm/salla-social.entry.js +1 -1
  94. package/dist/esm/salla-tiered-offer.entry.js +1 -1
  95. package/dist/esm/salla-tooltip.entry.js +1 -1
  96. package/dist/esm/salla-trust-badges.entry.js +1 -1
  97. package/dist/esm/salla-verify.entry.js +1 -1
  98. package/dist/esm/salla-wallet.entry.js +1 -1
  99. package/dist/esm/twilight.js +3 -3
  100. package/dist/twilight/{p-8220b125.entry.js → p-0d04ca56.entry.js} +1 -1
  101. package/dist/twilight/{p-fa379f1e.entry.js → p-11d325ba.entry.js} +1 -1
  102. package/dist/twilight/{p-0645c8e3.entry.js → p-1863db37.entry.js} +1 -1
  103. package/dist/twilight/{p-732c5190.entry.js → p-3f62e05b.entry.js} +1 -1
  104. package/dist/twilight/{p-4fb7f400.entry.js → p-4c74e526.entry.js} +1 -1
  105. package/dist/twilight/{p-1b7cfbae.entry.js → p-4df42ff8.entry.js} +1 -1
  106. package/dist/twilight/{p-d08cedb0.entry.js → p-5460b611.entry.js} +2 -2
  107. package/dist/twilight/{p-5f247331.entry.js → p-5789243f.entry.js} +1 -1
  108. package/dist/twilight/{p-56dde07a.entry.js → p-5981c13b.entry.js} +1 -1
  109. package/dist/twilight/{p-e4418e6f.entry.js → p-5f46651c.entry.js} +1 -1
  110. package/dist/twilight/{p-ef9ac6cb.entry.js → p-5f815dc4.entry.js} +1 -1
  111. package/dist/twilight/{p-dcd9e688.entry.js → p-62fd72e0.entry.js} +1 -1
  112. package/dist/twilight/{p-dd84065f.entry.js → p-6891ae55.entry.js} +1 -1
  113. package/dist/twilight/{p-c691fd39.entry.js → p-7d3b2c8d.entry.js} +1 -1
  114. package/dist/twilight/{p-0b970445.entry.js → p-842debd3.entry.js} +1 -1
  115. package/dist/twilight/{p-51ef83f7.entry.js → p-85d168c9.entry.js} +1 -1
  116. package/dist/twilight/{p-c848e1d3.entry.js → p-8d246fcd.entry.js} +1 -1
  117. package/dist/twilight/{p-988ea6cb.entry.js → p-8f481f80.entry.js} +1 -1
  118. package/dist/twilight/{p-c5afe02a.entry.js → p-99b49b76.entry.js} +1 -1
  119. package/dist/twilight/{p-a6ebba30.entry.js → p-9d46ba91.entry.js} +1 -1
  120. package/dist/twilight/{p-CoLlt5es.js → p-B0jU8m7y.js} +1 -1
  121. package/dist/twilight/{p-CP2LDZCD.js → p-BLPRGu3L.js} +1 -1
  122. package/dist/twilight/{p-k3nBgoPC.js → p-BcA-Dpxf.js} +1 -1
  123. package/dist/twilight/{p-bXg2F_NN.js → p-Bh2SK07N.js} +1 -1
  124. package/dist/twilight/{p-CWkLySV3.js → p-CtJEHiDh.js} +1 -1
  125. package/dist/twilight/{p-1Xk7fjpB.js → p-DFYs0E0K.js} +1 -1
  126. package/dist/twilight/{p-CD5i_50p.js → p-DykGR1vx.js} +1 -1
  127. package/dist/twilight/{p-BW8LVXVp.js → p-HMoEZhqa.js} +2 -2
  128. package/dist/twilight/{p-32512487.entry.js → p-af92eed9.entry.js} +1 -1
  129. package/dist/twilight/{p-c88d32f0.entry.js → p-b2548a59.entry.js} +1 -1
  130. package/dist/twilight/{p-67ed25a4.entry.js → p-b2ab5fcc.entry.js} +1 -1
  131. package/dist/twilight/{p-fcd1344e.entry.js → p-b4127acc.entry.js} +1 -1
  132. package/dist/twilight/{p-7012bda9.entry.js → p-c31e0731.entry.js} +1 -1
  133. package/dist/twilight/{p-ef3a4d3e.entry.js → p-c69d87e4.entry.js} +1 -1
  134. package/dist/twilight/{p-76657684.entry.js → p-ccfd9c1e.entry.js} +1 -1
  135. package/dist/twilight/{p-f4549e2e.entry.js → p-cef92263.entry.js} +1 -1
  136. package/dist/twilight/p-d6c99665.entry.js +4 -0
  137. package/dist/twilight/{p-8d3f2028.entry.js → p-dbce8093.entry.js} +1 -1
  138. package/dist/twilight/{p-5dd1b37c.entry.js → p-de903389.entry.js} +1 -1
  139. package/dist/twilight/{p-193bea42.entry.js → p-e23f38dc.entry.js} +1 -1
  140. package/dist/twilight/{p-4dd68813.entry.js → p-e584c46f.entry.js} +1 -1
  141. package/dist/twilight/{p-22f479da.entry.js → p-ecddf6ff.entry.js} +1 -1
  142. package/dist/twilight/{p-BIRmkG1d.js → p-sK70mswA.js} +1 -1
  143. package/dist/twilight/twilight.esm.js +1 -1
  144. package/dist/types/components/salla-advertisement/salla-advertisement.d.ts +1 -1
  145. package/dist/types/components/salla-user-menu/salla-user-menu.d.ts +2 -1
  146. package/package.json +5 -5
  147. package/dist/twilight/p-9f42e27b.entry.js +0 -4
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as s,h as e,a as t}from"./p-bXg2F_NN.js";var i,r;!function(s){s.ProductDetail="product.single",s.Cart="cart"}(i||(i={})),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"}(r||(r={}));const a=class{constructor(e){s(this,e),this.productCardComponent="custom-salla-product-card",this.offersList=[],this.isMultipleBank=!1,this.isBankOffer=!1,this.canRender=!1,this.showOffer=salla.config.get("store.settings.product.show_special_offers"),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.multipleBankOfferTitleText=salla.lang.get("pages.offer.multiple_bank_offers_title"),this.multipleBankOfferTitleDescription=salla.lang.get("pages.offer.multiple_bank_offers_message"),this.buy_quantity_text=s=>salla.lang.get("pages.offer.buy_quantity",{quantity:s}),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.multipleBankOfferTitleText=salla.lang.get("pages.offer.multiple_bank_offers_title"),this.multipleBankOfferTitleDescription=salla.lang.get("pages.offer.multiple_bank_offers_message"),this.buy_quantity_text(0)})),salla.onReady((()=>{this.currentPage=salla.config.get("page.slug"),this.userCurrency=salla.config.get("currencies")[salla.config.get("user.currency_code")].symbol})),this.categorySlot=this.host.querySelector('[slot="category"]')?.innerHTML||'<a href={url} class="s-offer-slide-cat-entry"><i class={icon}></i><h4>{name}</h4></a>'}async getEndpointByPageName(){return this.currentPage==i.Cart?`offers/cart/${await Salla.cart.getCurrentCartId()}`:this.currentPage==i.ProductDetail?`offers/product/${salla.config.get("page.id")}`:"offers"}emitPromotionViewed(){this.offersList.length&&this.canRender&&this.showOffer&&salla.event.emit("promotion::viewed",[{id:this.offersList[0].id,name:this.offersList[0].title,creative:this.offersList[0].description||"",position:1}])}emitPromotionClicked(s=1){this.offersList.length&&this.canRender&&this.showOffer&&salla.event.emit("promotion::clicked",[{id:this.offersList[0].id,name:this.offersList[0].title,creative:this.offersList[0].description||"",position:s}])}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((s=>{if(!(this.offersList=s.data).length)throw new Error("salla-offers:: There is no offers!");const e=this.offersList.find((s=>[r.SpecialPrice,r.Bank,r.BuyXGetY,r.DiscountsTable].includes(s.type)));if(!e)throw new Error("salla-offers:: Offer type not supported yet!");if(e.type===r.DiscountsTable)return this.offersList=[e];if(this.isBankOffer=e.type===r.Bank)return this.offersList=this.offersList.filter((s=>s.type===r.Bank)),this.isMultipleBank=this.offersList.length>1,this.offersList;if(e.type===r.SpecialPrice){const s=e.details;return"product"===s.apply_to?salla.product.api.fetch({source:"selected",source_value:s.targets}).then((s=>(e.details.products=s.data,this.offersList=[e]))):salla.product.api.categories().then((t=>{const i=this.findCategories(t.data,s.targets);return e.details.categories=i,this.offersList=[e]}))}const t=e.details.get;return"products"===t.source?salla.product.api.fetch({source:"selected",source_value:t.source_value}).then((s=>(t.products=s.data,e.details.get=t,this.offersList=[e]))):salla.product.api.categories().then((s=>(t.categories=this.findCategories(s.data,t.source_value),e.details.get=t,this.offersList=[e])))})).then((s=>{salla.storage.set(this.getStorageKey(),{offers:s,stored_at:(new Date).getTime()}),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,e){let t=[];for(const i of s)e.includes(i.id_||i.id)&&t.push(i),i.sub_categories?.length>0&&(t=t.concat(this.findCategories(i.sub_categories,e)));return t}getStorageKey(){try{const s=salla.config.get("page.slug").replace(".","_"),e=salla.lang.getLocale(),t=salla.config.currency().code;if(!s||!e||!t)throw new Error("Unable to get the storage key.");return`s-offers-${s}-${salla.config.get("page.id")}-${e}-${t}`}catch(s){return""}}getOffersFromStorage(){let s=salla.storage.get(this.getStorageKey());return!s||s.stored_at<(new Date).getTime()-6e5?(salla.storage.remove(this.getStorageKey()),null):(this.canRender=!0,Promise.resolve(s.offers))}render(){if(!this.offersList.length||!this.canRender||!this.showOffer)return null;const s=this.offersList[0],t={"block-title":this.isBankOffer?this.isMultipleBank?this.multipleBankOfferTitleText:null:s.title,"block-subTitle":this.isBankOffer?this.isMultipleBank?this.multipleBankOfferTitleDescription:null:s.description,"show-controls":this.isMultipleBank};return e("div",{class:"s-offer-wrapper",onClick:()=>this.emitPromotionClicked()},e("p",{class:"s-offer-corner-badge"},this.special_offer_text),e("salla-slider",{type:"carousel",id:"offer-slider",...t},e("div",{slot:"items"},this.renderSectionForOfferType(s.type))))}renderSectionForOfferType(s){return this.isBankOffer?this.renderBankSection():s==r.SpecialPrice?this.renderSpecialPriceSection():s==r.BuyXGetY?this.renderBuyXGetYSection():this.renderDiscountTableSection()}getCategoriesSection(s){return e("div",{class:"s-offer-slide-one-sixth swiper-slide",innerHTML:this.categorySlot.replace(/\{url\}/g,s.url).replace(/\{icon\}/g,s.icon||"sicon-store").replace(/\{name\}/g,s.name)})}renderBuyXGetYSection(){const s=this.offersList[0].details;return[s.get.products?.map((s=>e("div",{class:"s-offer-slide-one-fourth"},this.hasCustomComponent?e(this.productCardComponent,{product:s}):e("salla-product-card",{"shadow-on-hover":!0,product:s})))),s.get.categories?.map((s=>this.getCategoriesSection(s)))]}renderBankSection(){return this.offersList.map((s=>e("div",{class:{"s-offer-slide-one-sixth":this.isMultipleBank,"s-offer-bank-wrapper-sinlge-item":!this.isMultipleBank}},e("div",{class:{"s-offer-bank-wrapper":!0,"s-offer-slide-one-sixth":!this.isMultipleBank,"s-offer-bank-wrapper-multi-spacer":this.isMultipleBank}},e("div",{class:"s-offer-bank-logo"},e("img",{src:s.details.logo||salla.url.cdn("images/s-empty.png"),"data-src":s.details.logo,alt:s.title+" offer"})),e("ul",{class:"s-offer-bank-payment-wrapper"},s.details.payments.map((s=>e("li",{class:"s-offer-bank-payment-single"},e("img",{src:salla.url.cdn("images/payment/"+s+".png")||salla.url.cdn("images/s-empty.png"),"data-src":salla.url.cdn("images/payment/"+s+".png"),alt:"payment"}))))),this.isMultipleBank?e("p",{class:"s-offer-bank-payment-discount-percent"},`${this.product_discount_text} ${s.details.discount_value}${"percentage"===s.details.discount_type&&"%"}`):""),this.isMultipleBank?"":e("div",{class:"s-offer-bank-message s-offer-slide-one-fourth"},e("h2",null,this.offersList[0].title),e("p",{innerHTML:this.generateBankDescription(this.offersList[0].description,s.details.discount_value)})))))}generateBankDescription(s,e){return s.replace(new RegExp(`${e} %`),`<span class="s-offer-bank-message-amount">${e} %</span>`)}renderDiscountTableSection(){let s=this.offersList[0].details.show_price_after_discount;return this.offersList[0].details.discounts?.map((t=>e("div",{class:"s-offer-slide-one-fourth"},e("div",{class:"s-offer-slide-offer-entry"},e("div",{class:"s-offer-slide-offer-entry-price-quantity-container"},e("p",{class:"s-offer-slide-offer-entry-quantity"},this.buy_quantity_text(t.quantity)),s?e("div",{class:"s-offer-slide-offer-entry-price"},e("span",null,this.offer_with_price_text),e("span",{class:"s-offer-slide-offer-entry-price-amount"},t.discounted_amount)," ",e("span",null,this.userCurrency)):""),e("p",{class:"s-offer-slide-offer-entry-price-amount-percent"},this.with_discount_text,"(",e("span",null,t.percentage,!!t.percentage&&"%"),")")))))}renderSpecialPriceSection(){const s=this.offersList[0].details;return["product"===s.apply_to&&s.products?.map((s=>e("div",{class:"s-offer-slide-one-fourth"},this.hasCustomComponent?e(this.productCardComponent,{product:s}):e("salla-product-card",{"shadow-on-hover":!0,product:s})))),"category"===s.apply_to&&s.categories?.map((s=>this.getCategoriesSection(s)))]}get host(){return t(this)}};a.style='.s-offer-wrapper .s-slider-block__title h2{font-size:1.125rem;line-height:1.75rem;color:#f87171}.s-offer-wrapper .s-slider-block__title h2::before{font-family:"sallaicons";content:"\\ee30" !important;position:absolute;top:1rem;font-size:3rem;font-weight:400;line-height:1;color:#fef2f2}.s-offer-bank-wrapper-sinlge-item{display:flex;align-items:center !important;gap:14px}.s-offer-bank-wrapper{display:flex !important;width:100% !important}';export{a as salla_offer}
4
+ import{r as s,h as e,a as t}from"./p-Bh2SK07N.js";var i,r;!function(s){s.ProductDetail="product.single",s.Cart="cart"}(i||(i={})),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"}(r||(r={}));const a=class{constructor(e){s(this,e),this.productCardComponent="custom-salla-product-card",this.offersList=[],this.isMultipleBank=!1,this.isBankOffer=!1,this.canRender=!1,this.showOffer=salla.config.get("store.settings.product.show_special_offers"),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.multipleBankOfferTitleText=salla.lang.get("pages.offer.multiple_bank_offers_title"),this.multipleBankOfferTitleDescription=salla.lang.get("pages.offer.multiple_bank_offers_message"),this.buy_quantity_text=s=>salla.lang.get("pages.offer.buy_quantity",{quantity:s}),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.multipleBankOfferTitleText=salla.lang.get("pages.offer.multiple_bank_offers_title"),this.multipleBankOfferTitleDescription=salla.lang.get("pages.offer.multiple_bank_offers_message"),this.buy_quantity_text(0)})),salla.onReady((()=>{this.currentPage=salla.config.get("page.slug"),this.userCurrency=salla.config.get("currencies")[salla.config.get("user.currency_code")].symbol})),this.categorySlot=this.host.querySelector('[slot="category"]')?.innerHTML||'<a href={url} class="s-offer-slide-cat-entry"><i class={icon}></i><h4>{name}</h4></a>'}async getEndpointByPageName(){return this.currentPage==i.Cart?`offers/cart/${await Salla.cart.getCurrentCartId()}`:this.currentPage==i.ProductDetail?`offers/product/${salla.config.get("page.id")}`:"offers"}emitPromotionViewed(){this.offersList.length&&this.canRender&&this.showOffer&&salla.event.emit("promotion::viewed",[{id:this.offersList[0].id,name:this.offersList[0].title,creative:this.offersList[0].description||"",position:1}])}emitPromotionClicked(s=1){this.offersList.length&&this.canRender&&this.showOffer&&salla.event.emit("promotion::clicked",[{id:this.offersList[0].id,name:this.offersList[0].title,creative:this.offersList[0].description||"",position:s}])}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((s=>{if(!(this.offersList=s.data).length)throw new Error("salla-offers:: There is no offers!");const e=this.offersList.find((s=>[r.SpecialPrice,r.Bank,r.BuyXGetY,r.DiscountsTable].includes(s.type)));if(!e)throw new Error("salla-offers:: Offer type not supported yet!");if(e.type===r.DiscountsTable)return this.offersList=[e];if(this.isBankOffer=e.type===r.Bank)return this.offersList=this.offersList.filter((s=>s.type===r.Bank)),this.isMultipleBank=this.offersList.length>1,this.offersList;if(e.type===r.SpecialPrice){const s=e.details;return"product"===s.apply_to?salla.product.api.fetch({source:"selected",source_value:s.targets}).then((s=>(e.details.products=s.data,this.offersList=[e]))):salla.product.api.categories().then((t=>{const i=this.findCategories(t.data,s.targets);return e.details.categories=i,this.offersList=[e]}))}const t=e.details.get;return"products"===t.source?salla.product.api.fetch({source:"selected",source_value:t.source_value}).then((s=>(t.products=s.data,e.details.get=t,this.offersList=[e]))):salla.product.api.categories().then((s=>(t.categories=this.findCategories(s.data,t.source_value),e.details.get=t,this.offersList=[e])))})).then((s=>{salla.storage.set(this.getStorageKey(),{offers:s,stored_at:(new Date).getTime()}),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,e){let t=[];for(const i of s)e.includes(i.id_||i.id)&&t.push(i),i.sub_categories?.length>0&&(t=t.concat(this.findCategories(i.sub_categories,e)));return t}getStorageKey(){try{const s=salla.config.get("page.slug").replace(".","_"),e=salla.lang.getLocale(),t=salla.config.currency().code;if(!s||!e||!t)throw new Error("Unable to get the storage key.");return`s-offers-${s}-${salla.config.get("page.id")}-${e}-${t}`}catch(s){return""}}getOffersFromStorage(){let s=salla.storage.get(this.getStorageKey());return!s||s.stored_at<(new Date).getTime()-6e5?(salla.storage.remove(this.getStorageKey()),null):(this.canRender=!0,Promise.resolve(s.offers))}render(){if(!this.offersList.length||!this.canRender||!this.showOffer)return null;const s=this.offersList[0],t={"block-title":this.isBankOffer?this.isMultipleBank?this.multipleBankOfferTitleText:null:s.title,"block-subTitle":this.isBankOffer?this.isMultipleBank?this.multipleBankOfferTitleDescription:null:s.description,"show-controls":this.isMultipleBank};return e("div",{class:"s-offer-wrapper",onClick:()=>this.emitPromotionClicked()},e("p",{class:"s-offer-corner-badge"},this.special_offer_text),e("salla-slider",{type:"carousel",id:"offer-slider",...t},e("div",{slot:"items"},this.renderSectionForOfferType(s.type))))}renderSectionForOfferType(s){return this.isBankOffer?this.renderBankSection():s==r.SpecialPrice?this.renderSpecialPriceSection():s==r.BuyXGetY?this.renderBuyXGetYSection():this.renderDiscountTableSection()}getCategoriesSection(s){return e("div",{class:"s-offer-slide-one-sixth swiper-slide",innerHTML:this.categorySlot.replace(/\{url\}/g,s.url).replace(/\{icon\}/g,s.icon||"sicon-store").replace(/\{name\}/g,s.name)})}renderBuyXGetYSection(){const s=this.offersList[0].details;return[s.get.products?.map((s=>e("div",{class:"s-offer-slide-one-fourth"},this.hasCustomComponent?e(this.productCardComponent,{product:s}):e("salla-product-card",{"shadow-on-hover":!0,product:s})))),s.get.categories?.map((s=>this.getCategoriesSection(s)))]}renderBankSection(){return this.offersList.map((s=>e("div",{class:{"s-offer-slide-one-sixth":this.isMultipleBank,"s-offer-bank-wrapper-sinlge-item":!this.isMultipleBank}},e("div",{class:{"s-offer-bank-wrapper":!0,"s-offer-slide-one-sixth":!this.isMultipleBank,"s-offer-bank-wrapper-multi-spacer":this.isMultipleBank}},e("div",{class:"s-offer-bank-logo"},e("img",{src:s.details.logo||salla.url.cdn("images/s-empty.png"),"data-src":s.details.logo,alt:s.title+" offer"})),e("ul",{class:"s-offer-bank-payment-wrapper"},s.details.payments.map((s=>e("li",{class:"s-offer-bank-payment-single"},e("img",{src:salla.url.cdn("images/payment/"+s+".png")||salla.url.cdn("images/s-empty.png"),"data-src":salla.url.cdn("images/payment/"+s+".png"),alt:"payment"}))))),this.isMultipleBank?e("p",{class:"s-offer-bank-payment-discount-percent"},`${this.product_discount_text} ${s.details.discount_value}${"percentage"===s.details.discount_type&&"%"}`):""),this.isMultipleBank?"":e("div",{class:"s-offer-bank-message s-offer-slide-one-fourth"},e("h2",null,this.offersList[0].title),e("p",{innerHTML:this.generateBankDescription(this.offersList[0].description,s.details.discount_value)})))))}generateBankDescription(s,e){return s.replace(new RegExp(`${e} %`),`<span class="s-offer-bank-message-amount">${e} %</span>`)}renderDiscountTableSection(){let s=this.offersList[0].details.show_price_after_discount;return this.offersList[0].details.discounts?.map((t=>e("div",{class:"s-offer-slide-one-fourth"},e("div",{class:"s-offer-slide-offer-entry"},e("div",{class:"s-offer-slide-offer-entry-price-quantity-container"},e("p",{class:"s-offer-slide-offer-entry-quantity"},this.buy_quantity_text(t.quantity)),s?e("div",{class:"s-offer-slide-offer-entry-price"},e("span",null,this.offer_with_price_text),e("span",{class:"s-offer-slide-offer-entry-price-amount"},t.discounted_amount)," ",e("span",null,this.userCurrency)):""),e("p",{class:"s-offer-slide-offer-entry-price-amount-percent"},this.with_discount_text,"(",e("span",null,t.percentage,!!t.percentage&&"%"),")")))))}renderSpecialPriceSection(){const s=this.offersList[0].details;return["product"===s.apply_to&&s.products?.map((s=>e("div",{class:"s-offer-slide-one-fourth"},this.hasCustomComponent?e(this.productCardComponent,{product:s}):e("salla-product-card",{"shadow-on-hover":!0,product:s})))),"category"===s.apply_to&&s.categories?.map((s=>this.getCategoriesSection(s)))]}get host(){return t(this)}};a.style='.s-offer-wrapper .s-slider-block__title h2{font-size:1.125rem;line-height:1.75rem;color:#f87171}.s-offer-wrapper .s-slider-block__title h2::before{font-family:"sallaicons";content:"\\ee30" !important;position:absolute;top:1rem;font-size:3rem;font-weight:400;line-height:1;color:#fef2f2}.s-offer-bank-wrapper-sinlge-item{display:flex;align-items:center !important;gap:14px}.s-offer-bank-wrapper{display:flex !important;width:100% !important}';export{a as salla_offer}