@salla.sa/twilight-components 2.13.73 → 2.13.75

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 (68) hide show
  1. package/dist/cjs/app-globals-b7d4e7fe.js.map +1 -1
  2. package/dist/cjs/salla-add-product-button_48.cjs.entry.js.map +1 -1
  3. package/dist/cjs/salla-conditional-offer.cjs.entry.js +4 -1
  4. package/dist/cjs/salla-conditional-offer.cjs.entry.js.map +1 -1
  5. package/dist/cjs/salla-installment.cjs.entry.js +6 -4
  6. package/dist/cjs/salla-installment.cjs.entry.js.map +1 -1
  7. package/dist/cjs/salla-product-options.cjs.entry.js +1 -1
  8. package/dist/cjs/salla-product-options.cjs.entry.js.map +1 -1
  9. package/dist/collection/components/salla-conditional-offer/salla-conditional-offer.js +4 -1
  10. package/dist/collection/components/salla-conditional-offer/salla-conditional-offer.js.map +1 -1
  11. package/dist/collection/components/salla-installment/salla-installment.js +6 -4
  12. package/dist/collection/components/salla-installment/salla-installment.js.map +1 -1
  13. package/dist/collection/components/salla-product-options/salla-product-options.js +1 -1
  14. package/dist/collection/components/salla-product-options/salla-product-options.js.map +1 -1
  15. package/dist/components/index.js.map +1 -1
  16. package/dist/components/salla-conditional-offer.js +4 -1
  17. package/dist/components/salla-conditional-offer.js.map +1 -1
  18. package/dist/components/salla-installment.js +6 -4
  19. package/dist/components/salla-installment.js.map +1 -1
  20. package/dist/components/salla-product-options.js +1 -1
  21. package/dist/components/salla-product-options.js.map +1 -1
  22. package/dist/components/salla-quick-buy2.js.map +1 -1
  23. package/dist/esm/app-globals-d8ab32b4.js.map +1 -1
  24. package/dist/esm/salla-add-product-button_48.entry.js.map +1 -1
  25. package/dist/esm/salla-conditional-offer.entry.js +4 -1
  26. package/dist/esm/salla-conditional-offer.entry.js.map +1 -1
  27. package/dist/esm/salla-installment.entry.js +6 -4
  28. package/dist/esm/salla-installment.entry.js.map +1 -1
  29. package/dist/esm/salla-product-options.entry.js +1 -1
  30. package/dist/esm/salla-product-options.entry.js.map +1 -1
  31. package/dist/esm-es5/app-globals-d8ab32b4.js.map +1 -1
  32. package/dist/esm-es5/salla-add-product-button_48.entry.js.map +1 -1
  33. package/dist/esm-es5/salla-conditional-offer.entry.js +1 -1
  34. package/dist/esm-es5/salla-conditional-offer.entry.js.map +1 -1
  35. package/dist/esm-es5/salla-installment.entry.js +1 -1
  36. package/dist/esm-es5/salla-installment.entry.js.map +1 -1
  37. package/dist/esm-es5/salla-product-options.entry.js +1 -1
  38. package/dist/esm-es5/salla-product-options.entry.js.map +1 -1
  39. package/dist/twilight/p-104b415a.entry.js +5 -0
  40. package/dist/twilight/p-104b415a.entry.js.map +1 -0
  41. package/dist/twilight/p-2425ba38.entry.js +5 -0
  42. package/dist/twilight/p-2425ba38.entry.js.map +1 -0
  43. package/dist/twilight/{p-a0258069.entry.js → p-2cb87af3.entry.js} +2 -2
  44. package/dist/twilight/p-2cb87af3.entry.js.map +1 -0
  45. package/dist/twilight/p-5b1f4cd6.system.entry.js.map +1 -1
  46. package/dist/twilight/p-8d4ecfda.system.entry.js +5 -0
  47. package/dist/twilight/p-8d4ecfda.system.entry.js.map +1 -0
  48. package/dist/twilight/p-8e070ed6.js.map +1 -1
  49. package/dist/twilight/p-918de2be.entry.js.map +1 -1
  50. package/dist/twilight/p-963a9e0e.system.js +1 -1
  51. package/dist/twilight/p-ad60936a.system.entry.js +5 -0
  52. package/dist/twilight/p-ad60936a.system.entry.js.map +1 -0
  53. package/dist/twilight/{p-0022fccc.system.entry.js → p-c63f84a6.system.entry.js} +2 -2
  54. package/dist/twilight/p-c63f84a6.system.entry.js.map +1 -0
  55. package/dist/twilight/p-dad29c6b.system.js.map +1 -1
  56. package/dist/twilight/twilight.esm.js +1 -1
  57. package/package.json +5 -5
  58. package/dist/twilight/p-0022fccc.system.entry.js.map +0 -1
  59. package/dist/twilight/p-2f042e66.system.entry.js +0 -5
  60. package/dist/twilight/p-2f042e66.system.entry.js.map +0 -1
  61. package/dist/twilight/p-4e2a8d73.entry.js +0 -5
  62. package/dist/twilight/p-4e2a8d73.entry.js.map +0 -1
  63. package/dist/twilight/p-5f361320.entry.js +0 -5
  64. package/dist/twilight/p-5f361320.entry.js.map +0 -1
  65. package/dist/twilight/p-80998bed.system.entry.js +0 -5
  66. package/dist/twilight/p-80998bed.system.entry.js.map +0 -1
  67. package/dist/twilight/p-a0258069.entry.js.map +0 -1
  68. package/dist/types/global.d.ts +0 -20
@@ -1,5 +1,5 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as registerInstance,h,H as Host}from"./index-114c614f.js";var DiscountType;(function(e){e["PERCENTAGE"]="percentage";e["FIXED"]="fixed";e["FREE_PRODUCT"]="free_product"})(DiscountType||(DiscountType={}));var OfferType;(function(e){e["PRODUCT_COUNT"]="products_count";e["PRODUCT_PURCHASE"]="order_amount"})(OfferType||(OfferType={}));var sallaConditionalOfferCss=":host{display:block}";var SallaConditionalOffer=function(){function e(e){registerInstance(this,e);this.offer=null;this.products={};this.isLoading=true;this.canRender=true}e.prototype.componentWillLoad=function(){var e=this;salla.onReady().then((function(){var e,t,n;if(!((e=salla.config.get("store.features"))===null||e===void 0?void 0:e.includes("conditional-offer"))||!((n=(t=salla.storage.get("cart"))===null||t===void 0?void 0:t.summary)===null||n===void 0?void 0:n.count)){throw new Error("feature or cart object does not existed")}})).then((function(){return salla.api.cart.offers()})).then((function(t){var n=t.data;e.offer=n.find((function(e){return e.type==="conditional"}));e.offer.details.discounts.unshift({value:0,min_spend:0});return e.updateInitialOfferValue()})).then((function(){return e.getProducts()})).then((function(){return salla.event.on("cart::updated",(function(t){return e.updateOfferValues(t)}))})).catch((function(t){e.canRender=false;salla.logger.error("salla-conditional-offer:: Error",t)})).finally((function(){e.isLoading=false}))};e.prototype.getProducts=function(){var e=this;var t=this.offer.details.discounts.filter((function(e){var t=e.type;return t===DiscountType.FREE_PRODUCT})).map((function(e){var t=e.value;return t}));if(t.length>0){return salla.product.fetch({source:"selected",source_value:t}).then((function(t){var n=t.data;n.forEach((function(t){var n=t.id,i=t.url,o=t.image;e.products[n]={url:i,image:o}}))}))}};e.prototype.updateInitialOfferValue=function(){var e=this;return salla.api.cart.details().then((function(t){var n=t.data.cart;return e.updateOfferValues(n)}))};e.prototype.updateOfferValues=function(e){var t=e.items,n=e.total;var i;var o=this.offer.details.based_on===OfferType.PRODUCT_COUNT?t.reduce((function(e,t){var n=t.quantity;return e+n}),0):n;this.offer=Object.assign(Object.assign({},this.offer),{details:Object.assign(Object.assign({},(i=this.offer)===null||i===void 0?void 0:i.details),{current_value:o})});return this.offer};e.prototype.getCheckpointContent=function(e){var t,n;if(e.type===DiscountType.PERCENTAGE)return"".concat(e.value,"%");if(e.type===DiscountType.FIXED)return salla.money(e.value);if(e.type!==DiscountType.FREE_PRODUCT){salla.logger.error("salla-conditional-offer:: unexpected type (".concat(e.type,")!"));return""}var i=this.products[e.value];if(!i){salla.logger.error("salla-conditional-offer:: there is no product with id (".concat(e.value,")!"));return""}return h("a",{class:"s-conditional-offer-product-link",href:i.url},h("img",{class:"s-conditional-offer-checkpoint-image-content",loading:"lazy",decoding:"async",alt:((t=i===null||i===void 0?void 0:i.image)===null||t===void 0?void 0:t.alt)||"",src:(n=i===null||i===void 0?void 0:i.image)===null||n===void 0?void 0:n.url}))};e.prototype.getOfferType=function(e){var t;var n=(t=this.offer.details)===null||t===void 0?void 0:t.based_on;if(n===OfferType.PRODUCT_COUNT)return salla.lang.choice("blocks.header.products_count",e.min_spend);if(n===OfferType.PRODUCT_PURCHASE)return salla.money(e.min_spend);salla.logger.warn("salla-conditional-offer:: Unexpected offer detail's based_on value: ".concat(n));return"".concat(e.min_spend)};e.prototype.clamp=function(e,t,n){return Math.max(t,Math.min(e,n))};e.prototype.mapValueRanges=function(e,t,n,i,o){var r=(e-t)*(o-i)/(n-t)+i;if(r===Number.POSITIVE_INFINITY)return 100;if(r===Number.NEGATIVE_INFINITY)return 0;return this.clamp(r,0,100)};e.prototype.getCheckPointView=function(e,t){var n,i;var o=this.offer.details.discounts.findIndex((function(t){var n=t.min_spend;return n===e.min_spend}));var r=(i=(n=this.offer.details.discounts[o-1])===null||n===void 0?void 0:n.min_spend)!==null&&i!==void 0?i:0;var a=this.mapValueRanges(this.offer.details.current_value,r,e.min_spend,0,100);var s=e.min_spend<=this.offer.details.current_value;return h("div",{class:"s-conditional-offer-checkpoint-container"},t>0?[h("div",{key:"progress-line",class:"s-conditional-offer-progress-line-container"},h("div",{class:"s-conditional-offer-progress-line-inactive"}),h("div",{class:"s-conditional-offer-progress-line-active",style:{width:"".concat(a,"%")}})),h("div",{key:"checkpoint",class:"s-conditional-offer-checkpoint ".concat(s?"s-conditional-offer-active-checkpoint":"")},h("div",{class:"s-conditional-offer-item-avatar-content ".concat(s?"active":"")},this.products&&this.getCheckpointContent(e)),h("div",{class:"s-conditional-offer-checkpoint-label ".concat(s?"active":""),innerHTML:this.getOfferType(e)}))]:h("div",{key:"label",class:{"s-conditional-offer-checkpoint-label":true,"first-checkpoint":t===0,active:s},innerHTML:this.getOfferType(e)}))};e.prototype.getLoadingSkeletonView=function(){return h(Host,{class:"s-conditional-offer-container "},h("div",{class:"s-conditional-offer-skeleton-wrapper"},h("div",{class:"s-conditional-offer-skeleton-title"},h("salla-skeleton",{height:"16px",width:"30%"})),h("div",{class:"s-conditional-offer-skeleton-subtitle"},h("salla-skeleton",{height:"16px",width:"35%"})),h("div",{class:"s-conditional-offer-skeleton-checkpoints-wrapper"},Array(3).fill(null).map((function(){return[h("salla-skeleton",{key:"checkpoint-line",height:"8px"}),h("div",{class:"s-conditional-offer-skeleton-checkpoint",key:"checkpoint"},h("salla-skeleton",{height:"60px",width:"60px",type:"circle"}))]})))))};e.prototype.render=function(){var e=this;if(!this.canRender)return null;if(this.isLoading)return this.getLoadingSkeletonView();return h(Host,{class:"s-conditional-offer-container"},h("div",{class:"s-conditional-offer-title-wrapper"},h("div",{class:"s-conditional-offer-title"},this.offer.title),this.offer.description?h("div",{class:"s-conditional-offer-subtitle"},this.offer.description," ",h("i",{class:"sicon-information"})):null),h("div",{class:"s-conditional-offer-progress-container"},this.offer.details.discounts.map((function(t,n){return h("div",{class:{"flex-1":n>0},key:t.min_spend},e.getCheckPointView(t,n))}))))};return e}();SallaConditionalOffer.style=sallaConditionalOfferCss;export{SallaConditionalOffer as salla_conditional_offer};
4
+ import{r as registerInstance,h,H as Host}from"./index-114c614f.js";var DiscountType;(function(e){e["PERCENTAGE"]="percentage";e["FIXED"]="fixed";e["FREE_PRODUCT"]="free_product"})(DiscountType||(DiscountType={}));var OfferType;(function(e){e["PRODUCT_COUNT"]="products_count";e["PRODUCT_PURCHASE"]="order_amount"})(OfferType||(OfferType={}));var sallaConditionalOfferCss=":host{display:block}";var SallaConditionalOffer=function(){function e(e){registerInstance(this,e);this.offer=null;this.products={};this.isLoading=true;this.canRender=true}e.prototype.componentWillLoad=function(){var e=this;salla.onReady().then((function(){var e,t,n;if(!((e=salla.config.get("store.features"))===null||e===void 0?void 0:e.includes("conditional-offer"))||!((n=(t=salla.storage.get("cart"))===null||t===void 0?void 0:t.summary)===null||n===void 0?void 0:n.count)){throw new Error("feature or cart object does not existed")}})).then((function(){return salla.api.cart.offers()})).then((function(t){var n=t.data;e.offer=n.find((function(e){return e.type==="conditional"}));if(!e.offer){throw new Error("No conditional offer has been activated in the merchant dashboard")}e.offer.details.discounts.unshift({value:0,min_spend:0});return e.updateInitialOfferValue()})).then((function(){return e.getProducts()})).then((function(){return salla.event.on("cart::updated",(function(t){return e.updateOfferValues(t)}))})).catch((function(t){e.canRender=false;salla.logger.error("salla-conditional-offer:: Error",t)})).finally((function(){e.isLoading=false}))};e.prototype.getProducts=function(){var e=this;var t=this.offer.details.discounts.filter((function(e){var t=e.type;return t===DiscountType.FREE_PRODUCT})).map((function(e){var t=e.value;return t}));if(t.length>0){return salla.product.fetch({source:"selected",source_value:t}).then((function(t){var n=t.data;n.forEach((function(t){var n=t.id,i=t.url,o=t.image;e.products[n]={url:i,image:o}}))}))}};e.prototype.updateInitialOfferValue=function(){var e=this;return salla.api.cart.details().then((function(t){var n=t.data.cart;return e.updateOfferValues(n)}))};e.prototype.updateOfferValues=function(e){var t=e.items,n=e.total;var i;var o=this.offer.details.based_on===OfferType.PRODUCT_COUNT?t.reduce((function(e,t){var n=t.quantity;return e+n}),0):n;this.offer=Object.assign(Object.assign({},this.offer),{details:Object.assign(Object.assign({},(i=this.offer)===null||i===void 0?void 0:i.details),{current_value:o})});return this.offer};e.prototype.getCheckpointContent=function(e){var t,n;if(e.type===DiscountType.PERCENTAGE)return"".concat(e.value,"%");if(e.type===DiscountType.FIXED)return salla.money(e.value);if(e.type!==DiscountType.FREE_PRODUCT){salla.logger.error("salla-conditional-offer:: unexpected type (".concat(e.type,")!"));return""}var i=this.products[e.value];if(!i){salla.logger.error("salla-conditional-offer:: there is no product with id (".concat(e.value,")!"));return""}return h("a",{class:"s-conditional-offer-product-link",href:i.url},h("img",{class:"s-conditional-offer-checkpoint-image-content",loading:"lazy",decoding:"async",alt:((t=i===null||i===void 0?void 0:i.image)===null||t===void 0?void 0:t.alt)||"",src:(n=i===null||i===void 0?void 0:i.image)===null||n===void 0?void 0:n.url}))};e.prototype.getOfferType=function(e){var t;var n=(t=this.offer.details)===null||t===void 0?void 0:t.based_on;if(n===OfferType.PRODUCT_COUNT)return salla.lang.choice("blocks.header.products_count",e.min_spend);if(n===OfferType.PRODUCT_PURCHASE)return salla.money(e.min_spend);salla.logger.warn("salla-conditional-offer:: Unexpected offer detail's based_on value: ".concat(n));return"".concat(e.min_spend)};e.prototype.clamp=function(e,t,n){return Math.max(t,Math.min(e,n))};e.prototype.mapValueRanges=function(e,t,n,i,o){var r=(e-t)*(o-i)/(n-t)+i;if(r===Number.POSITIVE_INFINITY)return 100;if(r===Number.NEGATIVE_INFINITY)return 0;return this.clamp(r,0,100)};e.prototype.getCheckPointView=function(e,t){var n,i;var o=this.offer.details.discounts.findIndex((function(t){var n=t.min_spend;return n===e.min_spend}));var r=(i=(n=this.offer.details.discounts[o-1])===null||n===void 0?void 0:n.min_spend)!==null&&i!==void 0?i:0;var a=this.mapValueRanges(this.offer.details.current_value,r,e.min_spend,0,100);var s=e.min_spend<=this.offer.details.current_value;return h("div",{class:"s-conditional-offer-checkpoint-container"},t>0?[h("div",{key:"progress-line",class:"s-conditional-offer-progress-line-container"},h("div",{class:"s-conditional-offer-progress-line-inactive"}),h("div",{class:"s-conditional-offer-progress-line-active",style:{width:"".concat(a,"%")}})),h("div",{key:"checkpoint",class:"s-conditional-offer-checkpoint ".concat(s?"s-conditional-offer-active-checkpoint":"")},h("div",{class:"s-conditional-offer-item-avatar-content ".concat(s?"active":"")},this.products&&this.getCheckpointContent(e)),h("div",{class:"s-conditional-offer-checkpoint-label ".concat(s?"active":""),innerHTML:this.getOfferType(e)}))]:h("div",{key:"label",class:{"s-conditional-offer-checkpoint-label":true,"first-checkpoint":t===0,active:s},innerHTML:this.getOfferType(e)}))};e.prototype.getLoadingSkeletonView=function(){return h(Host,{class:"s-conditional-offer-container"},h("div",{class:"s-conditional-offer-skeleton-inner-container"},h("div",{class:"s-conditional-offer-skeleton-subtitle"},h("salla-skeleton",{height:"16px",width:"30%"})),h("div",{class:"s-conditional-offer-skeleton-subtitle"},h("salla-skeleton",{height:"16px",width:"35%"})),h("div",{class:"s-conditional-offer-skeleton-checkpoints-wrapper"},Array(3).fill(null).map((function(){return[h("salla-skeleton",{key:"checkpoint-line",height:"8px"}),h("div",{key:"checkpoint"},h("salla-skeleton",{height:"60px",width:"60px",type:"circle"}))]})))))};e.prototype.render=function(){var e=this;if(!this.canRender)return null;if(this.isLoading)return this.getLoadingSkeletonView();return h(Host,{class:"s-conditional-offer-container"},h("div",{class:"s-conditional-offer-title-wrapper"},h("div",{class:"s-conditional-offer-title"},this.offer.title),this.offer.description?h("div",{class:"s-conditional-offer-subtitle"},this.offer.description," ",h("i",{class:"sicon-information"})):null),h("div",{class:"s-conditional-offer-progress-container"},this.offer.details.discounts.map((function(t,n){return h("div",{class:{"flex-1":n>0},key:t.min_spend},e.getCheckPointView(t,n))}))))};return e}();SallaConditionalOffer.style=sallaConditionalOfferCss;export{SallaConditionalOffer as salla_conditional_offer};
5
5
  //# sourceMappingURL=salla-conditional-offer.entry.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["DiscountType","OfferType","sallaConditionalOfferCss","SallaConditionalOffer","prototype","componentWillLoad","_this","this","salla","onReady","then","_a","config","get","includes","_c","_b","storage","summary","count","Error","api","cart","offers","_d","data","offer","find","type","details","discounts","unshift","value","min_spend","updateInitialOfferValue","getProducts","event","on","updatedCart","updateOfferValues","catch","error","canRender","logger","finally","isLoading","freeProductIDs","filter","FREE_PRODUCT","map","length","product","fetch","source","source_value","forEach","id","url","image","products","items","total","current_value","based_on","PRODUCT_COUNT","reduce","quantity","Object","assign","getCheckpointContent","discount","PERCENTAGE","concat","FIXED","money","productItem","h","class","href","loading","decoding","alt","src","getOfferType","basedOn","lang","choice","PRODUCT_PURCHASE","warn","clamp","min","max","Math","mapValueRanges","initialMinRange","initialMaxRange","newMinRange","newMaxRange","newRange","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","getCheckPointView","index","checkpointIndex","findIndex","previousCheckpointValue","progressPercentage","isActive","key","style","width","innerHTML","active","getLoadingSkeletonView","Host","height","Array","fill","render","title","description"],"sources":["src/components/salla-conditional-offer/interfaces.ts","src/components/salla-conditional-offer/salla-conditional-offer.scss?tag=salla-conditional-offer","src/components/salla-conditional-offer/salla-conditional-offer.tsx"],"sourcesContent":["import type { Product } from \"@salla.sa/twilight/types/common\";\n\nexport enum DiscountType {\n PERCENTAGE = \"percentage\",\n FIXED = \"fixed\",\n FREE_PRODUCT = \"free_product\",\n}\n\nexport enum OfferType {\n PRODUCT_COUNT = \"products_count\",\n PRODUCT_PURCHASE = \"order_amount\",\n}\n\nexport interface Discount {\n type?: DiscountType;\n value?: number;\n min_spend?: number;\n max_discount?: number;\n}\n\nexport interface OfferDetails {\n based_on?: OfferType;\n ends_at?: number;\n start_value?: number;\n end_value?: number;\n current_value?: number;\n discounts?: Discount[];\n}\n\nexport interface Offer {\n id?: number;\n type?: string;\n title?: string;\n description?: string;\n details?: OfferDetails | null;\n}\n\n\nexport interface ProductDetail {\n id?: number;\n sku?: string;\n name?: string;\n description?: string;\n url?: string;\n promotion_title?: null;\n subtitle?: null;\n type?: string;\n status?: string;\n price?: number;\n base_currency_price?: BaseCurrencyPrice;\n sale_price?: number;\n regular_price?: number;\n starting_price?: null;\n quantity?: null;\n max_quantity?: number;\n discount_ends?: null;\n is_taxable?: boolean;\n has_read_more?: boolean;\n can_add_note?: boolean;\n can_show_remained_quantity?: boolean;\n can_upload_file?: boolean;\n has_custom_form?: boolean;\n has_metadata?: boolean;\n is_on_sale?: boolean;\n is_hidden_quantity?: boolean;\n is_available?: boolean;\n is_out_of_stock?: boolean;\n is_require_shipping?: boolean;\n weight?: null;\n calories?: null;\n image?: Image;\n currency?: string;\n}\n\nexport interface BaseCurrencyPrice {\n currency?: string;\n amount?: number;\n}\n\nexport interface Image {\n url?: string;\n alt?: string;\n}\n\nexport interface UpdatedCart {\n items: Array<Product>;\n total: number;\n}\n",":host {\n display: block;\n}","import { Component, Host, State, h } from \"@stencil/core\";\nimport {\n type Discount,\n DiscountType,\n type Offer,\n OfferType,\n type UpdatedCart,\n} from \"./interfaces\";\nimport type { Product } from \"@salla.sa/twilight/types/common\";\n\n@Component({\n tag: \"salla-conditional-offer\",\n styleUrl: \"salla-conditional-offer.scss\",\n})\nexport class SallaConditionalOffer {\n\n @State() offer: Offer = null;\n @State() products: Record<string, Pick<Product, 'image' | 'url'>> = {}\n @State() isLoading = true\n @State() canRender = true\n\n componentWillLoad() {\n salla.onReady().then(() => {\n if (!salla.config.get('store.features')?.includes('conditional-offer') || !salla.storage.get(\"cart\")?.summary?.count) {\n throw new Error('feature or cart object does not existed');\n }\n })\n .then(() => salla.api.cart.offers())\n .then(({ data }: { data: Offer[] }) => {\n //it's okay if there is an exception here, all thens will be skipped, and will catch the error,\n this.offer = data.find(offer => offer.type === \"conditional\")\n this.offer.details.discounts.unshift(({ value: 0, min_spend: 0 }))\n return this.updateInitialOfferValue()\n }).then(() => this.getProducts()).then(() => salla.event.on(\"cart::updated\", (updatedCart: UpdatedCart) => this.updateOfferValues(updatedCart)))\n .catch(error => {\n this.canRender = false\n salla.logger.error('salla-conditional-offer:: Error', error)\n }).finally(() => {\n this.isLoading = false\n })\n\n }\n\n private getProducts() {\n const freeProductIDs = this.offer.details.discounts.filter(({ type }) => type === DiscountType.FREE_PRODUCT).map(({ value }) => value)\n if (freeProductIDs.length > 0) {\n return salla.product.fetch({ source: 'selected', source_value: freeProductIDs }).then(({ data }: { data: Array<Product> }) => {\n data.forEach(({ id, url, image }) => {\n this.products[id] = { url, image }\n })\n })\n }\n }\n \n private updateInitialOfferValue() {\n return salla.api.cart.details().then(({ data: { cart } }: { data: { cart: UpdatedCart } }) => this.updateOfferValues(cart))\n }\n\n private updateOfferValues({ items, total }: UpdatedCart) {\n const current_value = this.offer.details.based_on === OfferType.PRODUCT_COUNT ? items.reduce((count: number, { quantity }) => count + quantity, 0,) : total\n //we need to assign the offer object a new reference to trigger re-rendering\n this.offer = {\n ...this.offer, details: {\n ...this.offer?.details, current_value,\n }\n }\n return this.offer\n }\n\n private getCheckpointContent(discount: Discount) {\n\n if (discount.type === DiscountType.PERCENTAGE) return `${discount.value}%`\n\n if (discount.type === DiscountType.FIXED) return salla.money(discount.value)\n\n if (discount.type !== DiscountType.FREE_PRODUCT) {\n salla.logger.error(`salla-conditional-offer:: unexpected type (${discount.type})!`);\n return \"\";\n }\n\n const productItem = this.products[discount.value]\n\n if (!productItem) {\n salla.logger.error(`salla-conditional-offer:: there is no product with id (${discount.value})!`);\n return \"\";\n }\n\n return <a class=\"s-conditional-offer-product-link\" href={productItem.url} >\n <img\n class=\"s-conditional-offer-checkpoint-image-content\"\n loading=\"lazy\"\n decoding=\"async\"\n alt={productItem?.image?.alt || \"\"}\n src={productItem?.image?.url} />\n </a>\n }\n\n private getOfferType(discount: Discount): string {\n const basedOn = this.offer.details?.based_on;\n if (basedOn === OfferType.PRODUCT_COUNT) return salla.lang.choice(\"blocks.header.products_count\", discount.min_spend);\n if (basedOn === OfferType.PRODUCT_PURCHASE) return salla.money(discount.min_spend);\n\n salla.logger.warn(`salla-conditional-offer:: Unexpected offer detail's based_on value: ${basedOn}`);\n return `${discount.min_spend}`;\n }\n\n private clamp(value: number, min: number, max: number) {\n return Math.max(min, Math.min(value, max));\n }\n \n private mapValueRanges(value: number, initialMinRange: number, initialMaxRange: number, newMinRange: number, newMaxRange: number) {\n\n const newRange = ((value - initialMinRange) * (newMaxRange - newMinRange)) / (initialMaxRange - initialMinRange) + newMinRange;\n\n if (newRange === Number.POSITIVE_INFINITY) return 100\n\n if (newRange === Number.NEGATIVE_INFINITY) return 0\n\n return this.clamp(newRange, 0, 100)\n }\n\n private getCheckPointView(discount: Discount, index: number) {\n const checkpointIndex = this.offer.details.discounts.findIndex(({ min_spend }) => min_spend === discount.min_spend);\n const previousCheckpointValue = this.offer.details.discounts[checkpointIndex - 1]?.min_spend ?? 0;\n const progressPercentage = this.mapValueRanges(this.offer.details.current_value, previousCheckpointValue, discount.min_spend, 0, 100);\n const isActive = discount.min_spend <= this.offer.details.current_value;\n\n return (\n <div class=\"s-conditional-offer-checkpoint-container\">\n {index > 0 ? [\n <div key=\"progress-line\" class=\"s-conditional-offer-progress-line-container\">\n <div class=\"s-conditional-offer-progress-line-inactive\" />\n <div class=\"s-conditional-offer-progress-line-active\" style={{ width: `${progressPercentage}%` }} />\n </div>,\n <div key=\"checkpoint\" class={`s-conditional-offer-checkpoint ${isActive ? \"s-conditional-offer-active-checkpoint\" : \"\"}`} >\n <div class={`s-conditional-offer-item-avatar-content ${isActive ? \"active\" : \"\"}`} >\n {this.products && this.getCheckpointContent(discount)}\n </div>\n <div class={`s-conditional-offer-checkpoint-label ${isActive ? \"active\" : \"\"}`} innerHTML={this.getOfferType(discount)} />\n\n </div>\n ] :\n <div key=\"label\" class={{ \"s-conditional-offer-checkpoint-label\": true, \"first-checkpoint\": index === 0, active: isActive }} innerHTML={this.getOfferType(discount)} />\n }\n </div>\n );\n }\n\n private getLoadingSkeletonView() {\n return <Host class=\"s-conditional-offer-container \" >\n <div class=\"s-conditional-offer-skeleton-wrapper\">\n <div class=\"s-conditional-offer-skeleton-title\">\n <salla-skeleton height=\"16px\" width=\"30%\" />\n </div>\n\n <div class=\"s-conditional-offer-skeleton-subtitle\">\n <salla-skeleton height=\"16px\" width=\"35%\" />\n </div>\n <div class=\"s-conditional-offer-skeleton-checkpoints-wrapper\">\n {Array(3).fill(null).map(() => (\n [<salla-skeleton key=\"checkpoint-line\" height=\"8px\" />,\n <div class=\"s-conditional-offer-skeleton-checkpoint\" key=\"checkpoint\">\n <salla-skeleton height=\"60px\" width=\"60px\" type=\"circle\" />\n </div>]\n ))}\n </div>\n\n </div>\n </Host>\n }\n\n render() {\n if (!this.canRender) return null\n if (this.isLoading) return this.getLoadingSkeletonView()\n\n return <Host class=\"s-conditional-offer-container\">\n <div class=\"s-conditional-offer-title-wrapper\">\n <div class=\"s-conditional-offer-title\">{this.offer.title}</div>\n {this.offer.description ? <div class=\"s-conditional-offer-subtitle\">\n {this.offer.description} <i class=\"sicon-information\" />\n </div> : null}\n </div>\n <div class=\"s-conditional-offer-progress-container\">\n {this.offer.details.discounts.map((discount, index) => (\n <div class={{ \"flex-1\": index > 0 }} key={discount.min_spend}>\n {this.getCheckPointView(discount, index)}\n </div>\n ))}\n </div>\n </Host>\n }\n}\n"],"mappings":";;;mEAEA,IAAYA,cAAZ,SAAYA,GACRA,EAAA,2BACAA,EAAA,iBACAA,EAAA,8BACH,EAJD,CAAYA,4BAAY,KAMxB,IAAYC,WAAZ,SAAYA,GACRA,EAAA,kCACAA,EAAA,kCACH,EAHD,CAAYA,sBAAS,KCRrB,IAAMC,yBAA2B,uB,ICcpBC,sBAAqB,W,kDAEN,K,cAC4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EAAA,kBAAgBwC,OAAO,OAAOL,MAAM,SAExCnC,EAAA,OAAKC,MAAM,oDACNwC,MAAM,GAAGC,KAAK,MAAMrE,KAAI,kBACpB2B,EAAA,kBAAgBiC,IAAI,kBAAkBO,OAAO,QAC9CxC,EAAA,OAAKC,MAAM,0CAA0CgC,IAAI,cACrDjC,EAAA,kBAAgBwC,OAAO,OAAOL,MAAM,OAAOnF,KAAK,YAH/B,M,EAYzCzB,EAAAC,UAAAmH,OAAA,eAAAjH,EAAAC,KACI,IAAKA,KAAKmC,UAAW,OAAO,KAC5B,GAAInC,KAAKsC,UAAW,OAAOtC,KAAK2G,yBAEhC,OAAOtC,EAACuC,KAAI,CAACtC,MAAM,iCACfD,EAAA,OAAKC,MAAM,qCACPD,EAAA,OAAKC,MAAM,6BAA6BtE,KAAKmB,MAAM8F,OAClDjH,KAAKmB,MAAM+F,YAAc7C,EAAA,OAAKC,MAAM,gCAChCtE,KAAKmB,MAAM+F,YAAW,IAAE7C,EAAA,KAAGC,MAAM,uBAC7B,MAEbD,EAAA,OAAKC,MAAM,0CACNtE,KAAKmB,MAAMG,QAAQC,UAAUmB,KAAI,SAACqB,EAAUiC,GAAK,OAC9C3B,EAAA,OAAKC,MAAO,CAAE,SAAU0B,EAAQ,GAAKM,IAAKvC,EAASrC,WAC9C3B,EAAKgG,kBAAkBhC,EAAUiC,GAFQ,K,WAzKhC,G"}
1
+ {"version":3,"names":["DiscountType","OfferType","sallaConditionalOfferCss","SallaConditionalOffer","prototype","componentWillLoad","_this","this","salla","onReady","then","_a","config","get","includes","_c","_b","storage","summary","count","Error","api","cart","offers","_d","data","offer","find","type","details","discounts","unshift","value","min_spend","updateInitialOfferValue","getProducts","event","on","updatedCart","updateOfferValues","catch","error","canRender","logger","finally","isLoading","freeProductIDs","filter","FREE_PRODUCT","map","length","product","fetch","source","source_value","forEach","id","url","image","products","items","total","current_value","based_on","PRODUCT_COUNT","reduce","quantity","Object","assign","getCheckpointContent","discount","PERCENTAGE","concat","FIXED","money","productItem","h","class","href","loading","decoding","alt","src","getOfferType","basedOn","lang","choice","PRODUCT_PURCHASE","warn","clamp","min","max","Math","mapValueRanges","initialMinRange","initialMaxRange","newMinRange","newMaxRange","newRange","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","getCheckPointView","index","checkpointIndex","findIndex","previousCheckpointValue","progressPercentage","isActive","key","style","width","innerHTML","active","getLoadingSkeletonView","Host","height","Array","fill","render","title","description"],"sources":["src/components/salla-conditional-offer/interfaces.ts","src/components/salla-conditional-offer/salla-conditional-offer.scss?tag=salla-conditional-offer","src/components/salla-conditional-offer/salla-conditional-offer.tsx"],"sourcesContent":["import type { Product } from \"@salla.sa/twilight/types/common\";\n\nexport enum DiscountType {\n PERCENTAGE = \"percentage\",\n FIXED = \"fixed\",\n FREE_PRODUCT = \"free_product\",\n}\n\nexport enum OfferType {\n PRODUCT_COUNT = \"products_count\",\n PRODUCT_PURCHASE = \"order_amount\",\n}\n\nexport interface Discount {\n type?: DiscountType;\n value?: number;\n min_spend?: number;\n max_discount?: number;\n}\n\nexport interface OfferDetails {\n based_on?: OfferType;\n ends_at?: number;\n start_value?: number;\n end_value?: number;\n current_value?: number;\n discounts?: Discount[];\n}\n\nexport interface Offer {\n id?: number;\n type?: string;\n title?: string;\n description?: string;\n details?: OfferDetails | null;\n}\n\n\nexport interface ProductDetail {\n id?: number;\n sku?: string;\n name?: string;\n description?: string;\n url?: string;\n promotion_title?: null;\n subtitle?: null;\n type?: string;\n status?: string;\n price?: number;\n base_currency_price?: BaseCurrencyPrice;\n sale_price?: number;\n regular_price?: number;\n starting_price?: null;\n quantity?: null;\n max_quantity?: number;\n discount_ends?: null;\n is_taxable?: boolean;\n has_read_more?: boolean;\n can_add_note?: boolean;\n can_show_remained_quantity?: boolean;\n can_upload_file?: boolean;\n has_custom_form?: boolean;\n has_metadata?: boolean;\n is_on_sale?: boolean;\n is_hidden_quantity?: boolean;\n is_available?: boolean;\n is_out_of_stock?: boolean;\n is_require_shipping?: boolean;\n weight?: null;\n calories?: null;\n image?: Image;\n currency?: string;\n}\n\nexport interface BaseCurrencyPrice {\n currency?: string;\n amount?: number;\n}\n\nexport interface Image {\n url?: string;\n alt?: string;\n}\n\nexport interface UpdatedCart {\n items: Array<Product>;\n total: number;\n}\n",":host {\n display: block;\n}","import { Component, Host, State, h } from \"@stencil/core\";\nimport {\n type Discount,\n DiscountType,\n type Offer,\n OfferType,\n type UpdatedCart,\n} from \"./interfaces\";\nimport type { Product } from \"@salla.sa/twilight/types/common\";\n\n@Component({\n tag: \"salla-conditional-offer\",\n styleUrl: \"salla-conditional-offer.scss\",\n})\nexport class SallaConditionalOffer {\n\n @State() offer: Offer = null;\n @State() products: Record<string, Pick<Product, 'image' | 'url'>> = {}\n @State() isLoading = true\n @State() canRender = true\n\n componentWillLoad() {\n salla.onReady().then(() => {\n if (!salla.config.get('store.features')?.includes('conditional-offer') || !salla.storage.get(\"cart\")?.summary?.count) {\n throw new Error('feature or cart object does not existed');\n }\n })\n .then(() => salla.api.cart.offers())\n .then(({ data }: { data: Offer[] }) => {\n //it's okay if there is an exception here, all thens will be skipped, and will catch the error,\n this.offer = data.find(offer => offer.type === \"conditional\")\n\n if (!this.offer) {\n throw new Error('No conditional offer has been activated in the merchant dashboard');\n }\n\n this.offer.details.discounts.unshift(({ value: 0, min_spend: 0 }))\n return this.updateInitialOfferValue()\n }).then(() => this.getProducts()).then(() => salla.event.on(\"cart::updated\", (updatedCart: UpdatedCart) => this.updateOfferValues(updatedCart)))\n .catch(error => {\n this.canRender = false\n salla.logger.error('salla-conditional-offer:: Error', error)\n }).finally(() => {\n this.isLoading = false\n })\n\n }\n\n private getProducts() {\n const freeProductIDs = this.offer.details.discounts.filter(({ type }) => type === DiscountType.FREE_PRODUCT).map(({ value }) => value)\n if (freeProductIDs.length > 0) {\n return salla.product.fetch({ source: 'selected', source_value: freeProductIDs }).then(({ data }: { data: Array<Product> }) => {\n data.forEach(({ id, url, image }) => {\n this.products[id] = { url, image }\n })\n })\n }\n }\n\n private updateInitialOfferValue() {\n return salla.api.cart.details().then(({ data: { cart } }: { data: { cart: UpdatedCart } }) => this.updateOfferValues(cart))\n }\n\n private updateOfferValues({ items, total }: UpdatedCart) {\n const current_value = this.offer.details.based_on === OfferType.PRODUCT_COUNT ? items.reduce((count: number, { quantity }) => count + quantity, 0,) : total\n //we need to assign the offer object a new reference to trigger re-rendering\n this.offer = {\n ...this.offer, details: {\n ...this.offer?.details, current_value,\n }\n }\n return this.offer\n }\n\n private getCheckpointContent(discount: Discount) {\n\n if (discount.type === DiscountType.PERCENTAGE) return `${discount.value}%`\n\n if (discount.type === DiscountType.FIXED) return salla.money(discount.value)\n\n if (discount.type !== DiscountType.FREE_PRODUCT) {\n salla.logger.error(`salla-conditional-offer:: unexpected type (${discount.type})!`);\n return \"\";\n }\n\n const productItem = this.products[discount.value]\n\n if (!productItem) {\n salla.logger.error(`salla-conditional-offer:: there is no product with id (${discount.value})!`);\n return \"\";\n }\n\n return <a class=\"s-conditional-offer-product-link\" href={productItem.url} >\n <img\n class=\"s-conditional-offer-checkpoint-image-content\"\n loading=\"lazy\"\n decoding=\"async\"\n alt={productItem?.image?.alt || \"\"}\n src={productItem?.image?.url} />\n </a>\n }\n\n private getOfferType(discount: Discount): string {\n const basedOn = this.offer.details?.based_on;\n if (basedOn === OfferType.PRODUCT_COUNT) return salla.lang.choice(\"blocks.header.products_count\", discount.min_spend);\n if (basedOn === OfferType.PRODUCT_PURCHASE) return salla.money(discount.min_spend);\n\n salla.logger.warn(`salla-conditional-offer:: Unexpected offer detail's based_on value: ${basedOn}`);\n return `${discount.min_spend}`;\n }\n\n private clamp(value: number, min: number, max: number) {\n return Math.max(min, Math.min(value, max));\n }\n\n private mapValueRanges(value: number, initialMinRange: number, initialMaxRange: number, newMinRange: number, newMaxRange: number) {\n\n const newRange = ((value - initialMinRange) * (newMaxRange - newMinRange)) / (initialMaxRange - initialMinRange) + newMinRange;\n\n if (newRange === Number.POSITIVE_INFINITY) return 100\n\n if (newRange === Number.NEGATIVE_INFINITY) return 0\n\n return this.clamp(newRange, 0, 100)\n }\n\n private getCheckPointView(discount: Discount, index: number) {\n const checkpointIndex = this.offer.details.discounts.findIndex(({ min_spend }) => min_spend === discount.min_spend);\n const previousCheckpointValue = this.offer.details.discounts[checkpointIndex - 1]?.min_spend ?? 0;\n const progressPercentage = this.mapValueRanges(this.offer.details.current_value, previousCheckpointValue, discount.min_spend, 0, 100);\n const isActive = discount.min_spend <= this.offer.details.current_value;\n\n return (\n <div class=\"s-conditional-offer-checkpoint-container\">\n {index > 0 ? [\n <div key=\"progress-line\" class=\"s-conditional-offer-progress-line-container\">\n <div class=\"s-conditional-offer-progress-line-inactive\" />\n <div class=\"s-conditional-offer-progress-line-active\" style={{ width: `${progressPercentage}%` }} />\n </div>,\n <div key=\"checkpoint\" class={`s-conditional-offer-checkpoint ${isActive ? \"s-conditional-offer-active-checkpoint\" : \"\"}`} >\n <div class={`s-conditional-offer-item-avatar-content ${isActive ? \"active\" : \"\"}`} >\n {this.products && this.getCheckpointContent(discount)}\n </div>\n <div class={`s-conditional-offer-checkpoint-label ${isActive ? \"active\" : \"\"}`} innerHTML={this.getOfferType(discount)} />\n\n </div>\n ] :\n <div key=\"label\" class={{ \"s-conditional-offer-checkpoint-label\": true, \"first-checkpoint\": index === 0, active: isActive }} innerHTML={this.getOfferType(discount)} />\n }\n </div>\n );\n }\n\n private getLoadingSkeletonView() {\n return <Host class=\"s-conditional-offer-container\" >\n <div class=\"s-conditional-offer-skeleton-inner-container\">\n <div class=\"s-conditional-offer-skeleton-subtitle\">\n <salla-skeleton height=\"16px\" width=\"30%\" />\n </div>\n\n <div class=\"s-conditional-offer-skeleton-subtitle\">\n <salla-skeleton height=\"16px\" width=\"35%\" />\n </div>\n <div class=\"s-conditional-offer-skeleton-checkpoints-wrapper\">\n {Array(3).fill(null).map(() => (\n [<salla-skeleton key=\"checkpoint-line\" height=\"8px\" />,\n <div key=\"checkpoint\">\n <salla-skeleton height=\"60px\" width=\"60px\" type=\"circle\" />\n </div>]\n ))}\n </div>\n\n </div>\n </Host>\n }\n\n render() {\n if (!this.canRender) return null\n if (this.isLoading) return this.getLoadingSkeletonView()\n\n return <Host class=\"s-conditional-offer-container\">\n <div class=\"s-conditional-offer-title-wrapper\">\n <div class=\"s-conditional-offer-title\">{this.offer.title}</div>\n {this.offer.description ? <div class=\"s-conditional-offer-subtitle\">\n {this.offer.description} <i class=\"sicon-information\" />\n </div> : null}\n </div>\n <div class=\"s-conditional-offer-progress-container\">\n {this.offer.details.discounts.map((discount, index) => (\n <div class={{ \"flex-1\": index > 0 }} key={discount.min_spend}>\n {this.getCheckPointView(discount, index)}\n </div>\n ))}\n </div>\n </Host>\n }\n}\n"],"mappings":";;;mEAEA,IAAYA,cAAZ,SAAYA,GACRA,EAAA,2BACAA,EAAA,iBACAA,EAAA,8BACH,EAJD,CAAYA,4BAAY,KAMxB,IAAYC,WAAZ,SAAYA,GACRA,EAAA,kCACAA,EAAA,kCACH,EAHD,CAAYA,sBAAS,KCRrB,IAAMC,yBAA2B,uB,ICcpBC,sBAAqB,W,kDAEN,K,cAC4C,G,eAC/C,K,eACA,I,CAErBA,EAAAC,UAAAC,kBAAA,eAAAC,EAAAC,KACIC,MAAMC,UAAUC,MAAK,W,UACjB,MAAKC,EAAAH,MAAMI,OAAOC,IAAI,qBAAiB,MAAAF,SAAA,SAAAA,EAAEG,SAAS,0BAAyBC,GAAAC,EAAAR,MAAMS,QAAQJ,IAAI,WAAO,MAAAG,SAAA,SAAAA,EAAEE,WAAO,MAAAH,SAAA,SAAAA,EAAEI,OAAO,CAClH,MAAM,IAAIC,MAAM,0C,KAGnBV,MAAK,WAAM,OAAAF,MAAMa,IAAIC,KAAKC,QAAf,IACXb,MAAK,SAACc,G,IAAEC,EAAID,EAAAC,KAETnB,EAAKoB,MAAQD,EAAKE,MAAK,SAAAD,GAAS,OAAAA,EAAME,OAAS,aAAf,IAEhC,IAAKtB,EAAKoB,MAAO,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AAM,6BAA6BtE,KAAKmB,MAAM8F,OAClDjH,KAAKmB,MAAM+F,YAAc7C,EAAA,OAAKC,MAAM,gCAChCtE,KAAKmB,MAAM+F,YAAW,IAAE7C,EAAA,KAAGC,MAAM,uBAC7B,MAEbD,EAAA,OAAKC,MAAM,0CACNtE,KAAKmB,MAAMG,QAAQC,UAAUmB,KAAI,SAACqB,EAAUiC,GAAK,OAC9C3B,EAAA,OAAKC,MAAO,CAAE,SAAU0B,EAAQ,GAAKM,IAAKvC,EAASrC,WAC9C3B,EAAKgG,kBAAkBhC,EAAUiC,GAFQ,K,WA9KhC,G"}
@@ -1,5 +1,5 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import{r as registerInstance,h,H as Host,g as getElement}from"./index-114c614f.js";var sallaInstallmentCss='salla-installment:empty{display:none}#tabbyPromoWrapper{background:white;border-radius:0.375rem;-webkit-transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1), -webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);margin-bottom:20px}.salla-y #tabbyPromoWrapper{border:1px solid var(--color-grey-dark);border-radius:12px}#tabbyPromoWrapper:hover{-webkit-box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922);box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922)}#tabbyPromoWrapper #tabbyPromo *{font-family:var(--font-main)}#tabbyPromoWrapper #tabbyPromo>div>div{max-width:none;-webkit-box-shadow:none;box-shadow:none;border:none}#tabbyPromoWrapper #tabbyPromo .tabby-promo-snippet{max-width:100%;min-height:100px;padding:18px 20px;border:none !important}#tabbyPromoWrapper #tabbyPromo .tabby-promo-snippet__text,#tabbyPromoWrapper #tabbyPromo .tabby-promo-snippet__link{font-size:var(--font-sm);color:var(--color-text) !important}#tabbyPromoWrapper #tabbyPromo .tabby-promo-snippet__link{font-weight:bold}.tabby-promo-wrapper #tabby-promo{font-family:var(--font-main) !important}.tabby-promo-wrapper #tabby-promo .tabby-promo__feature-title{font-size:var(--font-md)}.tabby-promo-wrapper #tabby-promo .tabby-promo__feature-desc{font-size:var(--font-sm);line-height:20px}.tamara-product-widget{margin-bottom:20px}.tamara-product-widget,.spotii-wrapper{min-height:100px;position:relative;color:var(--color-text);font-size:var(--font-sm);line-height:1.25;padding:18px 20px 18px 100px !important;background:white;border-radius:0.375rem;-webkit-transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1), -webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1)}.salla-y .tamara-product-widget,.salla-y .spotii-wrapper{border-radius:12px;border:1px solid var(--color-grey-dark)}.tamara-product-widget:hover,.spotii-wrapper:hover{-webkit-box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922);box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922)}.tamara-product-widget .spotii-logo,.spotii-wrapper .spotii-logo{float:left;margin:0 0 0 -75px}.ltr .tamara-product-widget,.ltr .spotii-wrapper{text-align:left;padding:18px 100px 18px 20px !important}.ltr .tamara-product-widget .spotii-logo,.ltr .spotii-wrapper .spotii-logo{float:right;margin:0 -75px 0 0}.ltr .tamara-product-widget .spotii-product-widget,.ltr .spotii-wrapper .spotii-product-widget{text-align:left !important}.spotii-wrapper{margin-bottom:20px}.spotii-wrapper .spotii-promo{font-size:var(--font-md)}.spotii-wrapper .spotii-product-widget{font-size:var(--font-sm) !important;margin-top:10px}.tamara-product-widget .tamara-logo{position:absolute;left:20px;top:18px;margin:0 !important}.ltr .tamara-product-widget .tamara-logo{right:20px;left:auto}.tamara-product-widget span{font-family:var(--font-main);font-size:var(--font-sm);color:var(--color-text)}.tamara-product-widget span:last-child{display:block;position:relative;margin-top:8px}.tamara-popup__wrap{overflow:auto !important}.s-installment-mispay-wrapper{font-family:"Noto Sans Arabic", sans-serif;font-size:14px;text-align:right;padding:24px 20px 24px 0px;gap:42px;direction:rtl;line-height:22px;color:rgb(0, 0, 0);min-width:100%;-webkit-box-sizing:border-box;box-sizing:border-box;position:relative;background-color:white;border-radius:10px;border:1px solid var(--07--Light-Theme-Gray-color-gray-300, #EEE);margin:15px 0;display:-ms-flexbox;display:flex;-webkit-transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1), -webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1)}.s-installment-mispay-wrapper:hover{-webkit-box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922);box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922)}.s-installment-mispay-content{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:center;align-items:center;margin:15px !important}.s-installment-mispay-content-text{color:#292929;margin:0 16px 0 0;width:80%;position:absolute;left:14px;text-align:left}.s-installment-mispay-content img{height:28px;width:70px;display:inline-block;max-height:100%;vertical-align:middle;fill:none;stroke:unset;width:auto;position:absolute}.rtl .s-installment-mispay-content-text{right:14px;text-align:right;margin:0 0 0 16px}.rtl .s-installment-mispay-content img{left:14px !important}.ltr .s-installment-mispay-content img{right:14px !important}';var SallaInstallment=function(){function t(t){var e=this;registerInstance(this,t);this.tabbyBorderRemoved=false;this.tabbyRemoveBorderTries=0;this.price=undefined;this.language=salla.config.get("user.language_code");this.currency=salla.config.get("user.currency_code");this.tamaraIsActive=undefined;this.tabbyIsActive=undefined;this.spotiiIsActive=undefined;this.mispayActive=undefined;this.installment_sheria_text=function(t){return salla.lang.get("pages.products.installments",t)};salla.lang.onLoaded((function(){e.installment_sheria_text({payment:salla.money(parseFloat(e.price)),amount:salla.money((parseFloat(e.price)/3).toFixed(2)),installments:3});var t=salla.config.get("store.settings.installments");if(t){e.tamaraIsActive=t.includes("tamara_installment");e.tabbyIsActive=t.includes("tabby_installment");e.spotiiIsActive=t.includes("spotii_pay");e.mispayActive=t.includes("mispay_installment")}e.renderInstallments()}));salla.event.on("product::price.updated",(function(t){var a=t.data;if(!a.price||a.price==e.price){return}e.price=a.price;e.renderInstallments(true)}))}t.prototype.render=function(){return h(Host,null,this.tamaraIsActive?h("div",{class:"tamara-product-widget","data-price":this.price,"data-currency":this.currency,"data-lang":this.language,"data-payment-type":"installment"}):"",this.tabbyIsActive?h("div",{id:"tabbyPromoWrapper"},h("div",{id:"tabbyPromo"})):"",this.spotiiIsActive?h("div",{class:"spotii-wrapper"},h("div",{class:"spotii-promo"})):"",this.mispayActive?h("div",{class:"s-installment-mispay-wrapper"},h("div",{class:"s-installment-mispay-content"},h("img",{src:salla.url.cdn("images/payment/png/mispay.png"),alt:"mispay"}),h("span",{class:"s-installment-mispay-content-text"},this.installment_sheria_text({payment:salla.money(parseFloat(this.price)),amount:salla.money((parseFloat(this.price)/3).toFixed(2)),installments:3})))):"")};t.prototype.renderInstallments=function(t){var e=this;if(t===void 0){t=false}if(this.tamaraIsActive){if(t){var a=document.querySelector('script[src="https://cdn.tamara.co/widget/product-widget.min.js"]');if(a){a.remove()}}var i=document.createElement("script");i.setAttribute("src","https://cdn.tamara.co/widget/product-widget.min.js");document.head.appendChild(i);i.onload=function(){window.TamaraProductWidget.init({lang:e.language});setTimeout((function(){window.TamaraProductWidget.render()}),300)}}if(this.tabbyIsActive){if(t){var r=this.host.querySelector("#tabbyPromoWrapper");if(r){r.remove()}var o=document.createElement("div");o.setAttribute("id","tabbyPromoWrapper");var s=document.createElement("div");s.setAttribute("id","tabbyPromo");o.appendChild(s);this.host.appendChild(o);var n=document.querySelector('script[src="https://checkout.tabby.ai/tabby-promo.js"]');if(n){n.remove()}}var p=document.createElement("script");p.setAttribute("src","https://checkout.tabby.ai/tabby-promo.js");document.head.appendChild(p);p.onload=function(){var t=window.TabbyPromo;new t({selector:"#tabbyPromo",currency:e.currency,price:e.price,lang:e.language});document.querySelectorAll(".tabby-promo-snippet__logo").forEach((function(t){t.setAttribute("aria-label","Tabby Logo")}))};this.removeTabbyBorder()}if(this.spotiiIsActive){if(t){var l=this.host.querySelector(".spotii-wrapper");if(l){l.remove()}var b=document.createElement("div");b.classList.add("spotii-wrapper");var m=document.createElement("div");m.classList.add("spotii-promo");b.appendChild(m);this.host.appendChild(b);var d=document.querySelector('script[src="'+salla.url.cdn("js/price-widget-ar-salla.js")+'"]');if(d){d.remove()}}var c=salla.money((Number(this.price)/3).toFixed(2));var u=salla.config.get("theme.is_rtl",true);window.spotiiConfig={targetXPath:[".spotii-wrapper"],renderToPath:[".spotii-promo"],numberOfPayment:3,currency:this.currency,templateLine:"${textOne} ${number} ${textTwo} "+c+"${logo} ${info}",textOne:u?"جزء الدفع على":"Split it into",textTwo:u?"أقساط متساوية بدون تكاليف اضافية بقيمة":"payments of",textThree:"مع",price:this.price};var g=document.createElement("script");g.setAttribute("src",salla.url.cdn("js/price-widget-ar-salla.js"));document.head.appendChild(g)}};t.prototype.removeTabbyBorder=function(){var t=this;if(this.tabbyBorderRemoved||this.tabbyRemoveBorderTries>5){return}this.tabbyRemoveBorderTries++;setTimeout((function(){var e=document.querySelector("#tabbyPromo>div>div");e=e?e.shadowRoot.querySelector('div[class^="styles__tabby-promo-snippet--"]'):null;if(e){e.style="border: none; margin: 15px 0!important;";t.tabbyBorderRemoved=true}else{t.removeTabbyBorder()}}),this.tabbyRemoveBorderTries*500)};Object.defineProperty(t.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return t}();SallaInstallment.style=sallaInstallmentCss;export{SallaInstallment as salla_installment};
4
+ import{r as registerInstance,h,H as Host,g as getElement}from"./index-114c614f.js";var sallaInstallmentCss='salla-installment:empty{display:none}#tabbyPromoWrapper{background:white;border-radius:0.375rem;-webkit-transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1), -webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);margin-bottom:20px}.salla-y #tabbyPromoWrapper{border:1px solid var(--color-grey-dark);border-radius:12px}#tabbyPromoWrapper:hover{-webkit-box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922);box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922)}#tabbyPromoWrapper #tabbyPromo *{font-family:var(--font-main)}#tabbyPromoWrapper #tabbyPromo>div>div{max-width:none;-webkit-box-shadow:none;box-shadow:none;border:none}#tabbyPromoWrapper #tabbyPromo .tabby-promo-snippet{max-width:100%;min-height:100px;padding:18px 20px;border:none !important}#tabbyPromoWrapper #tabbyPromo .tabby-promo-snippet__text,#tabbyPromoWrapper #tabbyPromo .tabby-promo-snippet__link{font-size:var(--font-sm);color:var(--color-text) !important}#tabbyPromoWrapper #tabbyPromo .tabby-promo-snippet__link{font-weight:bold}.tabby-promo-wrapper #tabby-promo{font-family:var(--font-main) !important}.tabby-promo-wrapper #tabby-promo .tabby-promo__feature-title{font-size:var(--font-md)}.tabby-promo-wrapper #tabby-promo .tabby-promo__feature-desc{font-size:var(--font-sm);line-height:20px}.tamara-product-widget{margin-bottom:20px}.tamara-product-widget,.spotii-wrapper{min-height:100px;position:relative;color:var(--color-text);font-size:var(--font-sm);line-height:1.25;padding:18px 20px 18px 100px !important;background:white;border-radius:0.375rem;-webkit-transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1), -webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1)}.salla-y .tamara-product-widget,.salla-y .spotii-wrapper{border-radius:12px;border:1px solid var(--color-grey-dark)}.tamara-product-widget:hover,.spotii-wrapper:hover{-webkit-box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922);box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922)}.tamara-product-widget .spotii-logo,.spotii-wrapper .spotii-logo{float:left;margin:0 0 0 -75px}.ltr .tamara-product-widget,.ltr .spotii-wrapper{text-align:left;padding:18px 100px 18px 20px !important}.ltr .tamara-product-widget .spotii-logo,.ltr .spotii-wrapper .spotii-logo{float:right;margin:0 -75px 0 0}.ltr .tamara-product-widget .spotii-product-widget,.ltr .spotii-wrapper .spotii-product-widget{text-align:left !important}.spotii-wrapper{margin-bottom:20px}.spotii-wrapper .spotii-promo{font-size:var(--font-md)}.spotii-wrapper .spotii-product-widget{font-size:var(--font-sm) !important;margin-top:10px}.tamara-product-widget .tamara-logo{position:absolute;left:20px;top:18px;margin:0 !important}.ltr .tamara-product-widget .tamara-logo{right:20px;left:auto}.tamara-product-widget span{font-family:var(--font-main);font-size:var(--font-sm);color:var(--color-text)}.tamara-product-widget span:last-child{display:block;position:relative;margin-top:8px}.tamara-popup__wrap{overflow:auto !important}.s-installment-mispay-wrapper{font-family:"Noto Sans Arabic", sans-serif;font-size:14px;text-align:right;padding:24px 20px 24px 0px;gap:42px;direction:rtl;line-height:22px;color:rgb(0, 0, 0);min-width:100%;-webkit-box-sizing:border-box;box-sizing:border-box;position:relative;background-color:white;border-radius:10px;border:1px solid var(--07--Light-Theme-Gray-color-gray-300, #EEE);margin:15px 0;display:-ms-flexbox;display:flex;-webkit-transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:-webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);transition:box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1), -webkit-box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1)}.s-installment-mispay-wrapper:hover{-webkit-box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922);box-shadow:0 0 rgba(0, 0, 0, 0), 0 0 rgba(0, 0, 0, 0), 5px 10px 30px rgba(43, 45, 52, 0.0509803922)}.s-installment-mispay-content{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:center;align-items:center;margin:15px !important}.s-installment-mispay-content-text{color:#292929;margin:0 16px 0 0;width:80%;position:absolute;left:14px;text-align:left}.s-installment-mispay-content img{height:28px;width:70px;display:inline-block;max-height:100%;vertical-align:middle;fill:none;stroke:unset;width:auto;position:absolute}.rtl .s-installment-mispay-content-text{right:14px;text-align:right;margin:0 0 0 16px}.rtl .s-installment-mispay-content img{left:14px !important}.ltr .s-installment-mispay-content img{right:14px !important}';var SallaInstallment=function(){function t(t){var e=this;registerInstance(this,t);this.tabbyBorderRemoved=false;this.tabbyRemoveBorderTries=0;this.price=undefined;this.language=salla.config.get("user.language_code");this.currency=salla.config.get("user.currency_code");this.tamaraIsActive=undefined;this.tabbyIsActive=undefined;this.spotiiIsActive=undefined;this.mispayActive=undefined;this.installment_sheria_text=function(t){return salla.lang.get("pages.products.installments",t)};salla.lang.onLoaded((function(){e.installment_sheria_text({payment:salla.money(parseFloat(e.price)),amount:salla.money((parseFloat(e.price)/3).toFixed(2)),installments:3});var t=salla.config.get("store.settings.installments");if(t){e.tamaraIsActive=t.tamara;e.tabbyIsActive=t.tabby;e.spotiiIsActive=t.spotii;e.mispayActive=t.mispay}e.renderInstallments()}));salla.event.on("product::price.updated",(function(t){var a=t.data;if(!a.price||a.price==e.price){return}e.price=a.price;e.renderInstallments(true)}))}t.prototype.render=function(){return h(Host,null,this.tamaraIsActive?h("div",{class:"tamara-product-widget","data-price":this.price,"data-currency":this.currency,"data-lang":this.language,"data-payment-type":"installment"}):"",this.tabbyIsActive?h("div",{id:"tabbyPromoWrapper"},h("div",{id:"tabbyPromo"})):"",this.spotiiIsActive?h("div",{class:"spotii-wrapper"},h("div",{class:"spotii-promo"})):"",this.mispayActive?h("div",{class:"s-installment-mispay-wrapper"},h("div",{class:"s-installment-mispay-content"},h("img",{src:salla.url.cdn("images/payment/png/mispay.png"),alt:"mispay"}),h("span",{class:"s-installment-mispay-content-text"},this.installment_sheria_text({payment:salla.money(parseFloat(this.price)),amount:salla.money((parseFloat(this.price)/3).toFixed(2)),installments:3})))):"")};t.prototype.renderInstallments=function(t){var e=this;if(t===void 0){t=false}if(this.tamaraIsActive){if(t){var a=document.querySelector('script[src="https://cdn.tamara.co/widget/product-widget.min.js"]');if(a){a.remove()}}var i=document.createElement("script");i.setAttribute("src","https://cdn.tamara.co/widget/product-widget.min.js");document.head.appendChild(i);i.onload=function(){window.TamaraProductWidget.init({lang:e.language});setTimeout((function(){window.TamaraProductWidget.render()}),300)}}if(this.tabbyIsActive){if(t){var r=this.host.querySelector("#tabbyPromoWrapper");if(r){r.remove()}var o=document.createElement("div");o.setAttribute("id","tabbyPromoWrapper");var s=document.createElement("div");s.setAttribute("id","tabbyPromo");o.appendChild(s);this.host.appendChild(o);var n=document.querySelector('script[src="https://checkout.tabby.ai/tabby-promo.js"]');if(n){n.remove()}}var p=document.createElement("script");p.setAttribute("src","https://checkout.tabby.ai/tabby-promo.js");document.head.appendChild(p);p.onload=function(){var t=window.TabbyPromo;new t({selector:"#tabbyPromo",currency:e.currency,price:e.price,lang:e.language,publicKey:salla.config.get("store.settings.installments.tabby.publicKey"),merchantCode:salla.config.get("store.settings.installments.tabby.merchantCode")});document.querySelectorAll(".tabby-promo-snippet__logo").forEach((function(t){t.setAttribute("aria-label","Tabby Logo")}))};this.removeTabbyBorder()}if(this.spotiiIsActive){if(t){var l=this.host.querySelector(".spotii-wrapper");if(l){l.remove()}var b=document.createElement("div");b.classList.add("spotii-wrapper");var m=document.createElement("div");m.classList.add("spotii-promo");b.appendChild(m);this.host.appendChild(b);var d=document.querySelector('script[src="'+salla.url.cdn("js/price-widget-ar-salla.js")+'"]');if(d){d.remove()}}var c=salla.money((Number(this.price)/3).toFixed(2));var g=salla.config.get("theme.is_rtl",true);window.spotiiConfig={targetXPath:[".spotii-wrapper"],renderToPath:[".spotii-promo"],numberOfPayment:3,currency:this.currency,templateLine:"${textOne} ${number} ${textTwo} "+c+"${logo} ${info}",textOne:g?"جزء الدفع على":"Split it into",textTwo:g?"أقساط متساوية بدون تكاليف اضافية بقيمة":"payments of",textThree:"مع",price:this.price};var u=document.createElement("script");u.setAttribute("src",salla.url.cdn("js/price-widget-ar-salla.js"));document.head.appendChild(u)}};t.prototype.removeTabbyBorder=function(){var t=this;if(this.tabbyBorderRemoved||this.tabbyRemoveBorderTries>5){return}this.tabbyRemoveBorderTries++;setTimeout((function(){var e=document.querySelector("#tabbyPromo>div>div");e=e?e.shadowRoot.querySelector('div[class^="styles__tabby-promo-snippet--"]'):null;if(e){e.style="border: none; margin: 15px 0!important;";t.tabbyBorderRemoved=true}else{t.removeTabbyBorder()}}),this.tabbyRemoveBorderTries*500)};Object.defineProperty(t.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return t}();SallaInstallment.style=sallaInstallmentCss;export{SallaInstallment as salla_installment};
5
5
  //# sourceMappingURL=salla-installment.entry.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["sallaInstallmentCss","SallaInstallment","hostRef","_this","this","tabbyBorderRemoved","tabbyRemoveBorderTries","salla","config","get","replacement","lang","onLoaded","installment_sheria_text","payment","money","parseFloat","price","amount","toFixed","installments","installment","tamaraIsActive","includes","tabbyIsActive","spotiiIsActive","mispayActive","renderInstallments","event","on","_a","data","prototype","render","h","Host","class","currency","language","id","src","url","cdn","alt","isUpdating","oldTamaraScript","document","querySelector","remove","tamaraScript","createElement","setAttribute","head","appendChild","onload","window","TamaraProductWidget","init","setTimeout","oldTabbyWrapper","host","tabbyPromoWrapper","tabbyPromo","oldTabbyScript","tabbyScript","TabbyPromo","selector","querySelectorAll","forEach","element","removeTabbyBorder","oldSpotiiWrapper","spotiiPromoWrapper","classList","add","spotiiPromo","oldSpotiiScript","Number","isRTL","spotiiConfig","targetXPath","renderToPath","numberOfPayment","templateLine","textOne","textTwo","textThree","spotiiScript","promo","shadowRoot","style"],"sources":["src/components/salla-installment/salla-installment.scss?tag=salla-installment","src/components/salla-installment/salla-installment.tsx"],"sourcesContent":["/*\n The whole installment methods is a third-party widgets,\n So there aren't a custom classes (as other components) to style them.\n*/\n\nsalla-installment:empty {\n display: none;\n}\n\n/*\n* Installment::Tabby\n*/\n#tabbyPromoWrapper {\n background: white;\n border-radius: 0.375rem;\n transition: box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);\n margin-bottom: 20px;\n\n .salla-y & {\n border: 1px solid var(--color-grey-dark);\n border-radius: 12px\n }\n\n &:hover {\n box-shadow: 0 0 #0000, 0 0 #0000, 5px 10px 30px #2B2D340D;\n }\n\n #tabbyPromo {\n * {\n font-family: var(--font-main);\n }\n\n >div>div {\n max-width: none;\n //padding: 15px;\n box-shadow: none;\n border: none;\n }\n\n .tabby-promo-snippet {\n max-width: 100%;\n min-height: 100px;\n padding: 18px 20px;\n // border-color: var(--color-grey-dark);\n border: none !important;\n\n\n &__text,\n &__link {\n font-size: var(--font-sm);\n color: var(--color-text) !important;\n }\n\n &__link {\n font-weight: bold;\n }\n }\n }\n}\n\n.tabby-promo-wrapper {\n #tabby-promo {\n font-family: var(--font-main) !important;\n\n .tabby-promo {\n &__feature-title {\n font-size: var(--font-md);\n }\n\n &__feature-desc {\n font-size: var(--font-sm);\n line-height: 20px;\n }\n }\n }\n}\n\n/*\n* Installment::Tamara & Spotii\n*/\n.tamara-product-widget {\n margin-bottom: 20px;\n}\n\n.tamara-product-widget,\n.spotii-wrapper {\n min-height: 100px;\n position: relative;\n color: var(--color-text);\n font-size: var(--font-sm);\n line-height: 1.25;\n padding: 18px 20px 18px 100px !important;\n background: white;\n border-radius: 0.375rem;\n transition: box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);\n\n .salla-y & {\n border-radius: 12px;\n border: 1px solid var(--color-grey-dark);\n }\n\n &:hover {\n box-shadow: 0 0 #0000, 0 0 #0000, 5px 10px 30px #2B2D340D;\n }\n\n .spotii-logo {\n float: left;\n margin: 0 0 0 -75px;\n }\n}\n\n.ltr .tamara-product-widget,\n.ltr .spotii-wrapper {\n text-align: left;\n padding: 18px 100px 18px 20px !important;\n\n .spotii-logo {\n float: right;\n margin: 0 -75px 0 0;\n }\n\n .spotii-product-widget {\n text-align: left !important;\n }\n}\n\n.spotii-wrapper {\n margin-bottom: 20px;\n\n .spotii-promo {\n font-size: var(--font-md);\n }\n\n .spotii-product-widget {\n font-size: var(--font-sm) !important;\n margin-top: 10px;\n }\n}\n\n.tamara-product-widget {\n .tamara-logo {\n position: absolute;\n left: 20px;\n top: 18px;\n margin: 0 !important;\n\n .ltr & {\n right: 20px;\n left: auto;\n }\n }\n\n span {\n font-family: var(--font-main);\n font-size: var(--font-sm);\n color: var(--color-text);\n\n &:last-child {\n display: block;\n position: relative;\n margin-top: 8px;\n }\n }\n}\n\n.tamara-popup {\n &__wrap {\n overflow: auto !important;\n }\n}\n\n.s-installment-mispay-wrapper {\n font-family: \"Noto Sans Arabic\", sans-serif;\n font-size: 14px;\n text-align: right;\n padding: 24px 20px 24px 0px;\n gap: 42px;\n direction: rtl;\n line-height: 22px;\n color: rgb(0, 0, 0);\n min-width: 100%;\n box-sizing: border-box;\n position: relative;\n background-color: white;\n border-radius: 10px;\n border: 1px solid var(--07--Light-Theme-Gray-color-gray-300, #EEE);\n margin: 15px 0;\n display: flex;\n transition: box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.s-installment-mispay-wrapper:hover {\n box-shadow: 0 0 #0000, 0 0 #0000, 5px 10px 30px #2B2D340D;\n}\n\n.s-installment-mispay-content {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin: 15px !important;\n}\n\n.s-installment-mispay-content-text {\n color: #292929;\n margin: 0 16px 0 0;\n width: 80%;\n position: absolute;\n left: 14px;\n text-align: left;\n}\n\n\n.s-installment-mispay-content img {\n height: 28px;\n width: 70px;\n display: inline-block;\n max-height: 100%;\n vertical-align: middle;\n fill: none;\n stroke: unset;\n width: auto;\n position: absolute;\n}\n\n.rtl .s-installment-mispay-content-text {\n right: 14px;\n text-align: right;\n margin: 0 0 0 16px;\n}\n\n.rtl .s-installment-mispay-content img {\n left: 14px !important;\n}\n\n.ltr .s-installment-mispay-content img {\n right: 14px !important;\n}\n","import { Component, Host, h, Prop, State, Element } from '@stencil/core';\n\n@Component({\n tag: 'salla-installment',\n styleUrl: 'salla-installment.scss',\n})\n\nexport class SallaInstallment {\n private tabbyBorderRemoved: boolean = false;\n private tabbyRemoveBorderTries: number = 0;\n @Element() host: HTMLElement;\n constructor() {\n salla.lang.onLoaded(() => {\n this.installment_sheria_text({ payment: salla.money(parseFloat(this.price)), amount: salla.money((parseFloat(this.price) / 3).toFixed(2)), installments: 3 })\n const installment = salla.config.get('store.settings.installments');\n if (installment) {\n this.tamaraIsActive = installment.includes('tamara_installment');\n this.tabbyIsActive = installment.includes('tabby_installment');\n this.spotiiIsActive = installment.includes('spotii_pay');\n this.mispayActive = installment.includes('mispay_installment');\n }\n this.renderInstallments();\n });\n\n salla.event.on('product::price.updated', ({ data }) => {\n if (!data.price || data.price == this.price) {\n return;\n }\n this.price = data.price;\n this.renderInstallments(true);\n });\n }\n\n /**\n * Current product price\n */\n @Prop() price: string;\n /**\n * Language code\n */\n @Prop() language: string = salla.config.get('user.language_code');\n /**\n * Currency code\n */\n @Prop() currency: string = salla.config.get('user.currency_code');\n\n @State() tamaraIsActive: boolean;\n @State() tabbyIsActive: boolean;\n @State() spotiiIsActive: boolean;\n @State() mispayActive: boolean;\n\n @State() installment_sheria_text: (replacement: object) => string = (replacement) => salla.lang.get(\"pages.products.installments\", replacement)\n\n render() {\n return (\n <Host>\n {this.tamaraIsActive ?\n <div class=\"tamara-product-widget\"\n data-price={this.price}\n data-currency={this.currency}\n data-lang={this.language}\n data-payment-type=\"installment\">\n </div>\n : ''}\n\n {this.tabbyIsActive ?\n <div id=\"tabbyPromoWrapper\">\n <div id=\"tabbyPromo\"></div>\n </div>\n : ''}\n\n {this.spotiiIsActive ?\n <div class=\"spotii-wrapper\">\n {/*No need for the price, the price already in the page, and also tammara & tabby doesn't have price */}\n <div class=\"spotii-promo\"></div>\n </div>\n : ''}\n {this.mispayActive ?\n <div class=\"s-installment-mispay-wrapper\">\n <div class=\"s-installment-mispay-content\">\n <img src={salla.url.cdn('images/payment/png/mispay.png')} alt=\"mispay\" />\n <span class=\"s-installment-mispay-content-text\">{this.installment_sheria_text({ payment: salla.money(parseFloat(this.price)), amount: salla.money((parseFloat(this.price) / 3).toFixed(2)), installments: 3 })}</span>\n </div>\n </div>\n : ''}\n </Host>\n );\n }\n\n renderInstallments(isUpdating: boolean = false) {\n // Tamara\n if (this.tamaraIsActive) {\n if (isUpdating) {\n var oldTamaraScript = document.querySelector('script[src=\"https://cdn.tamara.co/widget/product-widget.min.js\"]');\n if (oldTamaraScript) {\n oldTamaraScript.remove();\n }\n }\n\n var tamaraScript = document.createElement('script');\n tamaraScript.setAttribute('src', 'https://cdn.tamara.co/widget/product-widget.min.js');\n document.head.appendChild(tamaraScript);\n tamaraScript.onload = () => {\n window.TamaraProductWidget.init({ lang: this.language });\n setTimeout(() => {\n window.TamaraProductWidget.render();\n }, 300);\n };\n }\n\n // tabby\n if (this.tabbyIsActive) {\n if (isUpdating) {\n\n // remove #tabbyPromoWrapper and re append it\n var oldTabbyWrapper = this.host.querySelector('#tabbyPromoWrapper');\n if (oldTabbyWrapper) {\n oldTabbyWrapper.remove();\n }\n\n var tabbyPromoWrapper = document.createElement('div');\n tabbyPromoWrapper.setAttribute('id', 'tabbyPromoWrapper');\n var tabbyPromo = document.createElement('div');\n tabbyPromo.setAttribute('id', 'tabbyPromo');\n tabbyPromoWrapper.appendChild(tabbyPromo);\n this.host.appendChild(tabbyPromoWrapper);\n\n var oldTabbyScript = document.querySelector('script[src=\"https://checkout.tabby.ai/tabby-promo.js\"]');\n if (oldTabbyScript) {\n oldTabbyScript.remove();\n }\n }\n\n var tabbyScript = document.createElement('script');\n tabbyScript.setAttribute('src', 'https://checkout.tabby.ai/tabby-promo.js');\n document.head.appendChild(tabbyScript);\n tabbyScript.onload = () => {\n const TabbyPromo = window.TabbyPromo;\n new TabbyPromo({\n selector: '#tabbyPromo',\n currency: this.currency,\n price: this.price,\n lang: this.language,\n });\n document.querySelectorAll('.tabby-promo-snippet__logo').forEach(function (element) {\n element.setAttribute('aria-label', 'Tabby Logo');\n });\n }\n // this is a workaround to remove the default border and add margin\n this.removeTabbyBorder();\n }\n\n // Spotii\n if (this.spotiiIsActive) {\n if (isUpdating) {\n\n var oldSpotiiWrapper = this.host.querySelector('.spotii-wrapper');\n if (oldSpotiiWrapper) {\n oldSpotiiWrapper.remove();\n }\n\n var spotiiPromoWrapper = document.createElement('div');\n spotiiPromoWrapper.classList.add('spotii-wrapper');\n var spotiiPromo = document.createElement('div');\n spotiiPromo.classList.add('spotii-promo');\n spotiiPromoWrapper.appendChild(spotiiPromo);\n this.host.appendChild(spotiiPromoWrapper);\n var oldSpotiiScript = document.querySelector('script[src=\"' + salla.url.cdn('js/price-widget-ar-salla.js') + '\"]');\n if (oldSpotiiScript) {\n oldSpotiiScript.remove();\n }\n }\n\n let amount = salla.money((Number(this.price) / 3).toFixed(2));\n let isRTL = salla.config.get('theme.is_rtl', true);\n window.spotiiConfig = {\n targetXPath: ['.spotii-wrapper'],\n renderToPath: ['.spotii-promo'],\n numberOfPayment: 3,\n currency: this.currency,\n templateLine: \"${textOne} ${number} ${textTwo} \" + amount + \"${logo} ${info}\",\n //todo:: translate these\n textOne: isRTL ? \"جزء الدفع على\" : \"Split it into\",\n textTwo: isRTL ? \"أقساط متساوية بدون تكاليف اضافية بقيمة\" : \"payments of\",\n textThree: \"مع\",\n price: this.price,\n // forcedShow: false,\n // merchantID: null,\n };\n\n var spotiiScript = document.createElement('script');\n spotiiScript.setAttribute('src', salla.url.cdn('js/price-widget-ar-salla.js'));\n document.head.appendChild(spotiiScript);\n // spotiiScript.onload = () => {\n // // setTimeout()\n // }\n }\n }\n\n\n /**\n * this is workaround to remove the default border and add margin\n * we will try to remove tabby border 5 times for 7.5 seconds\n */\n removeTabbyBorder() {\n if (this.tabbyBorderRemoved || this.tabbyRemoveBorderTries > 5) {\n return;\n }\n this.tabbyRemoveBorderTries++;\n setTimeout(() => {\n let promo: any = document.querySelector('#tabbyPromo>div>div');\n promo = promo ? promo.shadowRoot.querySelector('div[class^=\"styles__tabby-promo-snippet--\"]') : null;\n if (promo) {\n promo.style = 'border: none; margin: 15px 0!important;';\n this.tabbyBorderRemoved = true;\n } else {\n this.removeTabbyBorder();\n }\n }, this.tabbyRemoveBorderTries * 500)\n }\n}\n"],"m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AAAC,KACE,GAAIA,KAAKC,oBAAsBD,KAAKE,uBAAyB,EAAG,CAC9D,M,CAEFF,KAAKE,yBACLoD,YAAW,WACT,IAAI8B,EAAa1C,SAASC,cAAc,uBACxCyC,EAAQA,EAAQA,EAAMC,WAAW1C,cAAc,+CAAiD,KAChG,GAAIyC,EAAO,CACTA,EAAME,MAAQ,0CACdvF,EAAKE,mBAAqB,I,KACrB,CACLF,EAAKmE,mB,IAENlE,KAAKE,uBAAyB,I,kIAnNR,G"}
1
+ {"version":3,"names":["sallaInstallmentCss","SallaInstallment","hostRef","_this","this","tabbyBorderRemoved","tabbyRemoveBorderTries","salla","config","get","replacement","lang","onLoaded","installment_sheria_text","payment","money","parseFloat","price","amount","toFixed","installments","installment","tamaraIsActive","tamara","tabbyIsActive","tabby","spotiiIsActive","spotii","mispayActive","mispay","renderInstallments","event","on","_a","data","prototype","render","h","Host","class","currency","language","id","src","url","cdn","alt","isUpdating","oldTamaraScript","document","querySelector","remove","tamaraScript","createElement","setAttribute","head","appendChild","onload","window","TamaraProductWidget","init","setTimeout","oldTabbyWrapper","host","tabbyPromoWrapper","tabbyPromo","oldTabbyScript","tabbyScript","TabbyPromo","selector","publicKey","merchantCode","querySelectorAll","forEach","element","removeTabbyBorder","oldSpotiiWrapper","spotiiPromoWrapper","classList","add","spotiiPromo","oldSpotiiScript","Number","isRTL","spotiiConfig","targetXPath","renderToPath","numberOfPayment","templateLine","textOne","textTwo","textThree","spotiiScript","promo","shadowRoot","style"],"sources":["src/components/salla-installment/salla-installment.scss?tag=salla-installment","src/components/salla-installment/salla-installment.tsx"],"sourcesContent":["/*\n The whole installment methods is a third-party widgets,\n So there aren't a custom classes (as other components) to style them.\n*/\n\nsalla-installment:empty {\n display: none;\n}\n\n/*\n* Installment::Tabby\n*/\n#tabbyPromoWrapper {\n background: white;\n border-radius: 0.375rem;\n transition: box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);\n margin-bottom: 20px;\n\n .salla-y & {\n border: 1px solid var(--color-grey-dark);\n border-radius: 12px\n }\n\n &:hover {\n box-shadow: 0 0 #0000, 0 0 #0000, 5px 10px 30px #2B2D340D;\n }\n\n #tabbyPromo {\n * {\n font-family: var(--font-main);\n }\n\n >div>div {\n max-width: none;\n //padding: 15px;\n box-shadow: none;\n border: none;\n }\n\n .tabby-promo-snippet {\n max-width: 100%;\n min-height: 100px;\n padding: 18px 20px;\n // border-color: var(--color-grey-dark);\n border: none !important;\n\n\n &__text,\n &__link {\n font-size: var(--font-sm);\n color: var(--color-text) !important;\n }\n\n &__link {\n font-weight: bold;\n }\n }\n }\n}\n\n.tabby-promo-wrapper {\n #tabby-promo {\n font-family: var(--font-main) !important;\n\n .tabby-promo {\n &__feature-title {\n font-size: var(--font-md);\n }\n\n &__feature-desc {\n font-size: var(--font-sm);\n line-height: 20px;\n }\n }\n }\n}\n\n/*\n* Installment::Tamara & Spotii\n*/\n.tamara-product-widget {\n margin-bottom: 20px;\n}\n\n.tamara-product-widget,\n.spotii-wrapper {\n min-height: 100px;\n position: relative;\n color: var(--color-text);\n font-size: var(--font-sm);\n line-height: 1.25;\n padding: 18px 20px 18px 100px !important;\n background: white;\n border-radius: 0.375rem;\n transition: box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);\n\n .salla-y & {\n border-radius: 12px;\n border: 1px solid var(--color-grey-dark);\n }\n\n &:hover {\n box-shadow: 0 0 #0000, 0 0 #0000, 5px 10px 30px #2B2D340D;\n }\n\n .spotii-logo {\n float: left;\n margin: 0 0 0 -75px;\n }\n}\n\n.ltr .tamara-product-widget,\n.ltr .spotii-wrapper {\n text-align: left;\n padding: 18px 100px 18px 20px !important;\n\n .spotii-logo {\n float: right;\n margin: 0 -75px 0 0;\n }\n\n .spotii-product-widget {\n text-align: left !important;\n }\n}\n\n.spotii-wrapper {\n margin-bottom: 20px;\n\n .spotii-promo {\n font-size: var(--font-md);\n }\n\n .spotii-product-widget {\n font-size: var(--font-sm) !important;\n margin-top: 10px;\n }\n}\n\n.tamara-product-widget {\n .tamara-logo {\n position: absolute;\n left: 20px;\n top: 18px;\n margin: 0 !important;\n\n .ltr & {\n right: 20px;\n left: auto;\n }\n }\n\n span {\n font-family: var(--font-main);\n font-size: var(--font-sm);\n color: var(--color-text);\n\n &:last-child {\n display: block;\n position: relative;\n margin-top: 8px;\n }\n }\n}\n\n.tamara-popup {\n &__wrap {\n overflow: auto !important;\n }\n}\n\n.s-installment-mispay-wrapper {\n font-family: \"Noto Sans Arabic\", sans-serif;\n font-size: 14px;\n text-align: right;\n padding: 24px 20px 24px 0px;\n gap: 42px;\n direction: rtl;\n line-height: 22px;\n color: rgb(0, 0, 0);\n min-width: 100%;\n box-sizing: border-box;\n position: relative;\n background-color: white;\n border-radius: 10px;\n border: 1px solid var(--07--Light-Theme-Gray-color-gray-300, #EEE);\n margin: 15px 0;\n display: flex;\n transition: box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.s-installment-mispay-wrapper:hover {\n box-shadow: 0 0 #0000, 0 0 #0000, 5px 10px 30px #2B2D340D;\n}\n\n.s-installment-mispay-content {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin: 15px !important;\n}\n\n.s-installment-mispay-content-text {\n color: #292929;\n margin: 0 16px 0 0;\n width: 80%;\n position: absolute;\n left: 14px;\n text-align: left;\n}\n\n\n.s-installment-mispay-content img {\n height: 28px;\n width: 70px;\n display: inline-block;\n max-height: 100%;\n vertical-align: middle;\n fill: none;\n stroke: unset;\n width: auto;\n position: absolute;\n}\n\n.rtl .s-installment-mispay-content-text {\n right: 14px;\n text-align: right;\n margin: 0 0 0 16px;\n}\n\n.rtl .s-installment-mispay-content img {\n left: 14px !important;\n}\n\n.ltr .s-installment-mispay-content img {\n right: 14px !important;\n}\n","import { Component, Host, h, Prop, State, Element } from '@stencil/core';\n\n@Component({\n tag: 'salla-installment',\n styleUrl: 'salla-installment.scss',\n})\n\nexport class SallaInstallment {\n private tabbyBorderRemoved: boolean = false;\n private tabbyRemoveBorderTries: number = 0;\n @Element() host: HTMLElement;\n constructor() {\n salla.lang.onLoaded(() => {\n this.installment_sheria_text({ payment: salla.money(parseFloat(this.price)), amount: salla.money((parseFloat(this.price) / 3).toFixed(2)), installments: 3 })\n const installment = salla.config.get('store.settings.installments');\n if (installment) {\n this.tamaraIsActive = installment.tamara;\n this.tabbyIsActive = installment.tabby;\n this.spotiiIsActive = installment.spotii;\n this.mispayActive = installment.mispay;\n }\n this.renderInstallments();\n });\n\n salla.event.on('product::price.updated', ({ data }) => {\n if (!data.price || data.price == this.price) {\n return;\n }\n this.price = data.price;\n this.renderInstallments(true);\n });\n }\n\n /**\n * Current product price\n */\n @Prop() price: string;\n /**\n * Language code\n */\n @Prop() language: string = salla.config.get('user.language_code');\n /**\n * Currency code\n */\n @Prop() currency: string = salla.config.get('user.currency_code');\n\n @State() tamaraIsActive: boolean;\n @State() tabbyIsActive: boolean;\n @State() spotiiIsActive: boolean;\n @State() mispayActive: boolean;\n\n @State() installment_sheria_text: (replacement: object) => string = (replacement) => salla.lang.get(\"pages.products.installments\", replacement)\n\n render() {\n return (\n <Host>\n {this.tamaraIsActive ?\n <div class=\"tamara-product-widget\"\n data-price={this.price}\n data-currency={this.currency}\n data-lang={this.language}\n data-payment-type=\"installment\">\n </div>\n : ''}\n\n {this.tabbyIsActive ?\n <div id=\"tabbyPromoWrapper\">\n <div id=\"tabbyPromo\"></div>\n </div>\n : ''}\n\n {this.spotiiIsActive ?\n <div class=\"spotii-wrapper\">\n {/*No need for the price, the price already in the page, and also tammara & tabby doesn't have price */}\n <div class=\"spotii-promo\"></div>\n </div>\n : ''}\n {this.mispayActive ?\n <div class=\"s-installment-mispay-wrapper\">\n <div class=\"s-installment-mispay-content\">\n <img src={salla.url.cdn('images/payment/png/mispay.png')} alt=\"mispay\" />\n <span class=\"s-installment-mispay-content-text\">{this.installment_sheria_text({ payment: salla.money(parseFloat(this.price)), amount: salla.money((parseFloat(this.price) / 3).toFixed(2)), installments: 3 })}</span>\n </div>\n </div>\n : ''}\n </Host>\n );\n }\n\n renderInstallments(isUpdating: boolean = false) {\n // Tamara\n if (this.tamaraIsActive) {\n if (isUpdating) {\n var oldTamaraScript = document.querySelector('script[src=\"https://cdn.tamara.co/widget/product-widget.min.js\"]');\n if (oldTamaraScript) {\n oldTamaraScript.remove();\n }\n }\n\n var tamaraScript = document.createElement('script');\n tamaraScript.setAttribute('src', 'https://cdn.tamara.co/widget/product-widget.min.js');\n document.head.appendChild(tamaraScript);\n tamaraScript.onload = () => {\n window.TamaraProductWidget.init({ lang: this.language });\n setTimeout(() => {\n window.TamaraProductWidget.render();\n }, 300);\n };\n }\n\n // tabby\n if (this.tabbyIsActive) {\n if (isUpdating) {\n\n // remove #tabbyPromoWrapper and re append it\n var oldTabbyWrapper = this.host.querySelector('#tabbyPromoWrapper');\n if (oldTabbyWrapper) {\n oldTabbyWrapper.remove();\n }\n\n var tabbyPromoWrapper = document.createElement('div');\n tabbyPromoWrapper.setAttribute('id', 'tabbyPromoWrapper');\n var tabbyPromo = document.createElement('div');\n tabbyPromo.setAttribute('id', 'tabbyPromo');\n tabbyPromoWrapper.appendChild(tabbyPromo);\n this.host.appendChild(tabbyPromoWrapper);\n\n var oldTabbyScript = document.querySelector('script[src=\"https://checkout.tabby.ai/tabby-promo.js\"]');\n if (oldTabbyScript) {\n oldTabbyScript.remove();\n }\n }\n\n var tabbyScript = document.createElement('script');\n tabbyScript.setAttribute('src', 'https://checkout.tabby.ai/tabby-promo.js');\n document.head.appendChild(tabbyScript);\n tabbyScript.onload = () => {\n const TabbyPromo = window.TabbyPromo;\n new TabbyPromo({\n selector: '#tabbyPromo',\n currency: this.currency,\n price: this.price,\n lang: this.language,\n publicKey: salla.config.get('store.settings.installments.tabby.publicKey'),\n merchantCode: salla.config.get('store.settings.installments.tabby.merchantCode'),\n\n });\n document.querySelectorAll('.tabby-promo-snippet__logo').forEach(function (element) {\n element.setAttribute('aria-label', 'Tabby Logo');\n });\n }\n // this is a workaround to remove the default border and add margin\n this.removeTabbyBorder();\n }\n\n // Spotii\n if (this.spotiiIsActive) {\n if (isUpdating) {\n\n var oldSpotiiWrapper = this.host.querySelector('.spotii-wrapper');\n if (oldSpotiiWrapper) {\n oldSpotiiWrapper.remove();\n }\n\n var spotiiPromoWrapper = document.createElement('div');\n spotiiPromoWrapper.classList.add('spotii-wrapper');\n var spotiiPromo = document.createElement('div');\n spotiiPromo.classList.add('spotii-promo');\n spotiiPromoWrapper.appendChild(spotiiPromo);\n this.host.appendChild(spotiiPromoWrapper);\n var oldSpotiiScript = document.querySelector('script[src=\"' + salla.url.cdn('js/price-widget-ar-salla.js') + '\"]');\n if (oldSpotiiScript) {\n oldSpotiiScript.remove();\n }\n }\n\n let amount = salla.money((Number(this.price) / 3).toFixed(2));\n let isRTL = salla.config.get('theme.is_rtl', true);\n window.spotiiConfig = {\n targetXPath: ['.spotii-wrapper'],\n renderToPath: ['.spotii-promo'],\n numberOfPayment: 3,\n currency: this.currency,\n templateLine: \"${textOne} ${number} ${textTwo} \" + amount + \"${logo} ${info}\",\n //todo:: translate these\n textOne: isRTL ? \"جزء الدفع على\" : \"Split it into\",\n textTwo: isRTL ? \"أقساط متساوية بدون تكاليف اضافية بقيمة\" : \"payments of\",\n textThree: \"مع\",\n price: this.price,\n // forcedShow: false,\n // merchantID: null,\n };\n\n var spotiiScript = document.createElement('script');\n spotiiScript.setAttribute('src', salla.url.cdn('js/price-widget-ar-salla.js'));\n document.head.appendChild(spotiiScript);\n // spotiiScript.onload = () => {\n // // setTimeout()\n // }\n }\n }\n\n\n /**\n * this is workaround to remove the default border and add margin\n * we will try to remove tabby border 5 times for 7.5 seconds\n */\n removeTabbyBorder() {\n if (this.tabbyBorderRemoved || this.tabbyRemoveBorderTries > 5) {\n return;\n }\n this.tabbyRemoveBorderTries++;\n setTimeout(() => {\n let promo: any = document.querySelector('#tabbyPromo>div>div');\n promo = promo ? promo.shadowRoot.querySelector('div[class^=\"styles__tabby-promo-snippet--\"]') : null;\n if (promo) {\n promo.style = 'border: none; margin: 15px 0!important;';\n this.tabbyBorderRemoved = true;\n } else {\n this.removeTabbyBorder();\n }\n }, this.tabbyRemoveBorderTries * 500)\n }\n}\n"],"mappings":";;;mFAAA,IAAMA,oBAAsB,ohK,ICOfC,iBAAgB,WAI3B,SAAAA,EAAAC,GAAA,IAAAC,EAAAC,K,yBAHQA,KAAAC,mBAA8B,MAC9BD,KAAAE,uBAAiC,E,mCA+BdC,MAAMC,OAAOC,IAAI,sB,cAIjBF,MAAMC,OAAOC,IAAI,sB,kJAOwB,SAACC,GAAgB,OAAAH,MAAMI,KAAKF,IAAI,8BAA+BC,EAA9C,EAvCnFH,MAAMI,KAAKC,UAAS,WAClBT,EAAKU,wBAAwB,CAAEC,QAASP,MAAMQ,MAAMC,WAAWb,EAAKc,QAASC,OAAQX,MAAMQ,OAAOC,WAAWb,EAAKc,OAAS,GAAGE,QAAQ,IAAKC,aAAc,IACzJ,IAAMC,EAAcd,MAAMC,OAAOC,IAAI,+BACrC,GAAIY,EAAa,CACflB,EAAKmB,eAAiBD,EAAYE,OAClCpB,EAAKqB,cAAgBH,EAAYI,MACjCtB,EAAKuB,eAAiBL,EAAYM,OAClCxB,EAAKyB,aAAeP,EAAYQ,M,CAElC1B,EAAK2B,oB,IAGPvB,MAAMwB,MAAMC,GAAG,0BAA0B,SAACC,G,IAAEC,EAAID,EAAAC,KAC9C,IAAKA,EAAKjB,OAASiB,EAAKjB,OAASd,EAAKc,MAAO,CAC3C,M,CAEFd,EAAKc,MAAQiB,EAAKjB,MAClBd,EAAK2B,mBAAmB,K,IAwB5B7B,EAAAkC,UAAAC,OAAA,WACE,OACEC,EAACC,KAAI,KACFlC,KAAKkB,eACJe,EAAA,OAAKE,MAAM,wBAAuB,aACpBnC,KAAKa,MAAK,gBACPb,KAAKoC,SAAQ,YACjBpC,KAAKqC,SAAQ,oBACN,gBAElB,GAEHrC,KAAKoB,cACJa,EAAA,OAAKK,GAAG,qBACNL,EAAA,OAAKK,G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AAOb,KAAKa,OAKd,IAAI2E,EAAe3C,SAASI,cAAc,UAC1CuC,EAAatC,aAAa,MAAO/C,MAAMqC,IAAIC,IAAI,gCAC/CI,SAASM,KAAKC,YAAYoC,E,GAY9B3F,EAAAkC,UAAAwC,kBAAA,eAAAxE,EAAAC,KACE,GAAIA,KAAKC,oBAAsBD,KAAKE,uBAAyB,EAAG,CAC9D,M,CAEFF,KAAKE,yBACLuD,YAAW,WACT,IAAIgC,EAAa5C,SAASC,cAAc,uBACxC2C,EAAQA,EAAQA,EAAMC,WAAW5C,cAAc,+CAAiD,KAChG,GAAI2C,EAAO,CACTA,EAAME,MAAQ,0CACd5F,EAAKE,mBAAqB,I,KACrB,CACLF,EAAKwE,mB,IAENvE,KAAKE,uBAAyB,I,kIAtNR,G"}
@@ -1,5 +1,5 @@
1
1
  var __awaiter=this&&this.__awaiter||function(t,n,e,i){function o(t){return t instanceof e?t:new e((function(n){n(t)}))}return new(e||(e=Promise))((function(e,a){function r(t){try{l(i.next(t))}catch(t){a(t)}}function s(t){try{l(i["throw"](t))}catch(t){a(t)}}function l(t){t.done?e(t.value):o(t.value).then(r,s)}l((i=i.apply(t,n||[])).next())}))};var __generator=this&&this.__generator||function(t,n){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,o,a,r;return r={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(r[Symbol.iterator]=function(){return this}),r;function s(t){return function(n){return l([t,n])}}function l(s){if(i)throw new TypeError("Generator is already executing.");while(r&&(r=0,s[0]&&(e=0)),e)try{if(i=1,o&&(a=s[0]&2?o["return"]:s[0]?o["throw"]||((a=o["return"])&&a.call(o),0):o.next)&&!(a=a.call(o,s[1])).done)return a;if(o=0,a)s=[s[0]&2,a.value];switch(s[0]){case 0:case 1:a=s;break;case 4:e.label++;return{value:s[1],done:false};case 5:e.label++;o=s[1];s=[0];continue;case 7:s=e.ops.pop();e.trys.pop();continue;default:if(!(a=e.trys,a=a.length>0&&a[a.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){e.label=s[1];break}if(s[0]===6&&e.label<a[1]){e.label=a[1];a=s;break}if(a&&e.label<a[2]){e.label=a[2];e.ops.push(s);break}if(a[2])e.ops.pop();e.trys.pop();continue}s=n.call(t,e)}catch(t){s=[6,t];o=0}finally{i=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};
2
2
  /*!
3
3
  * Crafted with ❤ by Salla
4
- */import{r as registerInstance,c as createEvent,h,H as Host,g as getElement}from"./index-114c614f.js";import{C as CheckCircleIcon}from"./check-838f37a7.js";import{C as CameraIcon}from"./camera-d0a93c12.js";var DisplayType;(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["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"})(DisplayType||(DisplayType={}));var Currency;(function(t){t["Sar"]="SAR"})(Currency||(Currency={}));var FileIcon='\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';var sallaProductOptionsCss="";var SallaProductOptions=function(){function t(t){var n=this;registerInstance(this,t);this.changed=createEvent(this,"changed",7);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.outSkus=[];this.handleDonationOptions=function(t,e,i){if(e=="custom"&&i=="input"){salla.helpers.inputDigitsOnly(t.target);salla.event.emit("product-options::donation-changed",{id:n.productId,price:t.target.value});return}t.preventDefault();t.stopPropagation();n.isCustomDonation=t.target.value==="custom";if(n.donationInput){if(t.target.value==="custom"){n.donationInput.value="";n.donationInput.focus()}else{n.donationInput.value=t.target.value}if(e=="custom"){return}salla.event.emit("product-options::donation-changed",{id:n.productId,price:t.target.value})}};this.hideLabel=function(t){if(t.type===DisplayType.DONATION&&(t.donation&&!t.donation.can_donate)){return true}return false};this.getExpireDonationMessage=function(t){if(!t.donation){return}var n=t.donation.target_amount<=t.donation.collected_amount;return h("div",{class:{"s-product-options-donation-message":true,"s-product-options-donation-completed":n,"s-product-options-donation-expired":!n}},h("p",null,t.donation.target_message),h("span",null,n?salla.money(t.donation.target_amount):""))};this.optionsData=undefined;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=false;this.selectedOptions=[];this.canDisabled=undefined;this.selectedSkus=undefined;this.selectedOutSkus=undefined;this.productId=salla.config.get("page.id");this.options=undefined;this.canDisabled=!salla.config.get("store.settings.product.notify_options_availability");salla.lang.onLoaded((function(){n.outOfStockText=salla.lang.get("pages.products.out_of_stock");n.donationAmount=salla.lang.get("pages.products.donation_amount");n.selectDonationAmount=salla.lang.getWithDefault("pages.products.select_donation_amount","تحديد مبلغ التبرع");n.selectAmount=salla.lang.getWithDefault("pages.products.select_amount","اختر المبلغ")}));if(this.options){try{this.setOptionsData(Array.isArray(this.options)?this.options:JSON.parse(this.options));return}catch(t){salla.log("Bad json passed via options prop")}}if(!Array.isArray(this.optionsData)){salla.log("Options is not an array[] ---\x3e ",this.optionsData);this.setOptionsData([])}if(this.productId&&!salla.url.is_page("cart")){salla.api.product.getDetails(this.productId,["options"]).then((function(t){return n.setOptionsData(t.data.options)}))}}t.prototype.setOptionsData=function(t){var n,e;this.optionsData=t;var i=this;(e=(n=this.optionsData[0])===null||n===void 0?void 0:n.details)===null||e===void 0?void 0:e.forEach((function(t){Object.entries(t.skus_availability||{}).filter((function(t){return!t[1]})).map((function(t){return i.outSkus.push(Number(t[0]))}))}))};t.prototype.getSelectedOptionsData=function(){return __awaiter(this,void 0,void 0,(function(){var t,n;return __generator(this,(function(e){t={};n=this.host.getElementSallaData();n.forEach((function(n,e){e.startsWith("options[")&&(t[e.replace("options[","").replace("]","")]=n)}));return[2,t]}))}))};t.prototype.reportValidity=function(){return __awaiter(this,void 0,void 0,(function(){var t,n,e;return __generator(this,(function(i){t=this.host.querySelectorAll("[required]");n=true;for(e=0;e<t.length;e++){if("reportValidity"in t[e]&&!t[e].reportValidity()){n=false}}return[2,n]}))}))};t.prototype.hasOutOfStockOption=function(){return __awaiter(this,void 0,void 0,(function(){var t,n;var e=this;return __generator(this,(function(i){return[2,this.selectedOptions.some((function(t){return t.is_out}))||((t=this.selectedSkus)===null||t===void 0?void 0:t.length)&&((n=this.selectedSkus)===null||n===void 0?void 0:n.every((function(t){return e.outSkus.includes(t)})))]}))}))};t.prototype.getSelectedOptions=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,this.selectedOptions]}))}))};t.prototype.getOption=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(n){return[2,this.optionsData.find((function(n){return n.id===t}))]}))}))};t.prototype.invalidHandler=function(t,n){var e=t.target.closest(".s-product-options-option");if(!salla.url.is_page("cart")){e.scrollIntoView({behavior:"smooth",block:"center"})}e.classList.add("s-product-options-option-error")};t.prototype.changedHandler=function(t,n){var e={event:t,option:n,detail:null};if(n.details){var i=n.details.find((function(n){return Number(n.id)===Number(t.target.value)}));e.detail=i}var o=t.target.closest(".s-product-options-option");if(t.target.value||(n.type==DisplayType.FILE||n.type==DisplayType.IMAGE)&&t.type==="added"||n.type==DisplayType.MAP&&t.type==="selected"&&(t.target.lat&&t.target.lng)){setTimeout((function(){o.classList.remove("s-product-options-option-error")}),200)}var a=this.selectedOptions.findIndex((function(t){return t.option_id===e.option.id}));a>-1?this.selectedOptions[a]=Object.assign(Object.assign({},e.detail),{option_id:e.option.id}):this.selectedOptions.push(Object.assign(Object.assign({},e.detail),{option_id:e.option.id}));if(n.type==DisplayType.DONATION){salla.event.emit("product-options::donation-changed",{id:this.productId,price:t.target.value})}this.setSelectedSkus();this.handleRequiredMultipleOptions(n);this.changed.emit(e);salla.event.emit("product-options::change",e)};t.prototype.setSelectedSkus=function(){this.selectedSkus=this.selectedOptions.map((function(t){return Object.keys(t.skus_availability||{})})).reduce((function(t,n){return t.filter((function(t){return n.includes(t)}))})).map((function(t){return Number(t)}))};t.prototype.handleRequiredMultipleOptions=function(t){if(t.type!==DisplayType.MULTIPLE_OPTIONS||!t.required){return}var n=this.host.querySelector('[data-option-id="'.concat(t.id,'"]'));var e=n.querySelectorAll("input:checked").length;n.querySelectorAll("input").forEach((function(t){return t.toggleAttribute("required",!e)}))};t.prototype.getLatLng=function(t,n){return t?t.split(",")[n=="lat"?0:1]:""};t.prototype.getDisplayForType=function(t){if(this["".concat(t.type,"Option")]){return this["".concat(t.type,"Option")](t)}if(t.type===DisplayType.COLOR_PICKER){return this.colorPickerOption(t)}if(t.type===DisplayType.MULTIPLE_OPTIONS){return this.multipleOptions(t)}if(t.type===DisplayType.SINGLE_OPTION){return this.singleOption(t)}salla.log("Couldn't find options type(".concat(t.type,")😢"));return""};t.prototype.getOptionShownWhen=function(t){return t.visibility_condition?{"data-show-when":"options[".concat(t.visibility_condition.option,"] ").concat(t.visibility_condition.operator," ").concat(t.visibility_condition.value)}:{}};t.prototype.componentWillLoad=function(){this.outOfStockText=salla.lang.get("pages.products.out_of_stock");return new Promise((function(t){return salla.onReady(t)})).then((function(){return salla.api.cart.getCurrentCartId()}))};t.prototype.render=function(){var t=this;var n;if(((n=this.optionsData)===null||n===void 0?void 0:n.length)==0){return}return h(Host,{class:"s-product-options-wrapper"},h("salla-conditional-fields",null,this.optionsData.map((function(n){return h("div",Object.assign({class:"s-product-options-option-container".concat(n.visibility_condition?" hidden":""),"data-option-id":n.id},t.getOptionShownWhen(n)),n.name=="splitter"?t.splitterOption():h("div",{class:"s-product-options-option","data-option-type":n.type,"data-option-required":"".concat(n.required)},h("label",{htmlFor:"options["+n.id+"]",class:"s-product-options-option-label ".concat(t.hideLabel(n)?"s-product-options-option-label-hidden":"")},h("b",null,n.name,n.required&&h("span",null," * ")," "),h("small",null,n.placeholder)),h("div",{class:"s-product-options-option-content ".concat(t.hideLabel(n)?"s-product-options-option-content-full-width":"")},t.getDisplayForType(n))))}))))};t.prototype.componentDidLoad=function(){var t=this;var n,e;if(((n=this.optionsData)===null||n===void 0?void 0:n.length)==0&&!this.optionsData.some((function(t){return t.type==DisplayType.DONATION}))){return}var i=(e=this.optionsData.find((function(t){return t.type==DisplayType.DONATION})))===null||e===void 0?void 0:e.details.find((function(t){return t.is_selected}));if(!i){return}setTimeout((function(){salla.event.emit("product-options::donation-changed",{id:t.productId,price:i.additional_price})}),1e3)};t.prototype.donationOption=function(t,n){var e=this;var i,o;return h("div",{class:"s-product-options-donation-wrapper"},((i=t.donation)===null||i===void 0?void 0:i.can_donate)?[t.donation?h("div",{class:"s-product-options-donation-progress"},h("salla-progress-bar",{donation:t.donation})):"",t.details.length?[h("h4",null,this.selectAmount),h("div",{class:"s-product-options-donation-options"},t.details.map((function(t,n){return h("div",{class:"s-product-options-donation-options-item"},h("input",{id:"donation-option-".concat(n),type:"radio",name:"donating_option",checked:t.is_selected,value:t.additional_price,onChange:function(n){return e.handleDonationOptions(n,t,"option")}}),h("label",{htmlFor:"donation-option-".concat(n)},h("span",null,salla.money(t.name))))})),((o=t.donation)===null||o===void 0?void 0:o.custom_amount_enabled)?h("div",{class:"s-product-options-donation-options-item"},h("input",{id:"donation-option-custom",type:"radio",name:"donating_option",value:"custom",onChange:function(t){return e.handleDonationOptions(t,"custom","option")}}),h("label",{htmlFor:"donation-option-custom"},h("span",null," ",this.selectDonationAmount," "))):"")]:"",h("div",{class:{"s-product-options-donation-input-group":true,shown:!t.details.length||t.details.length&&this.isCustomDonation}},h("input",{type:"text",id:"donating-amount",name:"donation_amount",class:"s-form-control",ref:function(t){return e.donationInput=t},value:t.details.length&&t.details.some((function(t){return t.is_selected}))?t.details.find((function(t){return t.is_selected})).additional_price:t.value,placeholder:t.placeholder,onInput:function(t){return e.handleDonationOptions(t,"custom","input")},onBlur:function(n){return e.changedHandler(n,t)},onInvalid:function(n){return e.invalidHandler(n,t)}}),h("span",{class:"s-product-options-donation-amount-currency"},salla.config.currency(salla.config.get("user.currency_code")).symbol))]:this.getExpireDonationMessage(t))};t.prototype.fileUploader=function(t,n){var e=this;if(n===void 0){n=null}return h("salla-file-upload",Object.assign({},n||{},{"payload-name":"file",value:t.value,"instant-upload":true,name:"options[".concat(t.id,"]"),required:!t.visibility_condition&&t.required,height:"120px",onAdded:function(n){return e.changedHandler(n,t)},url:salla.cart.api.getUploadImageEndpoint(),"form-data":{cart_item_id:this.productId,product_id:this.productId},onInvalidInput:function(n){return e.invalidHandler(n,t)},class:{"s-product-options-image-input":true,required:t.required}}),h("div",{class:"s-product-options-filepond-placeholder"},h("span",{class:"s-product-options-filepond-placeholder-icon",innerHTML:n.accept&&n.accept.split(",").every((function(t){return t.includes("image")}))?CameraIcon:FileIcon}),h("p",{class:"s-product-options-filepond-placeholder-text"},salla.lang.get("common.uploader.drag_and_drop")),h("span",{class:"filepond--label-action"},salla.lang.get("common.uploader.browse"))))};t.prototype.imageOption=function(t){return this.fileUploader(t,{accept:"image/png,image/jpeg,image/jpg,image/gif"})};t.prototype.fileOption=function(t){var n=this;var e=t.details.map((function(t){return n.fileTypes[t.name]})).filter(Boolean);return(e===null||e===void 0?void 0:e.length)?this.fileUploader(t,{accept:e.join(",")}):"File types not selected."};t.prototype.numberOption=function(t){var n=this;return h("input",{type:"text",value:t.value,class:"s-form-control",required:!t.visibility_condition&&t.required,name:"options[".concat(t.id,"]"),placeholder:t.placeholder,onBlur:function(e){return n.changedHandler(e,t)},onInvalid:function(e){return n.invalidHandler(e,t)},onInput:function(t){return salla.helpers.inputDigitsOnly(t.target)}})};t.prototype.splitterOption=function(){return h("div",{class:"s-product-options-splitter"})};t.prototype.textOption=function(t){var n=this;return h("div",{class:"s-product-options-text"},h("input",{type:"text",value:t.value,maxLength:t===null||t===void 0?void 0:t.length,class:"s-form-control",required:!t.visibility_condition&&t.required,name:"options[".concat(t.id,"]"),placeholder:t.placeholder,onInvalid:function(e){return n.invalidHandler(e,t)},onInput:function(e){return n.changedHandler(e,t)}}))};t.prototype.textareaOption=function(t){var n=this;return h("div",{class:"s-product-options-textarea"},h("div",{class:"mt-1"},h("textarea",{rows:4,value:t.value,maxLength:t===null||t===void 0?void 0:t.length,class:"s-form-control",required:!t.visibility_condition&&t.required,id:"options[".concat(t.id,"]"),name:"options[".concat(t.id,"]"),placeholder:t.placeholder,onInvalid:function(e){return n.invalidHandler(e,t)},onInput:function(e){return n.changedHandler(e,t)}})))};t.prototype.mapOption=function(t){var n=this;return h("salla-map",{zoom:15,lat:this.getLatLng(t.value,"lat"),lng:this.getLatLng(t.value,"lng"),name:"options[".concat(t.id,"]"),searchable:true,required:t.required,onInvalidInput:function(e){return n.invalidHandler(e,t)},onSelected:function(e){return n.changedHandler(e,t)}})};t.prototype.colorPickerOption=function(t){var n=this;return h("salla-color-picker",{onSubmitted:function(e){return n.changedHandler(e,t)},name:"options[".concat(t.id,"]"),required:!t.visibility_condition&&t.required,onInvalidInput:function(e){return n.invalidHandler(e,t)},color:t.value})};t.prototype.timeOption=function(t){var n=this;return h("salla-datetime-picker",{noCalendar:true,enableTime:true,dateFormat:"h:i K",value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,name:"options[".concat(t.id,"]"),class:"s-product-options-time-element",onInvalidInput:function(e){return n.invalidHandler(e,t)},onPicked:function(e){return n.changedHandler(e,t)}})};t.prototype.dateOption=function(t){var n=this;return h("div",{class:"s-product-options-date-element"},h("salla-datetime-picker",{value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,minDate:new Date,name:"options[".concat(t.id,"]"),onInvalidInput:function(e){return n.invalidHandler(e,t)},onPicked:function(e){return n.changedHandler(e,t)}}))};t.prototype.datetimeOption=function(t){var n=this;return h("div",{class:"s-product-options-datetime-element"},h("salla-datetime-picker",{enableTime:true,value:t.value,dateFormat:"Y-m-d G:i:K",placeholder:t.name,required:!t.visibility_condition&&t.required,name:"options[".concat(t.id,"]"),maxDate:t.to_date_time,minDate:t.from_date_time,onInvalidInput:function(e){return n.invalidHandler(e,t)},onPicked:function(e){return n.changedHandler(e,t)}}))};t.prototype.getOptionDetailName=function(t,n,e){if(n===void 0){n=true}if(e&&e==DisplayType.COLOR){return t.name+(n&&this.isOptionDetailOut(t)?" <br/> <p> ".concat(this.outOfStockText," </p>"):"")+(t.additional_price?" <p> (".concat(salla.money(t.additional_price),") </p>"):"")}return t.name+(n&&this.isOptionDetailOut(t)?" - ".concat(this.outOfStockText):"")+(t.additional_price?" (".concat(salla.money(t.additional_price),")"):"")};t.prototype.isOptionDetailOut=function(t){var n=this;var e;if(t.is_out||!t.skus_availability||!((e=this.selectedSkus)===null||e===void 0?void 0:e.length)){return t.is_out}var i=this.selectedOptions.filter((function(n){return n.id==t.id})).length;if(i&&this.selectedOptions.length==1){return false}if(i){var o=this.selectedSkus.filter((function(t){return n.outSkus.includes(t)}));return Object.keys(t.skus_availability).some((function(t){return o.includes(Number(t))}))}return this.selectedOptions.some((function(n){return n.is_out&&n.option_id!==t.option_id}))};t.prototype.singleOption=function(t){var n=this;return h("div",null,h("select",{name:"options[".concat(t.id,"]"),required:!t.visibility_condition&&t.required,class:"s-form-control",onInvalid:function(e){return n.invalidHandler(e,t)},onChange:function(e){return n.changedHandler(e,t)}},h("option",{value:""},t.placeholder),t===null||t===void 0?void 0:t.details.map((function(t){return h("option",{value:t.id,disabled:n.canDisabled&&n.isOptionDetailOut(t),selected:t.is_selected},n.getOptionDetailName(t))}))))};t.prototype.multipleOptions=function(t){var n=this;var e=t.required&&!t.details.some((function(t){return t.is_selected}))&&!t.visibility_condition;return h("div",{class:{"s-product-options-multiple-options-wrapper":true,required:t.required}},t===null||t===void 0?void 0:t.details.map((function(i){return h("div",null,h("input",{type:"checkbox",value:i.id,disabled:n.isOptionDetailOut(i),checked:i.is_selected,required:e,name:"options[".concat(t.id,"][]"),id:"field-".concat(t.id,"-").concat(i.id),onChange:function(e){return n.changedHandler(e,t)},onInvalid:function(e){return n.invalidHandler(e,t)},"aria-describedby":"options[".concat(t.id,"]-description")}),h("label",{htmlFor:"field-".concat(t.id,"-").concat(i.id)},n.getOptionDetailName(i)))})))};t.prototype.colorOption=function(t){var n=this;return h("fieldset",{class:"s-product-options-colors-wrapper"},t===null||t===void 0?void 0:t.details.map((function(e){return h("div",{class:"s-product-options-colors-item"},h("input",{type:"radio",value:e.id,required:!t.visibility_condition&&t.required,checked:e.is_selected,name:"options[".concat(t.id,"]"),disabled:n.canDisabled&&n.isOptionDetailOut(e),id:"color-".concat(n.productId,"-").concat(t.id,"-").concat(e.id),onInvalid:function(e){return n.invalidHandler(e,t)},onChange:function(e){return n.changedHandler(e,t)}}),h("label",{htmlFor:"color-".concat(n.productId,"-").concat(t.id,"-").concat(e.id)},h("span",{style:{"background-color":e.color}}),h("div",{innerHTML:n.getOptionDetailName(e,true,t.type)})))})))};t.prototype.thumbnailOption=function(t){var n=this;return h("div",{class:"s-product-options-thumbnails-wrapper"},t.details.map((function(e){return h("div",null,h("input",{type:"radio",value:e.id,"data-itemid":e.id,required:!t.visibility_condition&&t.required,checked:e.is_selected,name:"options[".concat(t.id,"]"),"data-img-id":e.option_value,disabled:n.canDisabled&&n.isOptionDetailOut(e),id:"option_".concat(n.productId,"-").concat(t.id,"_").concat(e.id),onInvalid:function(e){return n.invalidHandler(e,t)},onChange:function(e){return n.changedHandler(e,t)}}),h("label",{htmlFor:"option_".concat(n.productId,"-").concat(t.id,"_").concat(e.id),"data-img-id":e.option_value,class:"go-to-slide"},h("img",{"data-src":e.image,src:e.image,title:e.name,alt:e.name}),h("span",{innerHTML:CheckCircleIcon,class:"s-product-options-thumbnails-icon"}),n.isOptionDetailOut(e)?[h("small",{class:"s-product-options-thumbnails-stock-badge"},n.outOfStockText),n.canDisabled?h("div",{class:"s-product-options-thumbnails-badge-overlay"}):""]:""),h("p",null,n.getOptionDetailName(e,false)," "))})))};Object.defineProperty(t.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return t}();SallaProductOptions.style=sallaProductOptionsCss;export{SallaProductOptions as salla_product_options};
4
+ */import{r as registerInstance,c as createEvent,h,H as Host,g as getElement}from"./index-114c614f.js";import{C as CheckCircleIcon}from"./check-838f37a7.js";import{C as CameraIcon}from"./camera-d0a93c12.js";var DisplayType;(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["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"})(DisplayType||(DisplayType={}));var Currency;(function(t){t["Sar"]="SAR"})(Currency||(Currency={}));var FileIcon='\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';var sallaProductOptionsCss="";var SallaProductOptions=function(){function t(t){var n=this;registerInstance(this,t);this.changed=createEvent(this,"changed",7);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.outSkus=[];this.handleDonationOptions=function(t,e,i){if(e=="custom"&&i=="input"){salla.helpers.inputDigitsOnly(t.target);salla.event.emit("product-options::donation-changed",{id:n.productId,price:t.target.value});return}t.preventDefault();t.stopPropagation();n.isCustomDonation=t.target.value==="custom";if(n.donationInput){if(t.target.value==="custom"){n.donationInput.value="";n.donationInput.focus()}else{n.donationInput.value=t.target.value}if(e=="custom"){return}salla.event.emit("product-options::donation-changed",{id:n.productId,price:t.target.value})}};this.hideLabel=function(t){if(t.type===DisplayType.DONATION&&(t.donation&&!t.donation.can_donate)){return true}return false};this.getExpireDonationMessage=function(t){if(!t.donation){return}var n=t.donation.target_amount<=t.donation.collected_amount;return h("div",{class:{"s-product-options-donation-message":true,"s-product-options-donation-completed":n,"s-product-options-donation-expired":!n}},h("p",null,t.donation.target_message),h("span",null,n?salla.money(t.donation.target_amount):""))};this.optionsData=undefined;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=false;this.selectedOptions=[];this.canDisabled=undefined;this.selectedSkus=undefined;this.selectedOutSkus=undefined;this.productId=salla.config.get("page.id");this.options=undefined;this.canDisabled=!salla.config.get("store.settings.product.notify_options_availability");salla.lang.onLoaded((function(){n.outOfStockText=salla.lang.get("pages.products.out_of_stock");n.donationAmount=salla.lang.get("pages.products.donation_amount");n.selectDonationAmount=salla.lang.getWithDefault("pages.products.select_donation_amount","تحديد مبلغ التبرع");n.selectAmount=salla.lang.getWithDefault("pages.products.select_amount","اختر المبلغ")}));if(this.options){try{this.setOptionsData(Array.isArray(this.options)?this.options:JSON.parse(this.options));return}catch(t){salla.log("Bad json passed via options prop")}}if(!Array.isArray(this.optionsData)){salla.log("Options is not an array[] ---\x3e ",this.optionsData);this.setOptionsData([])}if(this.productId&&!salla.url.is_page("cart")){salla.api.product.getDetails(this.productId,["options"]).then((function(t){return n.setOptionsData(t.data.options)}))}}t.prototype.setOptionsData=function(t){var n,e;this.optionsData=t;var i=this;(e=(n=this.optionsData[0])===null||n===void 0?void 0:n.details)===null||e===void 0?void 0:e.forEach((function(t){Object.entries(t.skus_availability||{}).filter((function(t){return!t[1]})).map((function(t){return i.outSkus.push(Number(t[0]))}))}))};t.prototype.getSelectedOptionsData=function(){return __awaiter(this,void 0,void 0,(function(){var t,n;return __generator(this,(function(e){t={};n=this.host.getElementSallaData();n.forEach((function(n,e){e.startsWith("options[")&&(t[e.replace("options[","").replace("]","")]=n)}));return[2,t]}))}))};t.prototype.reportValidity=function(){return __awaiter(this,void 0,void 0,(function(){var t,n,e;return __generator(this,(function(i){t=this.host.querySelectorAll("[required]");n=true;for(e=0;e<t.length;e++){if("reportValidity"in t[e]&&!t[e].reportValidity()){n=false}}return[2,n]}))}))};t.prototype.hasOutOfStockOption=function(){return __awaiter(this,void 0,void 0,(function(){var t,n;var e=this;return __generator(this,(function(i){return[2,this.selectedOptions.some((function(t){return t.is_out}))||((t=this.selectedSkus)===null||t===void 0?void 0:t.length)&&((n=this.selectedSkus)===null||n===void 0?void 0:n.every((function(t){return e.outSkus.includes(t)})))]}))}))};t.prototype.getSelectedOptions=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,this.selectedOptions]}))}))};t.prototype.getOption=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(n){return[2,this.optionsData.find((function(n){return n.id===t}))]}))}))};t.prototype.invalidHandler=function(t,n){var e=t.target.closest(".s-product-options-option");if(!salla.url.is_page("cart")){e.scrollIntoView({behavior:"smooth",block:"center"})}e.classList.add("s-product-options-option-error")};t.prototype.changedHandler=function(t,n){var e={event:t,option:n,detail:null};if(n.details){var i=n.details.find((function(n){return Number(n.id)===Number(t.target.value)}));e.detail=i}var o=t.target.closest(".s-product-options-option");if(t.target.value||(n.type==DisplayType.FILE||n.type==DisplayType.IMAGE)&&t.type==="added"||n.type==DisplayType.MAP&&t.type==="selected"&&(t.target.lat&&t.target.lng)){setTimeout((function(){o.classList.remove("s-product-options-option-error")}),200)}var a=this.selectedOptions.findIndex((function(t){return t.option_id===e.option.id}));a>-1?this.selectedOptions[a]=Object.assign(Object.assign({},e.detail),{option_id:e.option.id}):this.selectedOptions.push(Object.assign(Object.assign({},e.detail),{option_id:e.option.id}));if(n.type==DisplayType.DONATION){salla.event.emit("product-options::donation-changed",{id:this.productId,price:t.target.value})}this.setSelectedSkus();this.handleRequiredMultipleOptions(n);this.changed.emit(e);salla.event.emit("product-options::change",e)};t.prototype.setSelectedSkus=function(){this.selectedSkus=this.selectedOptions.map((function(t){return Object.keys(t.skus_availability||{})})).reduce((function(t,n){return t.filter((function(t){return n.includes(t)}))})).map((function(t){return Number(t)}))};t.prototype.handleRequiredMultipleOptions=function(t){if(t.type!==DisplayType.MULTIPLE_OPTIONS||!t.required){return}var n=this.host.querySelector('[data-option-id="'.concat(t.id,'"]'));var e=n.querySelectorAll("input:checked").length;n.querySelectorAll("input").forEach((function(t){return t.toggleAttribute("required",!e)}))};t.prototype.getLatLng=function(t,n){return t?t.split(",")[n=="lat"?0:1]:""};t.prototype.getDisplayForType=function(t){if(this["".concat(t.type,"Option")]){return this["".concat(t.type,"Option")](t)}if(t.type===DisplayType.COLOR_PICKER){return this.colorPickerOption(t)}if(t.type===DisplayType.MULTIPLE_OPTIONS){return this.multipleOptions(t)}if(t.type===DisplayType.SINGLE_OPTION){return this.singleOption(t)}salla.log("Couldn't find options type(".concat(t.type,")😢"));return""};t.prototype.getOptionShownWhen=function(t){return t.visibility_condition?{"data-show-when":"options[".concat(t.visibility_condition.option,"] ").concat(t.visibility_condition.operator," ").concat(t.visibility_condition.value)}:{}};t.prototype.componentWillLoad=function(){this.outOfStockText=salla.lang.get("pages.products.out_of_stock");return new Promise((function(t){return salla.onReady(t)})).then((function(){return salla.api.cart.getCurrentCartId(false,"salla-product-options-component-will-load-hook")}))};t.prototype.render=function(){var t=this;var n;if(((n=this.optionsData)===null||n===void 0?void 0:n.length)==0){return}return h(Host,{class:"s-product-options-wrapper"},h("salla-conditional-fields",null,this.optionsData.map((function(n){return h("div",Object.assign({class:"s-product-options-option-container".concat(n.visibility_condition?" hidden":""),"data-option-id":n.id},t.getOptionShownWhen(n)),n.name=="splitter"?t.splitterOption():h("div",{class:"s-product-options-option","data-option-type":n.type,"data-option-required":"".concat(n.required)},h("label",{htmlFor:"options["+n.id+"]",class:"s-product-options-option-label ".concat(t.hideLabel(n)?"s-product-options-option-label-hidden":"")},h("b",null,n.name,n.required&&h("span",null," * ")," "),h("small",null,n.placeholder)),h("div",{class:"s-product-options-option-content ".concat(t.hideLabel(n)?"s-product-options-option-content-full-width":"")},t.getDisplayForType(n))))}))))};t.prototype.componentDidLoad=function(){var t=this;var n,e;if(((n=this.optionsData)===null||n===void 0?void 0:n.length)==0&&!this.optionsData.some((function(t){return t.type==DisplayType.DONATION}))){return}var i=(e=this.optionsData.find((function(t){return t.type==DisplayType.DONATION})))===null||e===void 0?void 0:e.details.find((function(t){return t.is_selected}));if(!i){return}setTimeout((function(){salla.event.emit("product-options::donation-changed",{id:t.productId,price:i.additional_price})}),1e3)};t.prototype.donationOption=function(t,n){var e=this;var i,o;return h("div",{class:"s-product-options-donation-wrapper"},((i=t.donation)===null||i===void 0?void 0:i.can_donate)?[t.donation?h("div",{class:"s-product-options-donation-progress"},h("salla-progress-bar",{donation:t.donation})):"",t.details.length?[h("h4",null,this.selectAmount),h("div",{class:"s-product-options-donation-options"},t.details.map((function(t,n){return h("div",{class:"s-product-options-donation-options-item"},h("input",{id:"donation-option-".concat(n),type:"radio",name:"donating_option",checked:t.is_selected,value:t.additional_price,onChange:function(n){return e.handleDonationOptions(n,t,"option")}}),h("label",{htmlFor:"donation-option-".concat(n)},h("span",null,salla.money(t.name))))})),((o=t.donation)===null||o===void 0?void 0:o.custom_amount_enabled)?h("div",{class:"s-product-options-donation-options-item"},h("input",{id:"donation-option-custom",type:"radio",name:"donating_option",value:"custom",onChange:function(t){return e.handleDonationOptions(t,"custom","option")}}),h("label",{htmlFor:"donation-option-custom"},h("span",null," ",this.selectDonationAmount," "))):"")]:"",h("div",{class:{"s-product-options-donation-input-group":true,shown:!t.details.length||t.details.length&&this.isCustomDonation}},h("input",{type:"text",id:"donating-amount",name:"donation_amount",class:"s-form-control",ref:function(t){return e.donationInput=t},value:t.details.length&&t.details.some((function(t){return t.is_selected}))?t.details.find((function(t){return t.is_selected})).additional_price:t.value,placeholder:t.placeholder,onInput:function(t){return e.handleDonationOptions(t,"custom","input")},onBlur:function(n){return e.changedHandler(n,t)},onInvalid:function(n){return e.invalidHandler(n,t)}}),h("span",{class:"s-product-options-donation-amount-currency"},salla.config.currency(salla.config.get("user.currency_code")).symbol))]:this.getExpireDonationMessage(t))};t.prototype.fileUploader=function(t,n){var e=this;if(n===void 0){n=null}return h("salla-file-upload",Object.assign({},n||{},{"payload-name":"file",value:t.value,"instant-upload":true,name:"options[".concat(t.id,"]"),required:!t.visibility_condition&&t.required,height:"120px",onAdded:function(n){return e.changedHandler(n,t)},url:salla.cart.api.getUploadImageEndpoint(),"form-data":{cart_item_id:this.productId,product_id:this.productId},onInvalidInput:function(n){return e.invalidHandler(n,t)},class:{"s-product-options-image-input":true,required:t.required}}),h("div",{class:"s-product-options-filepond-placeholder"},h("span",{class:"s-product-options-filepond-placeholder-icon",innerHTML:n.accept&&n.accept.split(",").every((function(t){return t.includes("image")}))?CameraIcon:FileIcon}),h("p",{class:"s-product-options-filepond-placeholder-text"},salla.lang.get("common.uploader.drag_and_drop")),h("span",{class:"filepond--label-action"},salla.lang.get("common.uploader.browse"))))};t.prototype.imageOption=function(t){return this.fileUploader(t,{accept:"image/png,image/jpeg,image/jpg,image/gif"})};t.prototype.fileOption=function(t){var n=this;var e=t.details.map((function(t){return n.fileTypes[t.name]})).filter(Boolean);return(e===null||e===void 0?void 0:e.length)?this.fileUploader(t,{accept:e.join(",")}):"File types not selected."};t.prototype.numberOption=function(t){var n=this;return h("input",{type:"text",value:t.value,class:"s-form-control",required:!t.visibility_condition&&t.required,name:"options[".concat(t.id,"]"),placeholder:t.placeholder,onBlur:function(e){return n.changedHandler(e,t)},onInvalid:function(e){return n.invalidHandler(e,t)},onInput:function(t){return salla.helpers.inputDigitsOnly(t.target)}})};t.prototype.splitterOption=function(){return h("div",{class:"s-product-options-splitter"})};t.prototype.textOption=function(t){var n=this;return h("div",{class:"s-product-options-text"},h("input",{type:"text",value:t.value,maxLength:t===null||t===void 0?void 0:t.length,class:"s-form-control",required:!t.visibility_condition&&t.required,name:"options[".concat(t.id,"]"),placeholder:t.placeholder,onInvalid:function(e){return n.invalidHandler(e,t)},onInput:function(e){return n.changedHandler(e,t)}}))};t.prototype.textareaOption=function(t){var n=this;return h("div",{class:"s-product-options-textarea"},h("div",{class:"mt-1"},h("textarea",{rows:4,value:t.value,maxLength:t===null||t===void 0?void 0:t.length,class:"s-form-control",required:!t.visibility_condition&&t.required,id:"options[".concat(t.id,"]"),name:"options[".concat(t.id,"]"),placeholder:t.placeholder,onInvalid:function(e){return n.invalidHandler(e,t)},onInput:function(e){return n.changedHandler(e,t)}})))};t.prototype.mapOption=function(t){var n=this;return h("salla-map",{zoom:15,lat:this.getLatLng(t.value,"lat"),lng:this.getLatLng(t.value,"lng"),name:"options[".concat(t.id,"]"),searchable:true,required:t.required,onInvalidInput:function(e){return n.invalidHandler(e,t)},onSelected:function(e){return n.changedHandler(e,t)}})};t.prototype.colorPickerOption=function(t){var n=this;return h("salla-color-picker",{onSubmitted:function(e){return n.changedHandler(e,t)},name:"options[".concat(t.id,"]"),required:!t.visibility_condition&&t.required,onInvalidInput:function(e){return n.invalidHandler(e,t)},color:t.value})};t.prototype.timeOption=function(t){var n=this;return h("salla-datetime-picker",{noCalendar:true,enableTime:true,dateFormat:"h:i K",value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,name:"options[".concat(t.id,"]"),class:"s-product-options-time-element",onInvalidInput:function(e){return n.invalidHandler(e,t)},onPicked:function(e){return n.changedHandler(e,t)}})};t.prototype.dateOption=function(t){var n=this;return h("div",{class:"s-product-options-date-element"},h("salla-datetime-picker",{value:t.value,placeholder:t.name,required:!t.visibility_condition&&t.required,minDate:new Date,name:"options[".concat(t.id,"]"),onInvalidInput:function(e){return n.invalidHandler(e,t)},onPicked:function(e){return n.changedHandler(e,t)}}))};t.prototype.datetimeOption=function(t){var n=this;return h("div",{class:"s-product-options-datetime-element"},h("salla-datetime-picker",{enableTime:true,value:t.value,dateFormat:"Y-m-d G:i:K",placeholder:t.name,required:!t.visibility_condition&&t.required,name:"options[".concat(t.id,"]"),maxDate:t.to_date_time,minDate:t.from_date_time,onInvalidInput:function(e){return n.invalidHandler(e,t)},onPicked:function(e){return n.changedHandler(e,t)}}))};t.prototype.getOptionDetailName=function(t,n,e){if(n===void 0){n=true}if(e&&e==DisplayType.COLOR){return t.name+(n&&this.isOptionDetailOut(t)?" <br/> <p> ".concat(this.outOfStockText," </p>"):"")+(t.additional_price?" <p> (".concat(salla.money(t.additional_price),") </p>"):"")}return t.name+(n&&this.isOptionDetailOut(t)?" - ".concat(this.outOfStockText):"")+(t.additional_price?" (".concat(salla.money(t.additional_price),")"):"")};t.prototype.isOptionDetailOut=function(t){var n=this;var e;if(t.is_out||!t.skus_availability||!((e=this.selectedSkus)===null||e===void 0?void 0:e.length)){return t.is_out}var i=this.selectedOptions.filter((function(n){return n.id==t.id})).length;if(i&&this.selectedOptions.length==1){return false}if(i){var o=this.selectedSkus.filter((function(t){return n.outSkus.includes(t)}));return Object.keys(t.skus_availability).some((function(t){return o.includes(Number(t))}))}return this.selectedOptions.some((function(n){return n.is_out&&n.option_id!==t.option_id}))};t.prototype.singleOption=function(t){var n=this;return h("div",null,h("select",{name:"options[".concat(t.id,"]"),required:!t.visibility_condition&&t.required,class:"s-form-control",onInvalid:function(e){return n.invalidHandler(e,t)},onChange:function(e){return n.changedHandler(e,t)}},h("option",{value:""},t.placeholder),t===null||t===void 0?void 0:t.details.map((function(t){return h("option",{value:t.id,disabled:n.canDisabled&&n.isOptionDetailOut(t),selected:t.is_selected},n.getOptionDetailName(t))}))))};t.prototype.multipleOptions=function(t){var n=this;var e=t.required&&!t.details.some((function(t){return t.is_selected}))&&!t.visibility_condition;return h("div",{class:{"s-product-options-multiple-options-wrapper":true,required:t.required}},t===null||t===void 0?void 0:t.details.map((function(i){return h("div",null,h("input",{type:"checkbox",value:i.id,disabled:n.isOptionDetailOut(i),checked:i.is_selected,required:e,name:"options[".concat(t.id,"][]"),id:"field-".concat(t.id,"-").concat(i.id),onChange:function(e){return n.changedHandler(e,t)},onInvalid:function(e){return n.invalidHandler(e,t)},"aria-describedby":"options[".concat(t.id,"]-description")}),h("label",{htmlFor:"field-".concat(t.id,"-").concat(i.id)},n.getOptionDetailName(i)))})))};t.prototype.colorOption=function(t){var n=this;return h("fieldset",{class:"s-product-options-colors-wrapper"},t===null||t===void 0?void 0:t.details.map((function(e){return h("div",{class:"s-product-options-colors-item"},h("input",{type:"radio",value:e.id,required:!t.visibility_condition&&t.required,checked:e.is_selected,name:"options[".concat(t.id,"]"),disabled:n.canDisabled&&n.isOptionDetailOut(e),id:"color-".concat(n.productId,"-").concat(t.id,"-").concat(e.id),onInvalid:function(e){return n.invalidHandler(e,t)},onChange:function(e){return n.changedHandler(e,t)}}),h("label",{htmlFor:"color-".concat(n.productId,"-").concat(t.id,"-").concat(e.id)},h("span",{style:{"background-color":e.color}}),h("div",{innerHTML:n.getOptionDetailName(e,true,t.type)})))})))};t.prototype.thumbnailOption=function(t){var n=this;return h("div",{class:"s-product-options-thumbnails-wrapper"},t.details.map((function(e){return h("div",null,h("input",{type:"radio",value:e.id,"data-itemid":e.id,required:!t.visibility_condition&&t.required,checked:e.is_selected,name:"options[".concat(t.id,"]"),"data-img-id":e.option_value,disabled:n.canDisabled&&n.isOptionDetailOut(e),id:"option_".concat(n.productId,"-").concat(t.id,"_").concat(e.id),onInvalid:function(e){return n.invalidHandler(e,t)},onChange:function(e){return n.changedHandler(e,t)}}),h("label",{htmlFor:"option_".concat(n.productId,"-").concat(t.id,"_").concat(e.id),"data-img-id":e.option_value,class:"go-to-slide"},h("img",{"data-src":e.image,src:e.image,title:e.name,alt:e.name}),h("span",{innerHTML:CheckCircleIcon,class:"s-product-options-thumbnails-icon"}),n.isOptionDetailOut(e)?[h("small",{class:"s-product-options-thumbnails-stock-badge"},n.outOfStockText),n.canDisabled?h("div",{class:"s-product-options-thumbnails-badge-overlay"}):""]:""),h("p",null,n.getOptionDetailName(e,false)," "))})))};Object.defineProperty(t.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return t}();SallaProductOptions.style=sallaProductOptionsCss;export{SallaProductOptions as salla_product_options};
5
5
  //# sourceMappingURL=salla-product-options.entry.js.map