@salla.sa/twilight-components 2.11.74 → 2.11.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.
@@ -88,6 +88,9 @@ const SallaAddProductButton = class {
88
88
  }
89
89
  return this.hostAttributes;
90
90
  }
91
+ getQuickBuyBtnAttributes() {
92
+ return Object.assign(Object.assign({}, this.getBtnAttributes()), { type: this.supportStickyBar && window.innerWidth <= 768 ? 'plain' : 'buy' });
93
+ }
91
94
  componentWillLoad() {
92
95
  this.passedLabel = this.host.innerHTML.replace('<!---->', '').trim();
93
96
  if (this.host.hasAttribute('type') && this.host.getAttribute('type') === 'submit' && this.supportStickyBar) {
@@ -114,7 +117,7 @@ const SallaAddProductButton = class {
114
117
  if ((this.productStatus === 'out-and-notify' && this.channels) || this.hasOutOfStockOption) {
115
118
  return index.h(index.Host, null, index.h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), index.h("span", { class: "s-hidden" }, index.h("slot", null))));
116
119
  }
117
- return index.h(index.Host, { class: { 's-add-product-button-with-quick-buy': this.showQuickBuy, 's-add-product-button-with-sticky-bar': this.supportStickyBar } }, index.h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), index.h("slot", null)), this.showQuickBuy ? index.h("salla-quick-buy", Object.assign({}, this.getBtnAttributes())) : '');
120
+ return index.h(index.Host, { class: { 's-add-product-button-with-quick-buy': this.showQuickBuy, 's-add-product-button-with-sticky-bar': this.supportStickyBar } }, index.h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), index.h("slot", null)), this.showQuickBuy ? index.h("salla-quick-buy", Object.assign({}, this.getQuickBuyBtnAttributes())) : '');
118
121
  }
119
122
  componentDidLoad() {
120
123
  if (!this.notifyOptionsAvailability) {
@@ -144,7 +147,7 @@ const SallaAddProductButton = class {
144
147
  componentDidRender() {
145
148
  var _a;
146
149
  //if label not passed, get label
147
- if (!!this.passedLabel && window.innerWidth >= 768) {
150
+ if (!!this.passedLabel && !this.supportStickyBar) {
148
151
  return;
149
152
  }
150
153
  (_a = this.btn) === null || _a === void 0 ? void 0 : _a.setText(this.getLabel());
@@ -26110,9 +26110,6 @@ const SallaQuickBuy = class {
26110
26110
  if (!this.productId && salla.config.get('page.id')) {
26111
26111
  this.productId = salla.config.get('page.id');
26112
26112
  }
26113
- if (window.innerWidth <= 768 && this.type !== 'plain') {
26114
- this.type = 'plain';
26115
- }
26116
26113
  if (!this.productId) {
26117
26114
  salla.logger.warn('🍏 Pay: Failed load the quick buy, the product id is missing');
26118
26115
  return reject();
@@ -78,6 +78,9 @@ export class SallaAddProductButton {
78
78
  }
79
79
  return this.hostAttributes;
80
80
  }
81
+ getQuickBuyBtnAttributes() {
82
+ return Object.assign(Object.assign({}, this.getBtnAttributes()), { type: this.supportStickyBar && window.innerWidth <= 768 ? 'plain' : 'buy' });
83
+ }
81
84
  componentWillLoad() {
82
85
  this.passedLabel = this.host.innerHTML.replace('<!---->', '').trim();
83
86
  if (this.host.hasAttribute('type') && this.host.getAttribute('type') === 'submit' && this.supportStickyBar) {
@@ -113,7 +116,7 @@ export class SallaAddProductButton {
113
116
  return h(Host, { class: { 's-add-product-button-with-quick-buy': this.showQuickBuy, 's-add-product-button-with-sticky-bar': this.supportStickyBar } },
114
117
  h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }),
115
118
  h("slot", null)),
116
- this.showQuickBuy ? h("salla-quick-buy", Object.assign({}, this.getBtnAttributes())) : '');
119
+ this.showQuickBuy ? h("salla-quick-buy", Object.assign({}, this.getQuickBuyBtnAttributes())) : '');
117
120
  }
118
121
  componentDidLoad() {
119
122
  if (!this.notifyOptionsAvailability) {
@@ -143,7 +146,7 @@ export class SallaAddProductButton {
143
146
  componentDidRender() {
144
147
  var _a;
145
148
  //if label not passed, get label
146
- if (!!this.passedLabel && window.innerWidth >= 768) {
149
+ if (!!this.passedLabel && !this.supportStickyBar) {
147
150
  return;
148
151
  }
149
152
  (_a = this.btn) === null || _a === void 0 ? void 0 : _a.setText(this.getLabel());
@@ -122,9 +122,6 @@ export class SallaQuickBuy {
122
122
  if (!this.productId && salla.config.get('page.id')) {
123
123
  this.productId = salla.config.get('page.id');
124
124
  }
125
- if (window.innerWidth <= 768 && this.type !== 'plain') {
126
- this.type = 'plain';
127
- }
128
125
  if (!this.productId) {
129
126
  salla.logger.warn('🍏 Pay: Failed load the quick buy, the product id is missing');
130
127
  return reject();
@@ -91,6 +91,9 @@ const SallaAddProductButton$1 = /*@__PURE__*/ proxyCustomElement(class extends H
91
91
  }
92
92
  return this.hostAttributes;
93
93
  }
94
+ getQuickBuyBtnAttributes() {
95
+ return Object.assign(Object.assign({}, this.getBtnAttributes()), { type: this.supportStickyBar && window.innerWidth <= 768 ? 'plain' : 'buy' });
96
+ }
94
97
  componentWillLoad() {
95
98
  this.passedLabel = this.host.innerHTML.replace('<!---->', '').trim();
96
99
  if (this.host.hasAttribute('type') && this.host.getAttribute('type') === 'submit' && this.supportStickyBar) {
@@ -117,7 +120,7 @@ const SallaAddProductButton$1 = /*@__PURE__*/ proxyCustomElement(class extends H
117
120
  if ((this.productStatus === 'out-and-notify' && this.channels) || this.hasOutOfStockOption) {
118
121
  return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), h("span", { class: "s-hidden" }, h("slot", null))));
119
122
  }
120
- return h(Host, { class: { 's-add-product-button-with-quick-buy': this.showQuickBuy, 's-add-product-button-with-sticky-bar': this.supportStickyBar } }, h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), h("slot", null)), this.showQuickBuy ? h("salla-quick-buy", Object.assign({}, this.getBtnAttributes())) : '');
123
+ return h(Host, { class: { 's-add-product-button-with-quick-buy': this.showQuickBuy, 's-add-product-button-with-sticky-bar': this.supportStickyBar } }, h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), h("slot", null)), this.showQuickBuy ? h("salla-quick-buy", Object.assign({}, this.getQuickBuyBtnAttributes())) : '');
121
124
  }
122
125
  componentDidLoad() {
123
126
  if (!this.notifyOptionsAvailability) {
@@ -147,7 +150,7 @@ const SallaAddProductButton$1 = /*@__PURE__*/ proxyCustomElement(class extends H
147
150
  componentDidRender() {
148
151
  var _a;
149
152
  //if label not passed, get label
150
- if (!!this.passedLabel && window.innerWidth >= 768) {
153
+ if (!!this.passedLabel && !this.supportStickyBar) {
151
154
  return;
152
155
  }
153
156
  (_a = this.btn) === null || _a === void 0 ? void 0 : _a.setText(this.getLabel());
@@ -2525,9 +2525,6 @@ const SallaQuickBuy = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement
2525
2525
  if (!this.productId && salla.config.get('page.id')) {
2526
2526
  this.productId = salla.config.get('page.id');
2527
2527
  }
2528
- if (window.innerWidth <= 768 && this.type !== 'plain') {
2529
- this.type = 'plain';
2530
- }
2531
2528
  if (!this.productId) {
2532
2529
  salla.logger.warn('🍏 Pay: Failed load the quick buy, the product id is missing');
2533
2530
  return reject();
@@ -84,6 +84,9 @@ const SallaAddProductButton = class {
84
84
  }
85
85
  return this.hostAttributes;
86
86
  }
87
+ getQuickBuyBtnAttributes() {
88
+ return Object.assign(Object.assign({}, this.getBtnAttributes()), { type: this.supportStickyBar && window.innerWidth <= 768 ? 'plain' : 'buy' });
89
+ }
87
90
  componentWillLoad() {
88
91
  this.passedLabel = this.host.innerHTML.replace('<!---->', '').trim();
89
92
  if (this.host.hasAttribute('type') && this.host.getAttribute('type') === 'submit' && this.supportStickyBar) {
@@ -110,7 +113,7 @@ const SallaAddProductButton = class {
110
113
  if ((this.productStatus === 'out-and-notify' && this.channels) || this.hasOutOfStockOption) {
111
114
  return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), h("span", { class: "s-hidden" }, h("slot", null))));
112
115
  }
113
- return h(Host, { class: { 's-add-product-button-with-quick-buy': this.showQuickBuy, 's-add-product-button-with-sticky-bar': this.supportStickyBar } }, h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), h("slot", null)), this.showQuickBuy ? h("salla-quick-buy", Object.assign({}, this.getBtnAttributes())) : '');
116
+ return h(Host, { class: { 's-add-product-button-with-quick-buy': this.showQuickBuy, 's-add-product-button-with-sticky-bar': this.supportStickyBar } }, h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), h("slot", null)), this.showQuickBuy ? h("salla-quick-buy", Object.assign({}, this.getQuickBuyBtnAttributes())) : '');
114
117
  }
115
118
  componentDidLoad() {
116
119
  if (!this.notifyOptionsAvailability) {
@@ -140,7 +143,7 @@ const SallaAddProductButton = class {
140
143
  componentDidRender() {
141
144
  var _a;
142
145
  //if label not passed, get label
143
- if (!!this.passedLabel && window.innerWidth >= 768) {
146
+ if (!!this.passedLabel && !this.supportStickyBar) {
144
147
  return;
145
148
  }
146
149
  (_a = this.btn) === null || _a === void 0 ? void 0 : _a.setText(this.getLabel());
@@ -26106,9 +26106,6 @@ const SallaQuickBuy = class {
26106
26106
  if (!this.productId && salla.config.get('page.id')) {
26107
26107
  this.productId = salla.config.get('page.id');
26108
26108
  }
26109
- if (window.innerWidth <= 768 && this.type !== 'plain') {
26110
- this.type = 'plain';
26111
- }
26112
26109
  if (!this.productId) {
26113
26110
  salla.logger.warn('🍏 Pay: Failed load the quick buy, the product id is missing');
26114
26111
  return reject();
@@ -1,4 +1,4 @@
1
- var __awaiter=this&&this.__awaiter||function(t,e,i,n){function s(t){return t instanceof i?t:new i((function(e){e(t)}))}return new(i||(i=Promise))((function(i,o){function r(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n["throw"](t))}catch(t){o(t)}}function u(t){t.done?i(t.value):s(t.value).then(r,a)}u((n=n.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var i={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,s,o,r;return r={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(r[Symbol.iterator]=function(){return this}),r;function a(t){return function(e){return u([t,e])}}function u(r){if(n)throw new TypeError("Generator is already executing.");while(i)try{if(n=1,s&&(o=r[0]&2?s["return"]:r[0]?s["throw"]||((o=s["return"])&&o.call(s),0):s.next)&&!(o=o.call(s,r[1])).done)return o;if(s=0,o)r=[r[0]&2,o.value];switch(r[0]){case 0:case 1:o=r;break;case 4:i.label++;return{value:r[1],done:false};case 5:i.label++;s=r[1];r=[0];continue;case 7:r=i.ops.pop();i.trys.pop();continue;default:if(!(o=i.trys,o=o.length>0&&o[o.length-1])&&(r[0]===6||r[0]===2)){i=0;continue}if(r[0]===3&&(!o||r[1]>o[0]&&r[1]<o[3])){i.label=r[1];break}if(r[0]===6&&i.label<o[1]){i.label=o[1];o=r;break}if(o&&i.label<o[2]){i.label=o[2];i.ops.push(r);break}if(o[2])i.ops.pop();i.trys.pop();continue}r=e.call(t,i)}catch(t){r=[6,t];s=0}finally{n=o=0}if(r[0]&5)throw r[1];return{value:r[0]?r[1]:void 0,done:true}}};
1
+ var __awaiter=this&&this.__awaiter||function(t,e,i,s){function n(t){return t instanceof i?t:new i((function(e){e(t)}))}return new(i||(i=Promise))((function(i,o){function r(t){try{u(s.next(t))}catch(t){o(t)}}function a(t){try{u(s["throw"](t))}catch(t){o(t)}}function u(t){t.done?i(t.value):n(t.value).then(r,a)}u((s=s.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var i={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},s,n,o,r;return r={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(r[Symbol.iterator]=function(){return this}),r;function a(t){return function(e){return u([t,e])}}function u(r){if(s)throw new TypeError("Generator is already executing.");while(i)try{if(s=1,n&&(o=r[0]&2?n["return"]:r[0]?n["throw"]||((o=n["return"])&&o.call(n),0):n.next)&&!(o=o.call(n,r[1])).done)return o;if(n=0,o)r=[r[0]&2,o.value];switch(r[0]){case 0:case 1:o=r;break;case 4:i.label++;return{value:r[1],done:false};case 5:i.label++;n=r[1];r=[0];continue;case 7:r=i.ops.pop();i.trys.pop();continue;default:if(!(o=i.trys,o=o.length>0&&o[o.length-1])&&(r[0]===6||r[0]===2)){i=0;continue}if(r[0]===3&&(!o||r[1]>o[0]&&r[1]<o[3])){i.label=r[1];break}if(r[0]===6&&i.label<o[1]){i.label=o[1];o=r;break}if(o&&i.label<o[2]){i.label=o[2];i.ops.push(r);break}if(o[2])i.ops.pop();i.trys.pop();continue}r=e.call(t,i)}catch(t){r=[6,t];n=0}finally{s=o=0}if(r[0]&5)throw r[1];return{value:r[0]?r[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-f1d446ac.js";import{C as Cart}from"./cart-8c60b447.js";var sallaAddProductButtonCss=":host{display:block}salla-add-product-button[width=wide]{width:100%}";var SallaAddProductButton=function(){function t(t){var e=this;registerInstance(this,t);this.success=createEvent(this,"success",7);this.failed=createEvent(this,"failed",7);this.hostAttributes={};this.productStatus="sale";this.productType="product";this.selectedOptions=[];salla.onReady((function(){e.showQuickBuy=e.quickBuy&&!!salla.config.get("store.settings.buy_now")}))}t.prototype.getLabel=function(){if(this.productStatus==="sale"){if(this.supportStickyBar&&window.innerWidth<=768){return Cart}return salla.lang.get("pages.cart.add_to_cart")}if(this.productType!=="donating"){return salla.lang.get("pages.products.out_of_stock")}return salla.lang.get("pages.products.donation_exceed")};t.prototype.addProductToCart=function(t){var e=this;if(this.productType==="booking"){t.preventDefault();return this.addBookingProduct()}if(this.hostAttributes.type==="submit"){return false}t.preventDefault();var i=Object.entries({id:this.productId,donating_amount:this.donatingAmount,quantity:this.quantity,endpoint:"quickAdd"}).reduce((function(t,e){var i=e[0],n=e[1];return n?(t[i]=n,t):t}),{});return salla.cart.addItem(i).then((function(t){e.selectedOptions=[];e.success.emit(t)})).catch((function(t){return e.failed.emit(t)}))};t.prototype.addBookingProduct=function(){var t=this;if(salla.config.isGuest()){salla.auth.api.setAfterLoginEvent("booking::add",this.productId);salla.event.dispatch("login::open");return}return salla.booking.add(this.productId).then((function(e){return t.success.emit(e)})).catch((function(e){return t.failed.emit(e)}))};t.prototype.getBtnAttributes=function(){for(var t=0;t<this.host.attributes.length;t++){if(!["id","class"].includes(this.host.attributes[t].name)){this.hostAttributes[this.host.attributes[t].name]=this.host.attributes[t].value}}return this.hostAttributes};t.prototype.componentWillLoad=function(){var t=this;this.passedLabel=this.host.innerHTML.replace("\x3c!----\x3e","").trim();if(this.host.hasAttribute("type")&&this.host.getAttribute("type")==="submit"&&this.supportStickyBar){window.addEventListener("resize",(function(){var e,i;if(window.innerWidth>=768&&!!t.passedLabel){(e=t.btn)===null||e===void 0?void 0:e.setText(t.passedLabel)}else{(i=t.btn)===null||i===void 0?void 0:i.setText(t.getLabel())}}))}};t.prototype.render=function(){var t=this;var e;if((e=this.host.closest(".swiper-slide"))===null||e===void 0?void 0:e.classList.contains("swiper-slide-duplicate")){return""}if(this.hasSubscribedOptions){return h(Host,null,h("salla-product-availability",Object.assign({},this.getBtnAttributes(),{"is-subscribed":true}),h("span",{class:"s-hidden"},h("slot",null))))}if(this.productStatus==="out-and-notify"&&this.channels||this.hasOutOfStockOption){return h(Host,null,h("salla-product-availability",Object.assign({},this.getBtnAttributes()),h("span",{class:"s-hidden"},h("slot",null))))}return h(Host,{class:{"s-add-product-button-with-quick-buy":this.showQuickBuy,"s-add-product-button-with-sticky-bar":this.supportStickyBar}},h("salla-button",Object.assign({color:this.productStatus==="sale"?"primary":"light",type:"button",fill:this.productStatus==="sale"?"solid":"outline",ref:function(e){return t.btn=e},onClick:function(e){return t.addProductToCart(e)},disabled:this.productStatus!=="sale"},this.getBtnAttributes(),{"loader-position":"center"}),h("slot",null)),this.showQuickBuy?h("salla-quick-buy",Object.assign({},this.getBtnAttributes())):"")};t.prototype.componentDidLoad=function(){var t=this;if(!this.notifyOptionsAvailability){return}salla.event.on("product-options::change",(function(e){return __awaiter(t,void 0,void 0,(function(){var t,i,n,s,o,r;var a=this;return __generator(this,(function(u){switch(u.label){case 0:if(!["thumbnail","color","single-option"].includes(e.option.type)){return[2]}this.hasSubscribedOptions=false;n=this;return[4,(t=document.querySelector('salla-product-options[product-id="'.concat(this.productId,'"]')))===null||t===void 0?void 0:t.getSelectedOptions()];case 1:n.selectedOptions=u.sent();s=this;return[4,(i=document.querySelector('salla-product-options[product-id="'.concat(this.productId,'"]')))===null||i===void 0?void 0:i.hasOutOfStockOption()];case 2:s.hasOutOfStockOption=u.sent();o=salla.storage.get("product-".concat(this.productId,"-subscribed-options"));if(!o&&!this.subscribedOptions||!this.hasOutOfStockOption){return[2]}if(salla.config.isGuest()){r=o?o.map((function(t){return t.split(",").map((function(t){return parseInt(t)}))})):[];this.hasSubscribedOptions=r.length>0&&r.some((function(t){return t.every((function(t){return a.selectedOptions.some((function(e){return e.id===t}))}))}))}else{this.hasSubscribedOptions=this.subscribedOptions&&this.subscribedOptions!=="null"&&this.subscribedOptions!=="[]"?JSON.parse(this.subscribedOptions).some((function(t){return t.every((function(t){return a.selectedOptions.some((function(e){return e.id===t}))}))})):false}return[2]}}))}))}))};t.prototype.componentDidRender=function(){var t=this;var e;if(!!this.passedLabel&&window.innerWidth>=768){return}(e=this.btn)===null||e===void 0?void 0:e.setText(this.getLabel());salla.lang.onLoaded((function(){var e;return(e=t.btn)===null||e===void 0?void 0:e.setText(t.getLabel())}))};Object.defineProperty(t.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return t}();SallaAddProductButton.style=sallaAddProductButtonCss;export{SallaAddProductButton as salla_add_product_button};
4
+ */import{r as registerInstance,c as createEvent,h,H as Host,g as getElement}from"./index-f1d446ac.js";import{C as Cart}from"./cart-8c60b447.js";var sallaAddProductButtonCss=":host{display:block}salla-add-product-button[width=wide]{width:100%}";var SallaAddProductButton=function(){function t(t){var e=this;registerInstance(this,t);this.success=createEvent(this,"success",7);this.failed=createEvent(this,"failed",7);this.hostAttributes={};this.productStatus="sale";this.productType="product";this.selectedOptions=[];salla.onReady((function(){e.showQuickBuy=e.quickBuy&&!!salla.config.get("store.settings.buy_now")}))}t.prototype.getLabel=function(){if(this.productStatus==="sale"){if(this.supportStickyBar&&window.innerWidth<=768){return Cart}return salla.lang.get("pages.cart.add_to_cart")}if(this.productType!=="donating"){return salla.lang.get("pages.products.out_of_stock")}return salla.lang.get("pages.products.donation_exceed")};t.prototype.addProductToCart=function(t){var e=this;if(this.productType==="booking"){t.preventDefault();return this.addBookingProduct()}if(this.hostAttributes.type==="submit"){return false}t.preventDefault();var i=Object.entries({id:this.productId,donating_amount:this.donatingAmount,quantity:this.quantity,endpoint:"quickAdd"}).reduce((function(t,e){var i=e[0],s=e[1];return s?(t[i]=s,t):t}),{});return salla.cart.addItem(i).then((function(t){e.selectedOptions=[];e.success.emit(t)})).catch((function(t){return e.failed.emit(t)}))};t.prototype.addBookingProduct=function(){var t=this;if(salla.config.isGuest()){salla.auth.api.setAfterLoginEvent("booking::add",this.productId);salla.event.dispatch("login::open");return}return salla.booking.add(this.productId).then((function(e){return t.success.emit(e)})).catch((function(e){return t.failed.emit(e)}))};t.prototype.getBtnAttributes=function(){for(var t=0;t<this.host.attributes.length;t++){if(!["id","class"].includes(this.host.attributes[t].name)){this.hostAttributes[this.host.attributes[t].name]=this.host.attributes[t].value}}return this.hostAttributes};t.prototype.getQuickBuyBtnAttributes=function(){return Object.assign(Object.assign({},this.getBtnAttributes()),{type:this.supportStickyBar&&window.innerWidth<=768?"plain":"buy"})};t.prototype.componentWillLoad=function(){var t=this;this.passedLabel=this.host.innerHTML.replace("\x3c!----\x3e","").trim();if(this.host.hasAttribute("type")&&this.host.getAttribute("type")==="submit"&&this.supportStickyBar){window.addEventListener("resize",(function(){var e,i;if(window.innerWidth>=768&&!!t.passedLabel){(e=t.btn)===null||e===void 0?void 0:e.setText(t.passedLabel)}else{(i=t.btn)===null||i===void 0?void 0:i.setText(t.getLabel())}}))}};t.prototype.render=function(){var t=this;var e;if((e=this.host.closest(".swiper-slide"))===null||e===void 0?void 0:e.classList.contains("swiper-slide-duplicate")){return""}if(this.hasSubscribedOptions){return h(Host,null,h("salla-product-availability",Object.assign({},this.getBtnAttributes(),{"is-subscribed":true}),h("span",{class:"s-hidden"},h("slot",null))))}if(this.productStatus==="out-and-notify"&&this.channels||this.hasOutOfStockOption){return h(Host,null,h("salla-product-availability",Object.assign({},this.getBtnAttributes()),h("span",{class:"s-hidden"},h("slot",null))))}return h(Host,{class:{"s-add-product-button-with-quick-buy":this.showQuickBuy,"s-add-product-button-with-sticky-bar":this.supportStickyBar}},h("salla-button",Object.assign({color:this.productStatus==="sale"?"primary":"light",type:"button",fill:this.productStatus==="sale"?"solid":"outline",ref:function(e){return t.btn=e},onClick:function(e){return t.addProductToCart(e)},disabled:this.productStatus!=="sale"},this.getBtnAttributes(),{"loader-position":"center"}),h("slot",null)),this.showQuickBuy?h("salla-quick-buy",Object.assign({},this.getQuickBuyBtnAttributes())):"")};t.prototype.componentDidLoad=function(){var t=this;if(!this.notifyOptionsAvailability){return}salla.event.on("product-options::change",(function(e){return __awaiter(t,void 0,void 0,(function(){var t,i,s,n,o,r;var a=this;return __generator(this,(function(u){switch(u.label){case 0:if(!["thumbnail","color","single-option"].includes(e.option.type)){return[2]}this.hasSubscribedOptions=false;s=this;return[4,(t=document.querySelector('salla-product-options[product-id="'.concat(this.productId,'"]')))===null||t===void 0?void 0:t.getSelectedOptions()];case 1:s.selectedOptions=u.sent();n=this;return[4,(i=document.querySelector('salla-product-options[product-id="'.concat(this.productId,'"]')))===null||i===void 0?void 0:i.hasOutOfStockOption()];case 2:n.hasOutOfStockOption=u.sent();o=salla.storage.get("product-".concat(this.productId,"-subscribed-options"));if(!o&&!this.subscribedOptions||!this.hasOutOfStockOption){return[2]}if(salla.config.isGuest()){r=o?o.map((function(t){return t.split(",").map((function(t){return parseInt(t)}))})):[];this.hasSubscribedOptions=r.length>0&&r.some((function(t){return t.every((function(t){return a.selectedOptions.some((function(e){return e.id===t}))}))}))}else{this.hasSubscribedOptions=this.subscribedOptions&&this.subscribedOptions!=="null"&&this.subscribedOptions!=="[]"?JSON.parse(this.subscribedOptions).some((function(t){return t.every((function(t){return a.selectedOptions.some((function(e){return e.id===t}))}))})):false}return[2]}}))}))}))};t.prototype.componentDidRender=function(){var t=this;var e;if(!!this.passedLabel&&!this.supportStickyBar){return}(e=this.btn)===null||e===void 0?void 0:e.setText(this.getLabel());salla.lang.onLoaded((function(){var e;return(e=t.btn)===null||e===void 0?void 0:e.setText(t.getLabel())}))};Object.defineProperty(t.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return t}();SallaAddProductButton.style=sallaAddProductButtonCss;export{SallaAddProductButton as salla_add_product_button};