@salla.sa/twilight 2.7.11 → 2.7.12

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.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import e from"eventemitter2";import t from"axios";import n from"jwt-decode";import r from"infinite-scroll";import a from"lang.js";import i from"store/src/store-engine";import o from"store/storages/localStorage";import s from"store/storages/sessionStorage";import l from"store/storages/cookieStorage";import c from"store/storages/memoryStorage";var u=function(e,t,n){return alert(e)},d=function(e,t){return u(e,h.error,t)},h={error:"error",success:"success",info:"info"},f={fire:function(e,t,n){return u(e,t,n)},setNotifier:function(e){u=e},error:d,success:function(e,t){return u(e,h.success,t)},info:function(e,t){return u(e,h.info,t)},sallaInitiated:function(){var e=window.location.href.match(/([\?\&]danger=)[^&]+/g);e&&e.forEach((function(e){d(decodeURI(e.replace("?danger=","").replace("&danger=","")))}))},types:h};function p(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?p(Object(n),!0).forEach((function(t){F(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function g(){
2
2
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3
- g=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},a=r.iterator||"@@iterator",i=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function l(e,t,n,r){var a=t&&t.prototype instanceof d?t:d,i=Object.create(a.prototype),o=new x(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(a,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===a)throw i;return A()}for(n.method=a,n.arg=i;;){var o=n.delegate;if(o){var s=k(o,n);if(s){if(s===u)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var l=c(e,t,n);if("normal"===l.type){if(r=n.done?"completed":"suspendedYield",l.arg===u)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(r="completed",n.method="throw",n.arg=l.arg)}}}(e,n,o),i}function c(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var u={};function d(){}function h(){}function f(){}var p={};s(p,a,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(S([])));y&&y!==t&&n.call(y,a)&&(p=y);var m=f.prototype=d.prototype=Object.create(p);function b(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function r(a,i,o,s){var l=c(e[a],e,i);if("throw"!==l.type){var u=l.arg,d=u.value;return d&&"object"==typeof d&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(d).then((function(e){u.value=e,o(u)}),(function(e){return r("throw",e,o,s)}))}s(l.arg)}var a;this._invoke=function(e,n){function i(){return new t((function(t,a){r(e,n,t,a)}))}return a=a?a.then(i,i):i()}}function k(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,k(e,t),"throw"===t.method))return u;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return u}var r=c(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,u;var a=r.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,u):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,u)}function _(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function F(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(_,this),this.reset(!0)}function S(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:A}}function A(){return{value:void 0,done:!0}}return h.prototype=f,s(m,"constructor",f),s(f,"constructor",h),h.displayName=s(f,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,s(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},b(w.prototype),s(w.prototype,i,(function(){return this})),e.AsyncIterator=w,e.async=function(t,n,r,a,i){void 0===i&&(i=Promise);var o=new w(l(t,n,r,a),i);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},b(m),s(m,o,"Generator"),s(m,a,(function(){return this})),s(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=S,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(F),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],o=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),l=n.call(i,"finallyLoc");if(s&&l){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,u):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),u},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),F(n),u}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;F(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:S(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),u}},e}function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function m(e,t,n,r,a,i,o){try{var s=e[i](o),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,a)}function b(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var i=e.apply(t,n);function o(e){m(i,r,a,o,s,"next",e)}function s(e){m(i,r,a,o,s,"throw",e)}o(void 0)}))}}function w(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function k(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _(e,t,n){return t&&k(e.prototype,t),n&&k(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function F(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function x(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&A(e,t)}function S(e){return S=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},S(e)}function A(e,t){return A=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},A(e,t)}function E(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function O(e,t,n){return O=E()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var a=new(Function.bind.apply(e,r));return n&&A(a,n.prototype),a},O.apply(null,arguments)}function P(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function j(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return P(e)}function q(e){var t=E();return function(){var n,r=S(e);if(t){var a=S(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return j(this,n)}}function C(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=S(e)););return e}function L(){return L="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=C(e,t);if(r){var a=Object.getOwnPropertyDescriptor(r,t);return a.get?a.get.call(arguments.length<3?e:n):a.value}},L.apply(this,arguments)}function T(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,a,i=[],o=!0,s=!1;try{for(n=n.call(e);!(o=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);o=!0);}catch(e){s=!0,a=e}finally{try{o||null==n.return||n.return()}finally{if(s)throw a}}return i}(e,t)||D(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e){return function(e){if(Array.isArray(e))return N(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||D(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function D(e,t){if(e){if("string"==typeof e)return N(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?N(e,t):void 0}}function N(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var R,U,M=(R=window.console,U={log:function(e,t){if(R){"trace"===salla.config.get("debug")&&(t="trace");var n=R.log,r=void 0===t?n:this.__dict__[t]||n,a=["%cTwilight","color: #5cd5c4;font-weight:bold; border:1px solid #5cd5c4; padding: 2px 6px; border-radius: 5px;"],i={event:"#CFF680",backend:"#7b68ee"}[t];i&&(a[0]+="%c"+t[0].toUpperCase()+t.substring(1),a.push("margin-left: 5px;color: ".concat(i,";font-weight:bold; border:1px solid ").concat(i,"; padding: 2px 6px; border-radius: 5px;"))),r.call.apply(r,[R].concat(I(a.concat.apply(a,I(e)))))}},__dict__:{trace:R.trace,debug:R.debug,info:R.info,warn:R.warn,error:R.error}},{event:function(){U.log(arguments,"event")},trace:function(){U.log(arguments,"trace")},debug:function(){U.log(arguments,"debug")},info:function(){U.log(arguments,"info")},warn:function(){U.log(arguments,"warn")},error:function(){U.log(arguments,"error")},log:function(){U.log(arguments,void 0)},backend:function(){U.log(arguments,"backend")},logs:function(e){[e].flat().forEach((function(e){return e&&U.log([e].flat(),"backend")}))}}),z=function(){function e(t){w(this,e),this.parent=t,this.events={},this.namespace="";var n=/function (.{1,})\(/.exec(this.constructor.toString());this.className=(n&&n.length>1?n[1]:"").toLowerCase()}return _(e,[{key:"after_init",value:function(){this.createDynamicFunctions()}},{key:"createDynamicFunctions",value:function(){var e=this;Object.keys(this.events).forEach((function(t){e.createDynamicEventFuns(t),e.createDynamicListenerFuns(t)}))}},{key:"createDynamicEventFuns",value:function(e){if(!this[e]){var t=this;this[e]=function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return t.dispatch.apply(t,[e].concat(r))}}}},{key:"createDynamicListenerFuns",value:function(e){var t="on"+e.charAt(0).toUpperCase()+e.slice(1);if(!this[t]){var n=this;this[t]=function(t){return n.on(e,t)}}}},{key:"getEventName",value:function(e){return e=this.events[e]||e,!this.namespace||e.includes("::")?e:this.namespace+this.parent.delimiter+e}},{key:"dispatch",value:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return(t=this.parent).dispatch.apply(t,[this.getEventName(e)].concat(r))}},{key:"on",value:function(e,t){this.parent.addListener(this.getEventName(e),t)}},{key:"once",value:function(e,t){this.parent.once(this.getEventName(e),t)}},{key:"register",value:function(e,t){this.on(e,t)}},{key:"registerEventTemporary",value:function(e,t,n){n||(n=1),emitter.many(e,n,t)}}]),e}(),G=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="auth",r.events={login:"login",logout:"logout",codeSent:"code.sent",codeNotSent:"code.not-sent",verified:"verified",verificationFailed:"verification.failed",loggedIn:"logged.in",registered:"registered",registrationFailed:"registration.failed",loggedOut:"logged.out",failedLogout:"failed.logout",tokenFetched:"token.fetched",refreshFailed:"refresh.failed"},r.after_init(),r}return _(n,[{key:"login",value:function(e){return e?(e.type&&this.setTypeActionOnVerified(e.type),this.next_event=e.next_event||null,this.dispatch.apply(this,["login"].concat(Array.prototype.slice.call(arguments)))):(this.next_event=null,this.dispatch.apply(this,["login"].concat(Array.prototype.slice.call(arguments))))}},{key:"loggedIn",value:function(e){var t=this;salla.profile.info().then((function(e){salla.config.set("user",{id:e.data.id,type:"user",email:e.data.email,mobile:e.data.phone.code+e.data.phone.number,country_code:e.data.phone.country,language_code:e.data.language,currency_code:e.data.currency})})).finally((function(){return t.dispatch("loggedIn",e)}))}},{key:"setTypeActionOnVerified",value:function(e){this.type_action_on_verified=e}},{key:"getTypeActionOnVerified",value:function(){return this.type_action_on_verified||"redirect"}}]),n}(),V=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="cart",r.events={latestFetched:"latest.fetched",latestFailed:"latest.failed",updated:"updated",itemUpdated:"item.updated",itemUpdatedFailed:"item.updated.failed",itemAdded:"item.added",itemAddedFailed:"item.added.failed",itemDeleted:"item.deleted",itemDeletedFailed:"item.deleted.failed",submitted:"submitted",submitFailed:"submit.failed",imageDeleted:"image.deleted",imageNotDeleted:"image.not.deleted",detailsFetched:"details.fetched",detailsNotFetched:"details.not.fetched",successReset:"success.reset",couponAdded:"coupon.added",couponDeleted:"coupon.deleted",couponAdditionFailed:"coupon.addition.failed",couponDeletionFailed:"coupon.deletion.failed"},r.after_init(),r}return _(n,[{key:"updated",value:function(e){var t;return salla.cookie.set("fresh_summary",1),e&&"object"===y(e)?(e.offer&&salla.product.event.offerExisted(e.offer),salla.storage.set("cart.summary",{total:e.cart.total,sub_total:e.cart.sub_total,discount:e.cart.discount,real_shipping_cost:e.cart.real_shipping_cost,count:e.cart.count,shipping_cost:null!==(t=e.cart.free_shipping_bar)&&void 0!==t&&t.has_free_shipping?0:e.cart.real_shipping_cost}),this.dispatch("updated",e.cart)):(salla.logger.info("Cart summary not an object!",e),this.dispatch("updated"))}},{key:"latestFetched",value:function(e){return this.updated(e.data),this.dispatch("latestFetched",e)}},{key:"itemAdded",value:function(e,t){return this.updated(e.data),this.dispatch("itemAdded",e,t)}},{key:"itemDeleted",value:function(e,t){return this.updated(e.data),this.dispatch("itemDeleted",e,t)}},{key:"itemUpdated",value:function(e,t){return this.updated(e.data),this.dispatch("itemUpdated",e,t)}},{key:"couponAdded",value:function(e,t){return this.updated(e.data),this.dispatch("couponAdded",e,t)}},{key:"couponDeleted",value:function(e,t){return this.updated(e.data),this.dispatch("couponDeleted",e,t)}}]),n}(),$=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="order",r.events={canceled:"canceled",notCanceled:"not.canceled",orderCreated:"order.created",orderCreationFailed:"order.creation.failed",invoiceSent:"invoice.sent",invoiceNotSent:"invoice.not.sent"},r.after_init(),r}return _(n)}(),H=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="scope",r.events={fetched:"fetched",notFetched:"not.fetched",productAvailabilityFetched:"product-availability.fetched",productAvailabilityNotFetched:"product-availability.not.fetched",changeSucceeded:"changed",changeFailed:"not.changed"},r.after_init(),r}return _(n)}(),W=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="rating",r.events={orderNotFetched:"order.not.fetched",orderFetched:"order.fetched",storeRated:"store.rated",storeFailed:"store.failed",productsRated:"products.rated",productsFailed:"products.failed",shippingRated:"shipping.rated",shippingFailed:"shipping.failed"},r.after_init(),r}return _(n)}(),B=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="comment",r.events={added:"added",additionFailed:"addition.failed"},r.after_init(),r}return _(n)}(),Z=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="loyalty",r.events={exchangeSucceeded:"exchange.succeeded",exchangeFailed:"exchange.failed",programFetched:"program.fetched",programNotFetched:"program.not.fetched",resetSucceeded:"exchange-reset.succeeded",resetFailed:"exchange-reset.failed"},r.after_init(),r}return _(n)}(),Q=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="profile",r.events={updated:"updated",updateFailed:"update.failed",verificationCodeSent:"verification.code.sent",updateContactsFailed:"update.contacts.failed",verified:"verified",unverified:"unverified",infoFetched:"info.fetched",infoNotFetched:"info.not.fetched"},r.after_init(),r}return _(n)}(),J=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="product",r.events={priceUpdated:"price.updated",priceUpdateFailed:"price.updated.failed",availabilitySubscribed:"availability.subscribed",availabilitySubscribeFailed:"availability.subscribe.failed",categoriesFetched:"categories.fetched",categoriesFailed:"categories.failed",searchFailed:"search.failed",searchResults:"search.results",offerExisted:"offer.existed",fetchOffersFailed:"fetch.offers.failed",offersFetched:"offers.fetched",sizeGuideFetched:"size-guide.fetched",SizeGuideFetchFailed:"size-guide.failed",giftFetched:"gift.fetched",giftFetchFailed:"gift.failed",addGiftToCartSucceeded:"gift.add-to-cart.succeeded",addGiftToCartFailed:"gift.add-to-cart.failed",giftImageUploadSucceeded:"gift.image-upload.succeeded",giftImageUploadFailed:"gift.image-upload.failed"},r.after_init(),r}return _(n)}(),K=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="document",r.events={click:"click",change:"change",submit:"submit",keyup:"keyup",leaving:"leaving",request:"request",requestFailed:"request.failed"},r.after_init(),r}return _(n,[{key:"onClick",value:function(e,t){this.fireCallableFuns("click",e,t)}},{key:"onChange",value:function(e,t){this.fireCallableFuns("change",e,t)}},{key:"onSubmit",value:function(e,t){this.fireCallableFuns("submit",e,t)}},{key:"onKeyup",value:function(e,t){this.fireCallableFuns("keyup",e,t)}},{key:"fireCallableFuns",value:function(e,t,n){this.on(e,(function(e){"function"!=typeof t?"function"==typeof n&&e.target.matches(t)&&n(e):t(e)}))}},{key:"fireEvent",value:function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),a=2;a<n;a++)r[a-2]=arguments[a];return this.fireEventForElements.apply(this,[e,t,!1].concat(r))}},{key:"fireEventForAll",value:function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),a=2;a<n;a++)r[a-2]=arguments[a];return this.fireEventForElements.apply(this,[e,t,!0].concat(r))}},{key:"fireEventForElements",value:function(e,t,n){for(var r=this,a=arguments.length,i=new Array(a>3?a-3:0),o=3;o<a;o++)i[o-3]=arguments[o];if("string"==typeof e){if(n)return document.querySelectorAll(e).forEach((function(e){return r.fireEventForElements.apply(r,[e,t,!1].concat(i))}));e=document.querySelector(e)}if(e){var s=O(CustomEvent,[t].concat(i));return e.dispatchEvent(s)}salla.log("Failed To get element to fire event: "+t)}}]),n}(),X=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="wishlist",r.events={added:"added",removed:"removed",additionFailed:"addition.failed",removingFailed:"removing.failed"},r.after_init(),r}return _(n)}(),Y=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="currency",r.events={changed:"changed",failed:"failed",fetched:"fetched",failedToFetch:"failed.to.fetch"},r.after_init(),r}return _(n)}(),ee=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="twilight",r.events={initiated:"initiated"},r.after_init(),r}return _(n)}(),te=function(e){x(n,z);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="infiniteScroll",r.events={scrollThreshold:"scroll.threshold",request:"request",load:"load",append:"append",error:"error",last:"last",history:"history"},r.after_init(),r}return _(n)}(),ne=function(t){x(r,e);var n=q(r);function r(){var e;w(this,r);return(e=n.call(this,{wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1})).globalListners={},e.delimiter="::",e.auth=new G(P(e)),e.cart=new V(P(e)),e.order=new $(P(e)),e.scope=new H(P(e)),e.rating=new W(P(e)),e.comment=new B(P(e)),e.loyalty=new Z(P(e)),e.product=new J(P(e)),e.profile=new Q(P(e)),e.currency=new Y(P(e)),e.document=new K(P(e)),e.twilight=new ee(P(e)),e.wishlist=new X(P(e)),e.infiniteScroll=new te(P(e)),e.body=document.querySelector("body"),e.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],e.ingoreLogEvents=["document::click","document::keyup","document::change"],e.noneFireableActions=["document.request"],e.on("twilight::initiated",e.initiateSallaInAllClasses),e}return _(r,[{key:"initiateSallaInAllClasses",value:function(){var e=this;Object.keys(salla).forEach((function(t){"object"==y(t=salla[t])&&(e.callSallaInitiate(t),Object.keys(t).forEach((function(n){e.callSallaInitiate(t[n])})))}))}},{key:"callSallaInitiate",value:function(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}},{key:"createAndDispatch",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.dispatch.apply(this,[e].concat(n))}},{key:"dispatch",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var a,i,o=e.replace("::",".");if(!this.noneFireableActions.includes(o)&&"function"==typeof salla.call(o))return salla.log("'salla.".concat(o,"(...)' triggered using event '").concat(e,"'")),o=o.split("."),void(a=salla[o[0]])[o[1]].apply(a,n);(this.emit.apply(this,[e].concat(n)),window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign.apply(Object,[{event:e}].concat(I(n.values())))),this.ingoreLogEvents.includes(e)||!salla.config.get("debug")&&!this.logableEvents.includes(e))||(i=salla.logger).event.apply(i,[e].concat(n));var s=this;Object.keys(this.globalListners).forEach((function(t){var r;(r=s.globalListners)[t].apply(r,[e].concat(n))})),this.dispatchMobileEvent(e,v({},n.values()))}},{key:"dispatchEvents",value:function(e){if(e&&"object"===y(e))for(var t=0,n=Object.entries(e);t<n.length;t++){var r=T(n[t],2),a=r[0],i=r[1];this.dispatch(a,i)}else salla.log("No Events To Dispatch!",e)}},{key:"addListener",value:function(e,t){this.on(e,t)}},{key:"addEventListener",value:function(e,t){this.addListener(e,t)}},{key:"listen",value:function(e,t){this.addListener(e,t)}},{key:"registerGlobalListener",value:function(e,t){this.globalListners[e]=t}},{key:"dispatchMobileEvent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){salla.logger.warn(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){salla.logger.warn(e,"The native context does not exist yet")}}}]),r}(),re=function(){function e(t){w(this,e),this.parent=t,this.endpoints={},this.webEndpoints=[],this.namespace="BaseApi",this.endpointsMethods={},this.endpointsHeaders={};var n=/function (.{1,})\(/.exec(this.constructor.toString());this.className=(n&&n.length>1?n[1]:"").toLowerCase(),this.debounce={request:void 0,time:300,enabled:!0,exclude:[]}}return _(e,[{key:"after_init",value:function(){}},{key:"normalRequest",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=this,a=Array.isArray(e),i=a?this.getUrl.apply(this,I(e)):this.getUrl(e);e=a?e[0]:e,n=n||this.endpointsMethods[e]||"post";var o=this.endpointsHeaders[e];if("get"===n&&t instanceof FormData){var s={};Array.from(t.entries()).forEach((function(e){s[e[0]]=e[1]})),t={params:s}}o&&"get"===n&&(t=t?Object.assign(t,o):o);var l={namespace:this.namespace,action:e,url:i,payload:t,method:n,headers:o};try{salla.event.document.request(l)}catch(e){return salla.event.document.requestFailed(l),new Promise((function(){throw e}))}this.webEndpoints.includes(e)?i=salla.url.get(i):"http"!==i.substring(0,4)&&(i=salla.url.api(i));var c="undefined"!=typeof event?event.currentTarget:null,u=!1;return"SALLA-BUTTON"===(null==c?void 0:c.tagName)&&(u=!0),u&&(null==c||c.load()),this.parent[n](i,t,{headers:o}).then((function(e){return u&&(null==c||c.stop()),e.data&&e.request&&(e=e.data),r.handleAfterResponseActions(e),e})).catch((function(e){throw u&&(null==c||c.stop()),salla.event.document.requestFailed(l,e),r.handleErrorResponse(e),e}))}},{key:"request",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return!this.isFastRequestsAllowed()&&this.debounce.enabled?(this.debounce.request||(this.debounce.request=salla.helpers.debounce(this.normalRequest.bind(this),this.debounce.time)),this.debounce.request(e,t,n)):this.normalRequest(e,t,n)}},{key:"getUrl",value:function(e){for(var t=this.endpoints[e]||e,n=/{[^{}]+}/i,r=1;r<arguments.length;r++)t=t.replace(n,arguments[r]);return t}},{key:"handleAfterResponseActions",value:function(e){var t;if(e){var n=e.data,r=e.googleTags,a=void 0===r?null:r,i=n&&n.googleTags?n.googleTags:a;dataLayer&&i&&dataLayer.push(i),this.fireEventsForResponse(e),this.renderSections(e),this.showAlert(e),(null===(t=e.data)||void 0===t?void 0:t.token)&&salla.event.auth.tokenFetched(e.data.token)}}},{key:"fireEventsForResponse",value:function(e){var t,n,r=e.events||(null===(t=e.data)||void 0===t?void 0:t.events)||(null===(n=e.error)||void 0===n?void 0:n.events);"string"==typeof r&&(r=JSON.parse(r)),r&&Object.keys(r).forEach((function(e){return salla.event.dispatch(e,r[e])}))}},{key:"renderSections",value:function(e){e.sections&&Object.keys(e.sections).forEach((function(t){document.querySelectorAll(t.toSelector()).forEach((function(n){n.innerHTML=e.sections[t]}))}))}},{key:"handleErrorResponse",value:function(e){if(e.response&&e.response.data)return e.response.data.error&&e.response.data.error.fields&&!salla.config.get("sdk.notifier_handler_disabled",!1)?this.handleInvalidFields(e):this.handleAfterResponseActions(e.response.data)}},{key:"showAlert",value:function(e){var t,n;if(e&&!salla.config.get("sdk.notifier_handler_disabled",!1))return e.case&&e.msg?salla.notify.fire(e.msg,e.case,e):e.hasOwnProperty("success")&&null!==(t=e.data)&&void 0!==t&&t.message?salla.notify.fire(null===(n=e.data)||void 0===n?void 0:n.message,e.success?salla.notify.types.success:salla.notify.types.error,e):e.error&&e.error.message&&"FORBIDDEN"!==e.error.message?salla.error(e.error.message,e):void 0}},{key:"handleInvalidFields",value:function(e){var t=e.response.data.error.fields,n=[];Object.keys(t).forEach((function(e){var r=t[e];Array.isArray(r)?r.forEach((function(e){return n.push(e)})):n.push(r)}));var r=(n.length>1?"* ":"")+n.join("\n* ");salla.error(r,e)}},{key:"event",value:function(){return salla.event[this.className]}},{key:"getPossibleValue",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(e){if("object"!==y(e))return e;for(var r,a=0;a<t.length&&!(r=e[t[a]])&&!("undefined"!=typeof FormData&&e instanceof FormData&&(r=e.get(t[a])));a++);return"object"!=y(r=r||e)||n?r:void 0}}},{key:"isFastRequestsAllowed",value:function(){return salla.config.get("fastRequests")}},{key:"promise",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new Promise((function(n,r){return t?n(e):r(e)}))}},{key:"errorPromise",value:function(e){return this.promise(e,!1)}},{key:"successPromise",value:function(e){return this.promise(e,!0)}}]),e}(),ae=function(e){x(f,re);var t,n,r,a,i,o,s,l,c,u,d,h=q(f);function f(e){var t;return w(this,f),(t=h.call(this,e)).namespace="cart",t.endpoints={latest:"cart/latest",details:"cart/{cart}",quickAdd:"cart/{cart}/item/{product}/quick-add",addItem:"cart/{cart}/item/{product}/add",deleteItem:"cart/{cart}/item/{item}",updateItem:"cart/{cart}/item/{item}",deleteImage:"cart/{cart}/image/{image}",uploadImage:"cart/{cart}/image",status:"cart/{cart}/status",addCoupon:"cart/{id}/coupon",deleteCoupon:"cart/{id}/coupon"},t.endpointsMethods={latest:"get",details:"get",status:"get",updateItem:"post",deleteItem:"delete",deleteImage:"delete",deleteCoupon:"put"},t.webEndpoints=["latest"],t.after_init(),t}return _(f,[{key:"getCurrentCartId",value:(d=b(g().mark((function e(){return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.t0=salla.storage.get("cart.id"),e.t0){e.next=5;break}return e.next=4,this.latest();case 4:e.t0=e.sent.data.cart.id;case 5:return e.abrupt("return",e.t0);case 6:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"getUploadImageEndpoint",value:function(e){return salla.url.api(this.getUrl("uploadImage",e||salla.storage.get("cart.id")))}},{key:"latest",value:function(){return this.request("latest",{params:{source:""}}).then((function(e){return salla.storage.set("cart",e.data.cart),salla.event.cart.latestFetched(e),e})).catch((function(e){throw salla.storage.set("cart",""),salla.event.cart.latestFailed(e),e}))}},{key:"details",value:(u=b(g().mark((function e(){var t;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getCurrentCartId();case 2:return t=e.sent,e.abrupt("return",this.request(["details",t]).then((function(e){return salla.cart.event.detailsFetched(e),e})).catch((function(e){throw salla.cart.event.detailsNotFetched(e),e})));case 4:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"quickAdd",value:(c=b(g().mark((function e(t){return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.addItem(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"addItem",value:(l=b(g().mark((function e(t){var n,r,a,i;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((n=this.getCartPayload(t)).id){e.next=5;break}return r='There is no product "id"!',salla.cart.event.itemAddedFailed(r),e.abrupt("return",this.errorPromise(r));case 5:return a=this.getPossibleValue(n.payload,["quantity","donating_amount"])?"addItem":"quickAdd",e.next=8,this.getCurrentCartId();case 8:return i=e.sent,e.abrupt("return",this.request([a,i,n.id],n.payload).then((function(e){return salla.cart.event.itemAdded(e,n.id),e})).catch((function(e){throw salla.cart.event.itemAddedFailed(e,n.id),e})));case 10:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"deleteItem",value:(s=b(g().mark((function e(t){var n,r,a;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((n=this.getCartPayload(t)).id){e.next=5;break}return r='There is no "id"!',salla.cart.event.itemDeletedFailed(r),e.abrupt("return",this.errorPromise(r));case 5:return e.next=7,this.getCurrentCartId();case 7:return a=e.sent,e.abrupt("return",this.request(["deleteItem",a,n.id]).then((function(e){return salla.cart.event.itemDeleted(e,n.id),e})).catch((function(e){throw salla.cart.event.itemDeletedFailed(e,n.id),e})));case 9:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"updateItem",value:(o=b(g().mark((function e(t){var n,r,a,i;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((r=this.getCartPayload(t)).id){e.next=5;break}return a='There is no "id"!',salla.cart.event.itemUpdatedFailed(a),e.abrupt("return",this.errorPromise(a));case 5:return e.next=7,this.getCurrentCartId();case 7:return i=e.sent,"Object"===(null===(n=r.payload.constructor)||void 0===n?void 0:n.name)?r.payload._method="PUT":r.payload.append("_method","PUT"),e.abrupt("return",this.request(["updateItem",i,r.id],r.payload).then((function(e){return salla.cart.event.itemUpdated(e,r.id),e})).catch((function(e){throw salla.cart.event.itemUpdatedFailed(e,r.id),e})));case 10:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"deleteImage",value:(i=b(g().mark((function e(t){var n,r;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.getPossibleValue(t,["id","image_id","photo_id"])){e.next=4;break}return n='There is no "id"!',salla.cart.event.imageNotDeleted(n),e.abrupt("return",this.errorPromise(n));case 4:return e.next=6,this.getCurrentCartId();case 6:return r=e.sent,e.abrupt("return",this.request(["deleteImage",r,t]).then((function(e){return salla.cart.event.imageDeleted(e,t),e})).catch((function(e){throw salla.cart.event.imageNotDeleted(e,t),e})));case 8:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"status",value:(a=b(g().mark((function e(t){return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.t0=t,e.t0){e.next=5;break}return e.next=4,this.getCurrentCartId();case 4:e.t0=e.sent;case 5:return t=e.t0,e.abrupt("return",this.request(["status",t],{params:{has_apple_pay:!!window.ApplePaySession}}));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"submit",value:(r=b(g().mark((function e(){var t=this;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=this,e.next=3,this.getCurrentCartId();case 3:e.t1=e.sent,e.t0.status.call(e.t0,e.t1).then((function(e){var n=e.data.next_step.to;if(!["checkout","refresh","login"].includes(n)){var r="Can't find next_step );";throw salla.cart.event.submitFailed(r),r}if(salla.cart.event.submitted(e),"login"===n)return salla.auth.setCanRedirect(!1),salla.event.dispatch("login::open"),void salla.auth.event.onLoggedIn((function(e){salla.event.dispatch("login::close"),t.submit()}));"checkout"===n?window.location.href=e.data.next_step.url+(window.ApplePaySession?"?has_apple_pay=true":""):window.location.reload()})).catch((function(e){throw salla.cart.event.submitFailed(e),e}));case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getCartPayload",value:function(e){var t,n=(null===(t=e)||void 0===t?void 0:t.data)||("object"==y(e)?e:void 0);return{id:e=n?this.getPossibleValue(n,["prod_id","product_id","item_id","id"]):e,payload:n="object"==y(n)?n:void 0}}},{key:"handleAfterResponseActions",value:function(e){if(403===e.status){salla.storage.remove("cart");var t=salla.lang.get("pages.checkout.try_again");throw salla.error(t),t}L(S(f.prototype),"handleAfterResponseActions",this).call(this,e)}},{key:"reset",value:function(){salla.storage.remove("cart"),salla.cart.event.successReset()}},{key:"addCoupon",value:(n=b(g().mark((function e(t){var n,r;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=t.data||t,t=this.getPossibleValue(t,["coupon"])){e.next=6;break}return(n=new Error('There is no "Coupon Code"!')).name="EmptyCoupon",salla.event.cart.couponAdditionFailed(n),e.abrupt("return",this.errorPromise(n));case 6:return e.next=8,salla.cart.api.getCurrentCartId();case 8:return r=e.sent,e.abrupt("return",this.request(["addCoupon",r],{coupon:t}).then((function(e){return salla.event.cart.couponAdded(e,r),e})).catch((function(e){throw salla.event.cart.couponAdditionFailed(e,r),e})));case 10:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"deleteCoupon",value:(t=b(g().mark((function e(){var t;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,salla.cart.api.getCurrentCartId();case 2:return t=e.sent,e.abrupt("return",this.request(["deleteCoupon",t],{}).then((function(e){return salla.event.cart.couponDeleted(e,t),e})).catch((function(e){throw salla.event.cart.couponDeletionFailed(e,t),e})));case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),f}(),ie=function(e){x(a,re);var t,n,r=q(a);function a(e){var t;return w(this,a),(t=r.call(this,e)).namespace="loyalty",t.endpoints={getProgram:"loyalty",exchange:"loyalty/exchange",reset:"loyalty/exchange"},t.endpointsMethods={getProgram:"get",reset:"put"},t.after_init(),t}return _(a,[{key:"getProgram",value:function(){return this.request("getProgram").then((function(e){return salla.loyalty.event.programFetched(e),e})).catch((function(e){throw salla.loyalty.event.programNotFetched(e),e}))}},{key:"exchange",value:(n=b(g().mark((function e(t){var n,r,a,i=arguments;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=i.length>1&&void 0!==i[1]?i[1]:null,t=this.getPossibleValue(t,["id","loyalty_prize_id","prize_id"])){e.next=6;break}return r="Unable to find cart id. Please provide one.",salla.loyalty.event.exchangeFailed(r),e.abrupt("return",this.errorPromise(r));case 6:if(e.t0=n,e.t0){e.next=11;break}return e.next=10,salla.cart.getCurrentCartId();case 10:e.t0=e.sent;case 11:if(n=e.t0){e.next=16;break}return a="Unable to find cart id. Please provide one.",salla.loyalty.event.exchangeFailed(a),e.abrupt("return",this.errorPromise(a));case 16:return e.abrupt("return",this.request("exchange",{loyalty_prize_id:t,cart_id:n}).then((function(e){return salla.loyalty.event.exchangeSucceeded(e,t),e})).catch((function(e){throw salla.loyalty.event.exchangeFailed(e,t),e})));case 17:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"reset",value:(t=b(g().mark((function e(){var t,n,r=arguments;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.length>0&&void 0!==r[0]?r[0]:null,e.t0=t,e.t0){e.next=6;break}return e.next=5,salla.cart.getCurrentCartId();case 5:e.t0=e.sent;case 6:if(t=e.t0){e.next=11;break}return n="Unable to find cart id. Please provide one.",salla.loyalty.event.resetFailed(n),e.abrupt("return",this.errorPromise(n));case 11:return e.abrupt("return",this.request("reset",{cart_id:t}).then((function(e){return salla.loyalty.event.resetSucceeded(e),e})).catch((function(e){throw salla.loyalty.event.resetFailed(e),e})));case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),a}(),oe=function(e){x(r,re);var t,n=q(r);function r(e){var t;return w(this,r),(t=n.call(this,e)).namespace="auth",t.canRedirect_=!0,t.endpoints={login:"auth/{type}/send_verification",resend:"auth/resend_verification",verify:"auth/{type}/verify",register:"auth/register",logout:"logout",refresh:"auth/refresh"},t.webEndpoints=["logout","auth/jwt","refresh"],t.endpointsMethods={logout:"get"},t.after_init(),t}return _(r,[{key:"setCanRedirect",value:function(e){salla.api.auth.canRedirect_=e}},{key:"canRedirect",value:function(){return salla.api.auth.canRedirect_}},{key:"login",value:function(e){e.data&&(e=e.data);var t=this.getPossibleValue(e,["type"]);if(!["email","mobile"].includes(t)){var n="Login type should be in: [email, mobile]";return salla.auth.event.codeNotSent(n),this.errorPromise(n)}return this.request(["login",t],e).then((function(e){return salla.auth.event.codeSent(e,t),e})).catch((function(e){throw salla.auth.event.codeNotSent(e,t),e}))}},{key:"verify",value:(t=b(g().mark((function e(t){var n,r,a,i,o,s=arguments;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=!(s.length>1&&void 0!==s[1])||s[1],a=this.getPossibleValue(t,["type"])){e.next=6;break}return i="Failed to know what's login type!",salla.auth.event.verificationFailed(i),e.abrupt("return",this.errorPromise(i));case 6:return r=!1!==this.getPossibleValue(t,["supportWebAuth"])&&r,salla.auth.event.next_event&&(t.next_event=salla.auth.event.next_event),e.next=10,this.request(["verify",a],t);case 10:if(200===(null==(o=e.sent)?void 0:o.status)){e.next=14;break}return salla.auth.event.verificationFailed(o,a),e.abrupt("return",this.errorPromise(o));case 14:if(e.t0=r,!e.t0){e.next=18;break}return e.next=18,this.request("auth/jwt");case 18:return"authenticated"===(null===(n=o.data)||void 0===n?void 0:n.case)&&salla.auth.event.loggedIn(o),salla.auth.event.verified(o,a),e.abrupt("return",this.successPromise(o));case 21:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"resend",value:function(e){var t;return(e=e.data||e).type=e.type||"mobile","mobile"!==e.type||e.phone&&e.country_code?"email"!==e.type||e.email?this.request("resend",e).then((function(t){return salla.auth.event.codeSent(t,e),t})).catch((function(t){throw salla.auth.event.codeNotSent(t,e),t})):(salla.auth.event.codeNotSent(t="There is no email!",e),this.errorPromise(t)):(salla.auth.event.codeNotSent(t="There is no phone or country_code!",e),this.errorPromise(t))}},{key:"register",value:function(e){var t;return e.data&&(t=e.element,e=e.data),salla.auth.event.next_event&&(e.next_event=salla.auth.event.next_event),this.request("register",e).then((function(e){var n;return salla.auth.event.registered.call(t,e),"authenticated"===(null===(n=e.data)||void 0===n?void 0:n.case)&&salla.auth.event.loggedIn(e),e})).catch((function(e){throw salla.auth.event.registrationFailed.call(t,e),e}))}},{key:"logout",value:function(){return this.request("logout").then((function(e){return salla.auth.event.loggedOut(e),salla.log("Reloading after 0.1 sec..."),setTimeout((function(){return location.reload()}),100),e})).catch((function(e){throw salla.auth.event.failedLogout(e),e}))}},{key:"refresh",value:function(){return this.request("refresh").catch((function(e){throw salla.auth.event.refreshFailed(e),e}))}}]),r}(),se=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="order",r.endpoints={cancel:"orders/cancel/{id}",createCartFromOrder:"reorder/{id}",sendInvoice:"orders/send/{id}"},r.endpointsMethods={createCartFromOrder:"get"},r.after_init(),r}return _(n,[{key:"show",value:function(e){var t=this.getPossibleValue((null==e?void 0:e.data)||e,["id","order_id"]);salla.event.dispatch("mobile::order.placed",{order_id:t}),location.href=this.getPossibleValue((null==e?void 0:e.data)||e,["url"])}},{key:"cancel",value:function(e){return e=e||salla.config.get("page.id"),this.request(["cancel",e],{params:{has_apple_pay:!!window.ApplePaySession}}).then((function(t){return salla.event.order.canceled(t,e),t})).catch((function(t){throw salla.event.order.notCanceled(t,e),t}))}},{key:"createCartFromOrder",value:function(e){return e=e||salla.config.get("page.id"),this.request(["createCartFromOrder",e]).then((function(t){return salla.storage.set("cart",{id:t.data.cart_id,user_id:salla.config.get("user.id")}),salla.event.order.orderCreated(t,e),window.location.href=t.data.url,t})).catch((function(t){throw salla.event.order.orderCreationFailed(t,e),t}))}},{key:"sendInvoice",value:function(e){var t=this.getPossibleValue(e,["id"])||salla.config.get("page.id");if(!t||isNaN(t)){var n="There is no id!";return salla.order.event.invoiceNotSent(n),this.errorPromise(n)}return this.request(["sendInvoice",t],e).then((function(e){return salla.event.order.invoiceSent(e,t),e})).catch((function(e){throw salla.event.order.invoiceNotSent(e,t),e}))}}]),n}(),le=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="product",r.previousQuery="",r.endpoints={getPrice:"products/{id}/price",availabilitySubscribe:"products/{id}/availability-notify",search:"products/search",categories:"products/categories/{?id}",purchaseNow:"checkout/quick-purchase/{id}",offers:"products/{product_id}/specialoffer",getSizeGuides:"products/{prod_id}/size-guides",giftDetail:"products/{product_id}/buy-as-gift",giftToCart:"products/{product_id}/buy-as-gift",giftImage:"products/buy-as-gift/image"},r.endpointsMethods={giftDetail:"get"},r.webEndpoints=["purchaseNow"],r.after_init(),r}return _(n,[{key:"getPrice",value:function(e){var t=e.data||e,n=this.getPossibleValue(t,["id","prod_id","product_id"]);return this.request(["getPrice",n],"object"==y(t)?t:void 0).then((function(e){return salla.product.event.priceUpdated(e,n),e})).catch((function(e){throw salla.product.event.priceUpdateFailed(e,n),e}))}},{key:"categories",value:function(e){return this.request(["categories",e||""],null,"get").then((function(e){return salla.product.event.categoriesFetched(e),e})).catch((function(e){throw salla.product.event.categoriesFailed(e),e}))}},{key:"availabilitySubscribe",value:function(e){var t=e.data||e;return e=this.getPossibleValue(t,["id","prod_id"]),this.request(["availabilitySubscribe",e],"object"==y(t)?t:void 0).then((function(t){return salla.product.event.availabilitySubscribed(t,e),t})).catch((function(t){throw salla.product.event.availabilitySubscribedFailed(t,e),t}))}},{key:"search",value:function(e){var t,n=e.data;if(n||(n={params:"string"==typeof e?{query:e}:e}),!(e=n instanceof FormData?n.get("query"):n.query||(null===(t=n.params)||void 0===t?void 0:t.query))){var r='There is no "query"!';return salla.product.event.searchFailed(r),this.errorPromise(r)}if(e===salla.api.product.previousQuery){var a="Query is same as previous one!";return salla.product.event.searchFailed(a),salla.api.product.previousQuery=null,this.errorPromise(a)}return salla.api.product.previousQuery=e,this.request("search",n,"get").then((function(t){return salla.product.event.searchResults(t,e),t})).catch((function(t){throw salla.product.event.searchFailed(t,e),t}))}},{key:"offers",value:function(e){var t;if(!(e=this.getPossibleValue((null===(t=e)||void 0===t?void 0:t.data)|e,["product_id","id"]))){var n='There is no "product_id"!';return salla.offer.event.fetchDetailsFailed(n),this.errorPromise(n)}return this.request(["offers",e]).then((function(t){return salla.product.event.offersFetched(t,e),t})).catch((function(t){throw salla.product.event.fetchOffersFailed(t,e),t}))}},{key:"purchaseNow",value:function(e){var t=this;if(salla.config.isGuest())return salla.auth.event.dispatch("login");var n=e.product_data,r=this.getPossibleValue(n,["id","prod_id"]);if(!e.is_applepay)return this.request(["quickPurchase",r],"object"==y(n)?n:void 0).then((function(e){return e})).catch((function(e){throw e}));salla.event.dispatch("payments::apple-pay.start-transaction",{amount:e.total,currency:e.currency,requiredShippingContactFields:e.require_shipping?["postalAddress"]:null,shippingMethods:e.require_shipping?[]:null,supportedNetworks:e.applepay_supported_networks,validateMerchant:{url:baseUrl+"checkout/applepay/validate",onFailed:function(e){e.response,console.log("validateMerchant Failed!")},onSuccess:function(e){return console.log("validateMerchant Success"),t.request(["quickPurchase",r],"object"==y(n)?n:void 0)}},authorized:{url:baseUrl+"/checkout/{id}/payments/submit",onFailed:function(e){console.log("authorized Failed!"),window.Salla.Payments.ApplePay.onCancel({},e.data.error.message)},onSuccess:function(e){console.log(e),window.location.href=e.redirect.url,console.log("authorized Success:: redirect to thank you page, order placed")}},shippingMethodSelected:e.require_shipping?{url:baseUrl+"/checkout/{id}/shipping/details",onFailed:function(e){console.log("select shipping method failed!")},onSuccess:function(e){console.log("select shipping method success")}}:null,shippingContactSelected:e.require_shipping?{url:baseUrl+"/checkout/{id}/address/add",onFailed:function(e){console.log("created contact failed!")},onSuccess:function(e){console.log("created contact success : ",e.data.address_id)}}:null,recalculateTotal:{url:baseUrl+"/checkout/{id}/payments/recalculate"},onError:function(e){console.log(e),salla.notify.error(e)}})}},{key:"getSizeGuides",value:function(e){return this.request("products/".concat(e,"/size-guides"),null,"get").then((function(t){return salla.product.event.sizeGuideFetched(t,e),t})).catch((function(t){throw salla.product.event.sizeGuideFetchFailed(t,e),t}))}},{key:"getGiftDetails",value:function(e){return this.request(["giftDetail",e]).then((function(t){return salla.product.event.giftFetched(t,e),t})).catch((function(t){throw salla.product.event.giftFetchFailed(t,e),t}))}},{key:"addGiftToCart",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.request(["giftToCart",e],t).then((function(t){return salla.product.event.addGiftToCartSucceeded(t,e),n&&(window.location.href=t.redirect),response})).catch((function(t){throw salla.product.event.addGiftToCartFailed(t,e),t}))}},{key:"uploadGiftImage",value:function(e){return this.request("giftImage",e).then((function(e){return salla.product.event.giftImageUploadSucceeded(e),e})).catch((function(e){throw salla.product.event.giftImageUploadFailed(e),e}))}}]),n}(),ce=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="profile",r.endpoints={info:"auth/user",update:"profile/update",updateContacts:"profile/contacts/update",verify:"profile/verify"},r.after_init(),r}return _(n,[{key:"info",value:function(){return this.request("info",null,"get").then((function(e){return salla.profile.event.infoFetched(e),e})).catch((function(e){throw salla.profile.event.infoNotFetched(e),e}))}},{key:"update",value:function(e){return this.request("update",e).then((function(e){return salla.profile.event.updated(e),e})).catch((function(e){throw salla.event.profile.updateFailed(e),e}))}},{key:"updateContacts",value:function(e){return this.request("updateContacts",e).then((function(e){return salla.profile.event.verificationCodeSent(e),e})).catch((function(e){throw salla.event.profile.updateContactsFailed(e),e}))}},{key:"verify",value:function(e){return this.request("verify",e).then((function(e){return salla.profile.event.verified(e),e})).catch((function(e){throw salla.event.profile.unVerified(e),e}))}}]),n}(),ue=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="comment",r.endpoints={add:"{type}/{id}/comments"},r.after_init(),r}return _(n,[{key:"add",value:function(e){var t;null!==(t=e)&&void 0!==t&&t.data&&(e=e.data);var n,r=Object.fromEntries(e),a=r.id,i=r.type,o=r.comment;return a?i&&["products","pages","product","page"].includes(i)?o?(i+=["product","page"].includes(i)?"s":"",this.request(["add",i,a],{comment:o}).then((function(e){return salla.event.comment.added(e,a),e})).catch((function(e){throw salla.event.comment.additionFailed(e,a),e}))):(salla.event.comment.additionFailed(n="can't find comment content!"),this.errorPromise(n)):(salla.event.comment.additionFailed(n="Failed to get type one of:(products, product, page, pages)!"),this.errorPromise(n)):(salla.event.comment.additionFailed(n="Failed to get id!"),this.errorPromise(n))}}]),n}(),de=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="currency",r.endpoints={change:"/",list:"currencies"},r.endpointsMethods={change:"get",list:"get"},r.webEndpoints=["change"],r.after_init(),r}return _(n,[{key:"change",value:function(e){if(!(e=this.getPossibleValue(e.data||e,["currency","code"]))){var t="Can't find currency code!";return salla.currency.event.failed(t),this.errorPromise(t)}return this.request("change",{params:{change_currency:"",currency:e}}).then((function(t){return salla.cookie.set("fresh_summary",1),salla.storage.set("cart",""),salla.currency.event.changed(t,e),t})).catch((function(t){throw salla.currency.event.failed(t,e),t}))}},{key:"list",value:function(){return this.request("list").then((function(e){return salla.currency.event.fetched(e),e})).catch((function(e){throw salla.currency.event.failedToFetch(e),e}))}}]),n}(),he=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="document",r}return _(n)}(),fe=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="rating",r.endpoints={store:"rating/store",products:"rating/products",shipping:"rating/shipping",order:"rating/{order_id}"},r.endpointsMethods={order:"get"},r.after_init(),r}return _(n,[{key:"order",value:function(e){var t="object"===y(e)?e:{},n=this.getPossibleValue((null==e?void 0:e.data)||e,["order_id","id"]);if(!n){var r='There is no "order_id"!';return salla.event.rating.orderNotFetched(r),this.errorPromise(r)}return this.request(["order",n],t).then((function(e){return salla.event.rating.orderFetched(e,n),e})).catch((function(e){throw salla.event.rating.orderNotFetched(e,n),e}))}},{key:"store",value:function(e){if(!(e=e.data||e)){var t='There is no "data"!';return salla.event.rating.storeFailed(t),this.errorPromise(t)}return this.request("store",e).then((function(t){return salla.event.rating.storeRated(t,e),t})).catch((function(t){throw salla.event.rating.storeFailed(t,e),t}))}},{key:"products",value:function(e){if(!(e=e.data||e)){var t='There is no "data"!';return salla.event.rating.productsFailed(t),this.errorPromise(t)}return this.request("products",e).then((function(t){return salla.event.rating.productsRated(t,e),t})).catch((function(t){throw salla.event.rating.productsFailed(t,e),t}))}},{key:"shipping",value:function(e){if(!(e=e.data||e)){var t='There is no "data"!';return salla.event.rating.shippingFailed(t),this.errorPromise(t)}return this.request("shipping",e).then((function(t){return salla.event.rating.shippingRated(t,e),t})).catch((function(t){throw salla.event.rating.shippingFailed(t,e),t}))}}]),n}(),pe=function(){function e(t){var n;if(w(this,e),salla.config.merge(t),t){var r;if(t._token&&(salla.api.defaults.headers.common["X-CSRF-TOKEN"]=t._token),this.injectMaintenanceAlert(),this.injectThemePreviewAlert(),this.injectEditAlert(),null!=t&&null!==(n=t.user)&&void 0!==n&&n.language_code)salla.lang.setLocale(null==t||null===(r=t.user)||void 0===r?void 0:r.language_code);salla.lang.loadStoreTranslations(),salla.twilight.event.initiated(t)}else salla.twilight.event.initiated(t)}return _(e,[{key:"injectMaintenanceAlert",value:function(){salla.config.get("maintenance")&&(document.querySelector(".store-notify")?salla.logger.warn(".store-notify element Existed before!"):salla.lang.onLoaded((function(){var e=document.createElement("div");e.classList.add("store-notify"),e.style="background-color: #d63031; color: #fff; padding: 10px 15px; text-align: center; font-size: 17px;",e.innerHTML='<p style="margin:0 !important;">'.concat(salla.lang.get("blocks.header.maintenance_alert"),"</p>"),document.body.prepend(e)})))}},{key:"injectThemePreviewAlert",value:function(){"preview"===salla.config.get("theme.mode")&&(document.querySelector("#s-theme_preview_bar")?salla.logger.warn("#s-theme_preview_bar element Existed before!"):salla.lang.onLoaded((function(){var e=document.createElement("div");e.id="s-theme_preview_bar",e.setAttribute("style","display: flex; justify-content: space-between; text-align: center; background-color: #232323; color: #fff; padding: 10px; font-size: 0.875rem; line-height: 1.25rem; position: relative;"),e.innerHTML='\n <div style="display:flex; align-items:center;">\n <img width="32" src="https://assets.salla.sa/cp/assets/images/logo-new.png">\n <span style="margin:0 10px;">'.concat(salla.lang.get("blocks.header.preview_mode"),': <span style="background:rgba(255,255,255,0.25);border-radius:15px; padding:2px 15px 4px">').concat(salla.config.get("theme.name"),'</span></span>\n </div>\n <a href="').concat(salla.url.get("preview_theme/cancel/preview"),'" style="line-height:32px; width:32px;"><i class="sicon-cancel"></i></a>\n '),document.body.prepend(e)})))}},{key:"injectEditAlert",value:function(){var e=salla.config.get("edit");e&&(document.querySelector("#s-edit-alert")?salla.logger.warn("#s-edit-alert element Existed before!"):salla.lang.onLoaded((function(){var t=document.createElement("div");t.id="s-edit-alert",t.innerHTML='\n <a href="'.concat(e,'" style="display:block; background-color:').concat(salla.config.get("theme.color.primary","#5cd5c4"),"; color:").concat(salla.config.get("theme.color.reverse","#fff"),'; padding: 10px; text-align:center; font-size: 0.875rem; line-height: 1.25rem;">\n <i class="sicon-edit"></i> \n ').concat(salla.lang.get("pages.products.quick_edit"),"\n </a>\n "),document.body.prepend(t)})))}},{key:"handleElementAjaxRequest",value:function(e,t){var n=this;if(!(t instanceof HTMLFormElement||t instanceof HTMLAnchorElement))return salla.logger.warn("trying to call ajax from non Element!!"),!1;e.preventDefault();var r=t.getAjaxFormData(e),a=r.method?r.method.toLowerCase():void 0;salla.api.document.request(r.url,r.formData,a).then((function(e){return e.data&&e.request&&(e=e.data),salla.api.document.handleAfterResponseActions(e),n.callAjaxEvent(r.events.success,e,r.formData),e})).catch((function(e){throw salla.api.document.handleErrorResponse(e),n.callAjaxEvent(r.events.fail,e,r.formData),e}))}},{key:"callAjaxEvent",value:function(e,t,n){if(e){if(n instanceof FormData){var r={};Array.from(n.entries()).forEach((function(e){r[e[0]]=e[1]})),n=r}window[e]?window[e](t,n):salla.event.dispatch(e,t,n)}}}]),e}(),ve=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="twilight",r.after_init(),r}return _(n,[{key:"init",value:function(e){var t=null==e?void 0:e.events;return salla.isInitiated||(delete e.events,new pe(e),salla.isInitiated=!0),t&&salla.event.dispatchEvents(t),this.successPromise(e)}},{key:"api",value:function(e){var t=null==e?void 0:e.events;return t&&salla.event.dispatchEvents(t),this.successPromise(e)}}]),n}(),ge=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="wishlist",r.endpoints={add:"products/favorites/{id}",remove:"products/favorites/{id}"},r.endpointsMethods={remove:"delete"},r.after_init(),r}return _(n,[{key:"toggle",value:function(e){return salla.storage.get("salla::wishlist",[]).includes(e)?this.remove(e):this.add(e)}},{key:"add",value:function(e){var t,n,r=this;return salla.config.isGuest()?(salla.wishlist.event.additionFailed(n=salla.lang.get("common.messages.must_login")),salla.error(n),this.errorPromise(n)):(e=this.getPossibleValue((null===(t=e)||void 0===t?void 0:t.data)||e,["product_id","id"]))?this.request(["add",e]).then((function(t){return r.updateWishlistStorage(e),salla.wishlist.event.added(t,e),t})).catch((function(t){throw salla.wishlist.event.additionFailed(t,e),t})):(salla.wishlist.event.additionFailed(n="Failed to get product id!"),this.errorPromise(n))}},{key:"remove",value:function(e){var t,n,r=this;return salla.config.isGuest()?(salla.wishlist.event.additionFailed(n=salla.lang.get("common.messages.must_login")),salla.error(n),this.errorPromise(n)):(e=this.getPossibleValue((null===(t=e)||void 0===t?void 0:t.data)||e,["product_id","id"]))?this.request(["remove",e]).then((function(t){return r.updateWishlistStorage(e,!1),salla.wishlist.event.removed(t,e),t})).catch((function(t){throw salla.wishlist.event.removingFailed(t,e),t})):(salla.wishlist.event.removingFailed(n="Failed to get id!"),this.errorPromise(n))}},{key:"updateWishlistStorage",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=salla.storage.get("salla::wishlist",[]);t?n.push(e):n.splice(n.indexOf(e),1),salla.storage.set("salla::wishlist",n)}}]),n}(),ye=function(e){x(n,re);var t=q(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="scopes",r.endpoints={get:"scopes",change:"scopes",getProductAvailability:"scopes/availability?product_id={id}"},r.after_init(),r}return _(n,[{key:"get",value:function(){return this.request("scopes",null,"get").then((function(e){return salla.scope.event.fetched(e),e})).catch((function(e){throw salla.scope.event.notFetched(e),e}))}},{key:"change",value:function(e){return this.request("scopes",e).then((function(e){return salla.scope.event.changeSucceeded(e),e})).catch((function(e){throw salla.scope.event.changeFailed(e),e}))}},{key:"getProductAvailability",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.request("scopes/availability?product_id=".concat(e),null,"get").then((function(t){return salla.scope.event.productAvailabilityFetched(t,e),t})).catch((function(e){throw salla.scope.event.productAvailabilityNotFetched(e),resp}))}}]),n}(),me=function(){function e(n){var r=this;return w(this,e),n.on("twilight::initiated",(function(){return r.initiateRequest()})),n.on("profile::info.fetched",this.setCurrencyAndLanguage),n.on("auth::token.fetched",(function(e){return r.handleToken(e)})),n.on("document::request.failed",(function(e,t){salla.logger.warn(t,e)})),t.create({headers:{common:{"X-Requested-With":"XMLHttpRequest","S-SOURCE":"twilight","S-APP-VERSION":"v2.0.0","S-APP-OS":"browser"}}})}return _(e,[{key:"initiateRequest",value:function(){salla.api.defaults.baseURL=salla.config.get("store.api",salla.config.get("store.url")),salla.api.defaults.headers.common["Store-Identifier"]=salla.config.get("store.id"),salla.api.defaults.headers.common.currency=salla.config.get("user.currency_code","SAR"),salla.infiniteScroll.fetchOptions.headers["Accept-Language"]=salla.api.defaults.headers.common["accept-language"]=salla.lang.getLocale(),salla.api.defaults.headers.common["s-user-id"]=salla.config.get("user.id");var e=salla.storage.get("scope");e&&(salla.api.defaults.headers.common["s-scope-type"]=e.type,salla.api.defaults.headers.common["s-scope-id"]=e.id),this.injectTokenToTheRequests()}},{key:"injectTokenToTheRequests",value:function(){var e=salla.storage.get("token"),t=salla.config.isGuest(),r=salla.storage.get("cart");if(r&&(r.user_id!==salla.config.get("user.id")||r.store_id!==salla.config.get("store.id")))return salla.log("Auth:: The cart is not belong to current "+(r.user_id!==salla.config.get("user.id")?"user":"store")+"!"),void salla.cart.api.reset();if(!t||e){if(t&&e)return salla.log("Auth:: Token without user!"),salla.storage.remove("token"),void salla.cart.api.reset();if(!e)return salla.cart.api.reset(),void salla.auth.api.refresh();var a=n(e);return Date.now()/1e3>a.exp?(salla.log("Auth:: An expired token!"),salla.storage.remove("token"),salla.cart.api.reset(),void salla.auth.api.refresh()):a.sub!==salla.config.get("user.id")?(salla.log("Auth:: The user id is not match the token details!"),salla.storage.remove("token"),salla.cart.api.reset(),void salla.auth.api.refresh()):void this.setToken(e)}}},{key:"handleToken",value:function(e){salla.storage.set("token",e),this.setToken(e),salla.cart.api.reset()}},{key:"setToken",value:function(e){salla.api.defaults.headers.common.Authorization="Bearer "+e}},{key:"setCurrencyAndLanguage",value:function(e){salla.api.defaults.headers.common.currency=e.data.currency,salla.api.defaults.headers.common["accept-language"]=e.data.language,salla.infiniteScroll.fetchOptions.headers["Accept-Language"]=e.data.language}}]),e}(),be=function(e){x(n,me);var t=q(n);function n(e){var r,a;return w(this,n),(r=t.call(this,e)).apis={auth:new oe(P(r)),cart:new ae(P(r)),loyalty:new ie(P(r)),order:new se(P(r)),rating:new fe(P(r)),product:new le(P(r)),profile:new ce(P(r)),comment:new ue(P(r)),currency:new de(P(r)),document:new he(P(r)),twilight:new ve(P(r)),wishlist:new ge(P(r)),scope:new ye(P(r)),withoutNotifier:(a=b(g().mark((function e(t){return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return salla.config.set("sdk.notifier_handler_disabled",!0),e.next=3,t().finally((function(){salla.config.set("sdk.notifier_handler_disabled",!1)}));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)}))),function(e){return a.apply(this,arguments)})},Object.assign(P(r),r.apis),r.getHeaders=function(){return r.defaults.headers.common},r}return _(n)}(),we=_((function e(t,n){return w(this,e),this.api=t,this.event=n,new Proxy(this,{get:function(e,r){return"event"===r?n:"api"===r&&"twilight"!==(null==t?void 0:t.namespace)?t:t&&t[r]||e[r]}})})),ke=function(e){x(n,we);var t=q(n);function n(e,r){var a;return w(this,n),(a=t.call(this,e,r)).options={path:".infinite-scroll-btn",history:"push",status:".infinite-scroll-status",append:".list-block"},a.fetchOptions={headers:{"S-INFINITE-SCROLL":!0}},a.instances=[],a}return _(n,[{key:"initiate",value:function(e,t,n){n=this.getCustomOptions(t,n);var a="string"!=typeof e?e:document.querySelector(e),i=n.path;if(a&&i&&("string"!=typeof i||document.querySelector(i))){var o=new r(a,n);return o.on("scrollThreshold",salla.infiniteScroll.event.scrollThreshold),o.on("request",salla.infiniteScroll.event.request),o.on("load",salla.infiniteScroll.event.load),o.on("append",salla.infiniteScroll.event.append),o.on("error",salla.infiniteScroll.event.error),o.on("last",salla.infiniteScroll.event.last),o.on("history",salla.infiniteScroll.event.history),this.instances.push(o),o}salla.logger.warn(a?"Path Option (a link that has next page link) Not Existed!":"Container For InfiniteScroll not Existed!")}},{key:"getCustomOptions",value:function(e,t){return(t="object"==y(e)&&e||t||this.options).fetchOptions=this.fetchOptions,t.path=t.path||this.options.path,t.button=t.button||t.path,t.status=t.status||this.options.status,t.hasOwnProperty("history")||(t.history=this.options.history),t.nextPage=t.nextPage||t.next_page,t.append="string"==typeof e&&e||t.append||this.options.append,t}}]),n}();function _e(e,t,n){return e instanceof FormData?e.append(t,n):e[t]=n,e}function Fe(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e+="";for(var n,r=["٠","١","٢","٣","٤","٥","٦","٧","٨","٩"],a=["0","1","2","3","4","5","6","7","8","9"],i=(t=t||!salla.config.get("store.settings.arabic_numbers_enabled"))?r:a,o=t?a:r,s=0;s<i.length;s++)n=new RegExp(i[s],"g"),e=e.replace(n,o[s]);return e}function xe(e){var t=(e.match(/\./g)||[]).length;return t&&1!==t?xe(e.replace(/\.(.+)\./g,".$1")):e}String.prototype.toStudlyCase=function(){return this.trim().replace(/([^a-zA-Z\d].)/g,(function(e){return e.toUpperCase().replace(/[^a-zA-Z\d]/g,"")}))},String.prototype.toDatasetName=function(){return this.startsWith("data-")?this.substr(5).toStudlyCase():this.toStudlyCase()},String.prototype.toSelector=function(){return this.trim().startsWith(".")||this.trim().startsWith("#")?this:"#"+this},String.prototype.replaceArray=function(e,t){for(var n,r=this,a=0;a<e.length;a++)n=new RegExp(e[a],"g"),r=r.replace(n,t[a]);return r},String.prototype.rtrim=function(e){return void 0===e&&(e="\\s"),this.replace(new RegExp("["+e+"]*$"),"")},String.prototype.ltrim=function(e){return void 0===e&&(e="\\s"),this.replace(new RegExp("^["+e+"]*"),"")},String.prototype.digitsOnly=function(){return salla.helpers.digitsOnly(this)},Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){for(var t=this;t;){if(t.matches(e))return t;t=t.parentElement}}),Element.prototype.getElementSallaData=function(e){if(this.getAttribute){if(this.hasAttribute("data-json"))try{return JSON.parse(this.getAttribute("data-json"))}catch(e){}var t=this.getAttribute("data-function");if(t&&window[t]){if("function"==typeof window[t]){for(var n,r=arguments.length,a=new Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];return this.getFilteredData((n=window[t]).call.apply(n,[this].concat(a)))}return this.getFilteredData(window[t])}var o=this.hasAttribute("data-form-selector")?document.querySelector(this.dataset.formSelector):void 0;if((o="FORM"===this.tagName?this:o||this.closest("form")||this.closest("[salla-form-data]")||this)&&"FORM"===o.tagName)return this.getFilteredData(new FormData(o),null,o);var s=o.querySelectorAll("[name]");if(!s.length)return this.getFilteredData();var l=Object.assign({},this.dataset);return s.forEach((function(e){if(!["checkbox","radio"].includes(e.type)||e.checked)try{var t=salla.helpers.inputData(e.name,e.value,l);l[t.name]=t.value}catch(t){salla.log(e.name+" can't be send")}})),this.getFilteredData(l)}},Element.prototype.canEventFireHook=function(e){return!!this.hasAttribute&&this.hasAttribute(salla.api.hooksPrefix+e.type)},Element.prototype.hasAttributeStartsWith=function(e,t){e=e.toLowerCase();for(var n=0;n<this.attributes.length;n++){var r=this.attributes[n].name.toLowerCase();if(0===r.indexOf(e))return!t||r}return!1},HTMLFormElement.prototype.getAjaxFormData=function(e){var t=this.querySelectorAll('input[type="file"]');t.forEach((function(e){e.files.length||e.setAttribute("disabled","")}));var n=new FormData(this);return t.forEach((function(e){e.files.length||e.removeAttribute("disabled")})),{formData:this.getFilteredData(n,e),url:this.getAttribute("action"),method:this.getAttribute("method")||"post",events:{success:this.dataset.onSuccess,fail:this.dataset.onFail}}},Element.prototype.getFilteredData=function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return t=t||(null==r?void 0:r.dataset)||this.dataset,r&&this.name&&void 0!==this.value&&(t=_e(t,this.name,this.value)),["filterBeforeSubmit","filterBeforeSend"].forEach((function(a){var i=(null==r?void 0:r.dataset[a])||e.dataset[a];if(i){var o=window[i];if("function"==typeof o){if(!o(t,r||e,n)&&t)throw"Data failed to be pass verify function window.".concat(i,"(formData, element, event)!");return o(t,r||e,n)}salla.log("window."+i+"() not found!")}})),t},HTMLAnchorElement.prototype.getAjaxFormData=function(e){return{formData:this.getFilteredData(null,e),url:this.getAttribute("href"),method:this.dataset.type||"get",events:{success:this.dataset.onSuccess,fail:this.dataset.onFail}}};var Se="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},Ae=Array.isArray,Ee="object"==y(Se)&&Se&&Se.Object===Object&&Se,Oe="object"==("undefined"==typeof self?"undefined":y(self))&&self&&self.Object===Object&&self,Pe=Ee||Oe||Function("return this")(),je=Pe.Symbol,qe=je,Ce=Object.prototype,Le=Ce.hasOwnProperty,Te=Ce.toString,Ie=qe?qe.toStringTag:void 0;var De=function(e){var t=Le.call(e,Ie),n=e[Ie];try{e[Ie]=void 0;var r=!0}catch(e){}var a=Te.call(e);return r&&(t?e[Ie]=n:delete e[Ie]),a},Ne=Object.prototype.toString;var Re=De,Ue=function(e){return Ne.call(e)},Me=je?je.toStringTag:void 0;var ze=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Me&&Me in Object(e)?Re(e):Ue(e)};var Ge=ze,Ve=function(e){return null!=e&&"object"==y(e)};var $e=function(e){return"symbol"==y(e)||Ve(e)&&"[object Symbol]"==Ge(e)},He=Ae,We=$e,Be=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ze=/^\w*$/;var Qe=function(e,t){if(He(e))return!1;var n=y(e);return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!We(e))||(Ze.test(e)||!Be.test(e)||null!=t&&e in Object(t))};var Je=function(e){var t=y(e);return null!=e&&("object"==t||"function"==t)},Ke=ze,Xe=Je;var Ye,et=function(e){if(!Xe(e))return!1;var t=Ke(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t},tt=Pe["__core-js_shared__"],nt=(Ye=/[^.]+$/.exec(tt&&tt.keys&&tt.keys.IE_PROTO||""))?"Symbol(src)_1."+Ye:"";var rt=function(e){return!!nt&&nt in e},at=Function.prototype.toString;var it=et,ot=rt,st=Je,lt=function(e){if(null!=e){try{return at.call(e)}catch(e){}try{return e+""}catch(e){}}return""},ct=/^\[object .+?Constructor\]$/,ut=Function.prototype,dt=Object.prototype,ht=ut.toString,ft=dt.hasOwnProperty,pt=RegExp("^"+ht.call(ft).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var vt=function(e){return!(!st(e)||ot(e))&&(it(e)?pt:ct).test(lt(e))},gt=function(e,t){return null==e?void 0:e[t]};var yt=function(e,t){var n=gt(e,t);return vt(n)?n:void 0},mt=yt(Object,"create"),bt=mt;var wt=function(){this.__data__=bt?bt(null):{},this.size=0};var kt=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},_t=mt,Ft=Object.prototype.hasOwnProperty;var xt=function(e){var t=this.__data__;if(_t){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return Ft.call(t,e)?t[e]:void 0},St=mt,At=Object.prototype.hasOwnProperty;var Et=mt;var Ot=wt,Pt=kt,jt=xt,qt=function(e){var t=this.__data__;return St?void 0!==t[e]:At.call(t,e)},Ct=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Et&&void 0===t?"__lodash_hash_undefined__":t,this};function Lt(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Lt.prototype.clear=Ot,Lt.prototype.delete=Pt,Lt.prototype.get=jt,Lt.prototype.has=qt,Lt.prototype.set=Ct;var Tt=Lt;var It=function(){this.__data__=[],this.size=0};var Dt=function(e,t){return e===t||e!=e&&t!=t};var Nt=function(e,t){for(var n=e.length;n--;)if(Dt(e[n][0],t))return n;return-1},Rt=Nt,Ut=Array.prototype.splice;var Mt=Nt;var zt=Nt;var Gt=Nt;var Vt=It,$t=function(e){var t=this.__data__,n=Rt(t,e);return!(n<0)&&(n==t.length-1?t.pop():Ut.call(t,n,1),--this.size,!0)},Ht=function(e){var t=this.__data__,n=Mt(t,e);return n<0?void 0:t[n][1]},Wt=function(e){return zt(this.__data__,e)>-1},Bt=function(e,t){var n=this.__data__,r=Gt(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};function Zt(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Zt.prototype.clear=Vt,Zt.prototype.delete=$t,Zt.prototype.get=Ht,Zt.prototype.has=Wt,Zt.prototype.set=Bt;var Qt=Zt,Jt=yt(Pe,"Map"),Kt=Tt,Xt=Qt,Yt=Jt;var en=function(e){var t=y(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};var tn=function(e,t){var n=e.__data__;return en(t)?n["string"==typeof t?"string":"hash"]:n.map},nn=tn;var rn=tn;var an=tn;var on=tn;var sn=function(){this.size=0,this.__data__={hash:new Kt,map:new(Yt||Xt),string:new Kt}},ln=function(e){var t=nn(this,e).delete(e);return this.size-=t?1:0,t},cn=function(e){return rn(this,e).get(e)},un=function(e){return an(this,e).has(e)},dn=function(e,t){var n=on(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this};function hn(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}hn.prototype.clear=sn,hn.prototype.delete=ln,hn.prototype.get=cn,hn.prototype.has=un,hn.prototype.set=dn;var fn=hn;function pn(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function n(){var r=arguments,a=t?t.apply(this,r):r[0],i=n.cache;if(i.has(a))return i.get(a);var o=e.apply(this,r);return n.cache=i.set(a,o)||i,o};return n.cache=new(pn.Cache||fn),n}pn.Cache=fn;var vn=pn;var gn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,yn=/\\(\\)?/g,mn=function(e){var t=vn(e,(function(e){return 500===n.size&&n.clear(),e})),n=t.cache;return t}((function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(gn,(function(e,n,r,a){t.push(r?a.replace(yn,"$1"):n||e)})),t})),bn=mn;var wn=function(e,t){for(var n=-1,r=null==e?0:e.length,a=Array(r);++n<r;)a[n]=t(e[n],n,e);return a},kn=Ae,_n=$e,Fn=je?je.prototype:void 0,xn=Fn?Fn.toString:void 0;var Sn=function e(t){if("string"==typeof t)return t;if(kn(t))return wn(t,e)+"";if(_n(t))return xn?xn.call(t):"";var n=t+"";return"0"==n&&1/t==-Infinity?"-0":n},An=Sn;var En=Ae,On=Qe,Pn=bn,jn=function(e){return null==e?"":An(e)};var qn=$e;var Cn=function(e,t){return En(e)?e:On(e,t)?[e]:Pn(jn(e))},Ln=function(e){if("string"==typeof e||qn(e))return e;var t=e+"";return"0"==t&&1/e==-Infinity?"-0":t};var Tn=function(e,t){for(var n=0,r=(t=Cn(t,e)).length;null!=e&&n<r;)e=e[Ln(t[n++])];return n&&n==r?e:void 0};var In=function(e,t,n){var r=null==e?void 0:Tn(e,t);return void 0===r?n:r};function Dn(e,t,n){var r=e[0];return n&&0==e.length?Array.isArray(n)?(n.push(t),n):[n,t]:Array.isArray(n)?(n.push(t),n):"string"==typeof n?[n,t]:n?(n[r]=Dn(e.slice(1),t,n[r]),n):r?F({},r,Dn(e.slice(1),t)):""===r?[t]:t}function Nn(e){return salla.config.get("store.url",window.location.href.split("/").slice(0,-1).join("/")).rtrim("/")+"/"+e.ltrim("/")}window.onbeforeunload=function(e){if(salla.document.event.leaving(e),!salla.config.get("canLeave"))return e.preventDefault(),!1};var Rn={digitsOnly:function(e){return Fe(e,!0).replace(/[^0-9.]/g,"").replace("..",".").rtrim(".")},inputDigitsOnly:function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if("string"==typeof t)return document.querySelectorAll(t).forEach((function(t){return e(t,n)}));if(t){var r=salla.helpers.digitsOnly(t.value);return t.min&&r<t.min?t.value=t.min:t.max&&r>t.max?t.value=t.max:t.maxLength>=1&&r.toString().length>t.maxLength?t.value=r.toString().substring(0,t.maxLength):t.value=n||t.dataset.hasOwnProperty("digitsWithDecimal")?xe(r):r.replace(/\D/g,"")}salla.logger.warn("Can't find Object With Id: "+t)},number:Fe,money:function(e){return Fe((null==e?void 0:e.amount)|e)+" "+salla.config.currency(null==e?void 0:e.currency).symbol},setNested:function(e,t,n){for(var r=e,a=t.split("."),i=a.length,o=0;o<i-1;o++){var s=a[o];r[s]||(r[s]={}),r=r[s]}return r[a[i-1]]=n,e},getNested:function(e,t,n){var r=In(e,t);return void 0!==r?r:n},inputData:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e.includes("[")){var r=e.split("]").join("").split("[");return{name:r[0],value:Dn(r.slice(1),t,n[r[0]])}}return{name:e,value:t}},url:{get:Nn,asset:function(e){return function(e){return window.location.origin+"/"+e.ltrim("/")}("themes/"+salla.config.get("theme.name")+"/"+e.ltrim("/"))},cdn:function(e){return"https://cdn.salla.network/"+e.ltrim("/")},is_page:function(e){return e&&salla.config.get("page.slug")===e},api:function(e){return salla.config.get("store.api",Nn("")).rtrim("/")+"/"+e.ltrim("/")}},addParamToUrl:function(e,t){if(!t||!e)return window.location.href;var n=new RegExp("([?&])"+e+"=[^&]+[&]?","g"),r=window.location.href.replace(n,"$1").replace(/&$|\?$/,"");return(r+=(r.includes("?")?"&":"?")+e+"="+encodeURIComponent(t)).replace(/&$|\?$/,"")},debounce:function(e,t){t=t||100;var n,r=[];return function(){for(var a=arguments.length,i=new Array(a),o=0;o<a;o++)i[o]=arguments[o];return clearTimeout(n),n=setTimeout((function(){var t=e.apply(void 0,i);r.forEach((function(e){return e(t)})),r=[]}),t),new Promise((function(e){return r.push(e)}))}}},Un=function(){function e(){w(this,e)}return _(e,[{key:"toggleClassIf",value:function(e,t,n,r){var a=this;return document.querySelectorAll(e).forEach((function(e){return a.toggleElementClassIf(e,t,n,r)})),this}},{key:"toggleElementClassIf",value:function(e,t,n,r){var a,i;t=Array.isArray(t)?t:t.split(" "),n=Array.isArray(n)?n:n.split(" ");var o=r(e);return null==e||(a=e.classList).remove.apply(a,I(o?n:t)),null==e||(i=e.classList).add.apply(i,I(o?t:n)),this}},{key:"isValidEmail",value:function(e){return/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(e).toLowerCase())}},{key:"element",value:function(e){return"object"==y(e)?e:document.querySelector(e)}},{key:"watchElement",value:function(e,t){return this[e]=this.element(t),this}},{key:"watchElements",value:function(e){var t=this;return Object.entries(e).forEach((function(e){return t.watchElement(e[0],e[1])})),this}},{key:"on",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return"object"==y(t)?(this.element(t).addEventListener(e,n,r),this):(document.querySelectorAll(t).forEach((function(t){return t.addEventListener(e,n,r)})),this)}},{key:"onClick",value:function(e,t){return this.on("click",e,t)}},{key:"onKeyUp",value:function(e,t){return this.on("keyup",e,t)}},{key:"onEnter",value:function(e,t){return this.onKeyUp(e,(function(e){return 13===e.keyCode&&t(e)})),this}},{key:"all",value:function(e,t){return document.querySelectorAll(e).forEach(t),this}},{key:"hideElement",value:function(e){return this.element(e).style.display="none",this}},{key:"showElement",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"block";return this.element(e).style.display=t,this}},{key:"removeClass",value:function(e,t){var n;return(n=this.element(e).classList).remove.apply(n,I(Array.from(arguments).slice(1))),this}},{key:"addClass",value:function(e,t){var n;return(n=this.element(e).classList).add.apply(n,I(Array.from(arguments).slice(1))),this}},{key:"debounce",value:function(e){this.debounce_||(this.debounce_=salla.helpers.debounce((function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return e.apply(void 0,n)}),500));for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return this.debounce_.apply(this,[e].concat(n))}}]),e}(),Mn=function(){function e(){w(this,e)}var t;return _(e,[{key:"submit",value:(t=b(g().mark((function e(t){var n,r,a,i,o,s,l,c,u=arguments;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=u.length>1&&void 0!==u[1]?u[1]:null,a=r,"SubmitEvent"!==(null==r||null===(n=r.constructor)||void 0===n?void 0:n.name)){e.next=10;break}if(r.preventDefault(),"FORM"===(null===(i=r.target)||void 0===i?void 0:i.tagName)){e.next=7;break}return salla.logger.warn("Failed find the target element for submit action. make sure you submit a form element"),e.abrupt("return",new Promise((function(){throw"Failed find the target element for submit action. make sure you submit a form element"})));case 7:"SALLA-BUTTON"===(null==r||null===(o=r.submitter)||void 0===o||null===(s=o.parentElement)||void 0===s?void 0:s.tagName)&&r.submitter.parentElement.load(),a=r.target.getElementSallaData(),salla.log("Data from element",a);case 10:if(!/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/gm.test(t)){e.next=12;break}return e.abrupt("return",salla.twilight.request(t,a,"post").finally((function(){var e;loaderSupported&&(null==r||null===(e=r.submitter)||void 0===e||e.parentElement.stop())})));case 12:return l=t.split("."),c=l.splice(-1),e.next=16,salla.call(l.join("."))[c](a).finally((function(){var e,t;return null==r||null===(e=r.submitter)||void 0===e||null===(t=e.parentElement)||void 0===t?void 0:t.stop()})).catch((function(e){throw salla.logger.warn(e),e}));case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"onSubmit",value:function(e,t){return salla.form.submit(e,t),!1}},{key:"onChange",value:function(e,t){var n;return null!=t&&t.currentTarget?"FORM"!==(null==t||null===(n=t.currentTarget)||void 0===n?void 0:n.tagName)||t.currentTarget.checkValidity()?(salla.form.submit(e,t.currentTarget.getElementSallaData()),!0):(salla.logger.warn("Trying to trigger '".concat(e,"' without filling required fields!")),!1):(salla.logger.warn("Trying to trigger '".concat(e,"' without event!")),!1)}}]),e}(),zn=function(){function e(t){var n=this;w(this,e),t.on("cookies::remove",(function(e){return n.remove(e)})),t.on("cookies::add",(function(e,t){return n.set(e,t)}))}return _(e,[{key:"get",value:function(e){var t;return null===(t=document.cookie.split("; ").find((function(t){return t.startsWith(e+"=")})))||void 0===t?void 0:t.split("=")[1]}},{key:"set",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,r="";if(n){var a=new Date;a.setTime(a.getTime()+24*n*60*60*1e3),r="; expires="+a.toUTCString()}return document.cookie="".concat(e,"=").concat(t).concat(r,'"; path=/; secure; SameSite=Lax"'),this}},{key:"remove",value:function(e){return document.cookie="".concat(e,"=; Max-Age=0; path=/;"),this}}]),e}(),Gn=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w(this,e),this.triedToGetCurrencies_=!1,this.languages_=[],this.triedToGetLanguages_=!1,this.currencies_={},this.default_properties={debug:"undefined"!=typeof process&&"development"===process.env.NODE_ENV,token:null,fastRequests:!0,canLeave:!0,store:{api:"https://api.salla.dev/store/v1/"},currencies:{SAR:{code:"SAR",name:"ريال سعودي",symbol:"ر.س",amount:1,country_code:"sa"}}},this.properties_=v(v({},this.default_properties),t)}var t,n;return _(e,[{key:"merge",value:function(e){return Object.assign(this.properties_,e),this.properties_.store=v(v({},this.default_properties.store),this.properties_.store),this}},{key:"set",value:function(e,t){return e.includes(".")?(salla.helpers.setNested(this.properties_,e,t),this):(this.properties_[e]=t,this)}},{key:"get",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return e.includes(".")?salla.helpers.getNested(this.properties_,e,t):this.properties_.hasOwnProperty(e)?this.properties_[e]||t:t||void 0}},{key:"isUser",value:function(){return"user"===this.get("user.type")}},{key:"isGuest",value:function(){return!this.isUser()}},{key:"languages",value:(n=b(g().mark((function e(){var t,n,r,a=this;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.triedToGetLanguages_){e.next=2;break}return e.abrupt("return",this.languages_);case 2:return this.triedToGetLanguages_=!0,r=!0,e.next=6,salla.document.api.request("languages",null,"get");case 6:if(e.t1=t=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===t;case 10:if(!e.t0){e.next=14;break}e.next=15;break;case 14:null===(n=t.data)||void 0===n||n.map((function(e){r&&(a.languages_=[],r=!1),e.code=e.code||e.iso_code,e.url=salla.url.get(e.code),e.is_rtl=e.is_rtl||e.rtl,a.languages_.push(e)}));case 15:return this.set("languages",this.languages_),e.abrupt("return",this.languages_);case 17:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"currencies",value:(t=b(g().mark((function e(){var t,n,r,a=this;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.triedToGetCurrencies_){e.next=2;break}return e.abrupt("return",this.currencies_);case 2:return this.triedToGetCurrencies_=!0,r=!0,e.next=6,salla.currency.api.list();case 6:if(e.t1=t=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===t;case 10:if(!e.t0){e.next=14;break}e.next=15;break;case 14:null===(n=t.data)||void 0===n||n.map((function(e){r&&(a.currencies_={},r=!1),e.country_code=e.code.substr(0,2).toLowerCase(),a.currencies_[e.code]=e}));case 15:return this.set("currencies",this.currencies_),e.abrupt("return",this.currencies_);case 17:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"currency",value:function(e){return e=e||this.get("user.currency_code"),this.get("currencies."+e)||Object.values(this.get("currencies"))[0]}}]),e}(),Vn=function(e){x(n,a);var t=q(n);function n(e){var r;return w(this,n),(e=e||{}).messages=e.messages||window.translations,e.locale=e.locale||(window.locale||navigator.language||navigator.userLanguage||"ar").split("-")[0],e.fallback=e.fallback||e.locale,(r=t.call(this,e)).translationsLoaded=!1,r}return _(n,[{key:"onLoaded",value:function(e){if(this.translationsLoaded)return e();salla.event.once("languages::translations.loaded",e)}},{key:"loadStoreTranslations",value:function(){if(this.messages)window.addEventListener("load",(function(e){salla.event.dispatch("languages::translations.loaded"),salla.logger.info("The messages of transactions is already loaded")}));else if(salla.url.get("")){var e=salla.config.get("theme.translations_hash",salla.config.get("store.id","twilight"));this.loadScript(salla.url.get("languages/assets/".concat(e,".js")))}else this.loadScript("https://cdn.salla.network/js/translations.js",!1)}},{key:"setMessages",value:function(e){L(S(n.prototype),"setMessages",this).call(this,e),salla.event.dispatch("languages::translations.loaded"),this.translationsLoaded=!0}},{key:"loadScript",value:function(e){var t=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=document.createElement("script");r.src=e,r.onload=function(){return window.translations?t.setMessages(window.translations):n?(salla.logger.info("Failed to load Translations for store, lets try load it from cdn"),t.loadScript("https://cdn.salla.network/js/translations.js",!1)):void salla.logger.warn("Failed to load Translations from the cdn\nor: salla.lang.setMessages({....}), see https://docs.salla.dev for more information's.")},document.head.appendChild(r)}},{key:"get",value:function(e,t,r){return window.translations&&(e="trans."+e),L(S(n.prototype),"get",this).call(this,e,t,r)}},{key:"set",value:function(e,t){return salla.helpers.setNested(this.messages[this.getLocale()+".trans"],e,t),this}}]),n}(),$n=i.createStore([o,s,l,c],[]),Hn=function(){function e(t){var n=this;w(this,e),t.on("storage::item.remove",(function(e){return n.remove(e)})),t.on("storage::item.set",(function(e,t){return n.set(e,t)})),this.store=$n}return _(e,[{key:"set",value:function(e,t){if(e.includes(".")){var n=e.split(".")[0],r=F({},n,$n.get(n));return r=salla.helpers.setNested(r,e,t),$n.set(n,r[n])}return $n.set(e,t)}},{key:"remove",value:function(e){return $n.remove(e)}},{key:"get",value:function(e,t){if(e.includes(".")){var n=e.split(".")[0];return salla.helpers.getNested(F({},n,$n.get(n)),e)}return $n.get(e,t)}}]),e}(),Wn=new ne,Bn=new be(Wn);window.Salla=window.salla={notify:f,api:Bn,event:Wn,helpers:Rn,config:new Gn,storage:new Hn(Wn),cookie:new zn(Wn),lang:new Vn,form:new Mn,cart:new we(Bn.cart,Wn.cart),auth:new we(Bn.auth,Wn.auth),gift:new we(Bn.gift,Wn.gift),order:new we(Bn.order,Wn.order),scope:new we(Bn.scope,Wn.scope),rating:new we(Bn.rating,Wn.rating),comment:new we(Bn.comment,Wn.comment),loyalty:new we(Bn.loyalty,Wn.loyalty),product:new we(Bn.product,Wn.product),profile:new we(Bn.profile,Wn.profile),currency:new we(Bn.currency,Wn.currency),document:new we(Bn.document,Wn.document),twilight:new we(Bn.twilight,Wn.twilight),wishlist:new we(Bn.wishlist,Wn.wishlist),logger:M,log:M.log,success:f.success,error:f.error,onReady:function(e){return salla.isInitiated?e():salla.event.once("twilight::initiated",e)},isInitiated:!1,AppHelpers:Un,infiniteScroll:new ke(void 0,Wn.infiniteScroll),money:Rn.money,url:Rn.url,init:function(e){return Bn.twilight.init(e)},call:function(e){for(var t=salla,n=e.split(".");n.length&&(t=t[n.shift()]););return t}};var Zn=salla;export{Zn as default};
3
+ g=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},a=r.iterator||"@@iterator",i=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function l(e,t,n,r){var a=t&&t.prototype instanceof d?t:d,i=Object.create(a.prototype),o=new x(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(a,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===a)throw i;return A()}for(n.method=a,n.arg=i;;){var o=n.delegate;if(o){var s=k(o,n);if(s){if(s===u)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var l=c(e,t,n);if("normal"===l.type){if(r=n.done?"completed":"suspendedYield",l.arg===u)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(r="completed",n.method="throw",n.arg=l.arg)}}}(e,n,o),i}function c(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var u={};function d(){}function h(){}function f(){}var p={};s(p,a,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(S([])));y&&y!==t&&n.call(y,a)&&(p=y);var m=f.prototype=d.prototype=Object.create(p);function b(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function r(a,i,o,s){var l=c(e[a],e,i);if("throw"!==l.type){var u=l.arg,d=u.value;return d&&"object"==typeof d&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(d).then((function(e){u.value=e,o(u)}),(function(e){return r("throw",e,o,s)}))}s(l.arg)}var a;this._invoke=function(e,n){function i(){return new t((function(t,a){r(e,n,t,a)}))}return a=a?a.then(i,i):i()}}function k(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,k(e,t),"throw"===t.method))return u;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return u}var r=c(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,u;var a=r.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,u):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,u)}function _(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function F(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(_,this),this.reset(!0)}function S(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:A}}function A(){return{value:void 0,done:!0}}return h.prototype=f,s(m,"constructor",f),s(f,"constructor",h),h.displayName=s(f,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,s(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},b(w.prototype),s(w.prototype,i,(function(){return this})),e.AsyncIterator=w,e.async=function(t,n,r,a,i){void 0===i&&(i=Promise);var o=new w(l(t,n,r,a),i);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},b(m),s(m,o,"Generator"),s(m,a,(function(){return this})),s(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=S,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(F),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],o=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),l=n.call(i,"finallyLoc");if(s&&l){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,u):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),u},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),F(n),u}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;F(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:S(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),u}},e}function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function m(e,t,n,r,a,i,o){try{var s=e[i](o),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,a)}function b(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var i=e.apply(t,n);function o(e){m(i,r,a,o,s,"next",e)}function s(e){m(i,r,a,o,s,"throw",e)}o(void 0)}))}}function w(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function k(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _(e,t,n){return t&&k(e.prototype,t),n&&k(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function F(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function x(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&A(e,t)}function S(e){return S=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},S(e)}function A(e,t){return A=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},A(e,t)}function E(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function O(e,t,n){return O=E()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var a=new(Function.bind.apply(e,r));return n&&A(a,n.prototype),a},O.apply(null,arguments)}function P(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function j(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return P(e)}function C(e){var t=E();return function(){var n,r=S(e);if(t){var a=S(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return j(this,n)}}function q(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=S(e)););return e}function L(){return L="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=q(e,t);if(r){var a=Object.getOwnPropertyDescriptor(r,t);return a.get?a.get.call(arguments.length<3?e:n):a.value}},L.apply(this,arguments)}function T(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,a,i=[],o=!0,s=!1;try{for(n=n.call(e);!(o=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);o=!0);}catch(e){s=!0,a=e}finally{try{o||null==n.return||n.return()}finally{if(s)throw a}}return i}(e,t)||D(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e){return function(e){if(Array.isArray(e))return N(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||D(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function D(e,t){if(e){if("string"==typeof e)return N(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?N(e,t):void 0}}function N(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var R,U,M=(R=window.console,U={log:function(e,t){if(R){"trace"===salla.config.get("debug")&&(t="trace");var n=R.log,r=void 0===t?n:this.__dict__[t]||n,a=["%cTwilight","color: #5cd5c4;font-weight:bold; border:1px solid #5cd5c4; padding: 2px 6px; border-radius: 5px;"],i={event:"#CFF680",backend:"#7b68ee"}[t];i&&(a[0]+="%c"+t[0].toUpperCase()+t.substring(1),a.push("margin-left: 5px;color: ".concat(i,";font-weight:bold; border:1px solid ").concat(i,"; padding: 2px 6px; border-radius: 5px;"))),r.call.apply(r,[R].concat(I(a.concat.apply(a,I(e)))))}},__dict__:{trace:R.trace,debug:R.debug,info:R.info,warn:R.warn,error:R.error}},{event:function(){U.log(arguments,"event")},trace:function(){U.log(arguments,"trace")},debug:function(){U.log(arguments,"debug")},info:function(){U.log(arguments,"info")},warn:function(){U.log(arguments,"warn")},error:function(){U.log(arguments,"error")},log:function(){U.log(arguments,void 0)},backend:function(){U.log(arguments,"backend")},logs:function(e){[e].flat().forEach((function(e){return e&&U.log([e].flat(),"backend")}))}}),z=function(){function e(t){w(this,e),this.parent=t,this.events={},this.namespace="";var n=/function (.{1,})\(/.exec(this.constructor.toString());this.className=(n&&n.length>1?n[1]:"").toLowerCase()}return _(e,[{key:"after_init",value:function(){this.createDynamicFunctions()}},{key:"createDynamicFunctions",value:function(){var e=this;Object.keys(this.events).forEach((function(t){e.createDynamicEventFuns(t),e.createDynamicListenerFuns(t)}))}},{key:"createDynamicEventFuns",value:function(e){if(!this[e]){var t=this;this[e]=function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return t.dispatch.apply(t,[e].concat(r))}}}},{key:"createDynamicListenerFuns",value:function(e){var t="on"+e.charAt(0).toUpperCase()+e.slice(1);if(!this[t]){var n=this;this[t]=function(t){return n.on(e,t)}}}},{key:"getEventName",value:function(e){return e=this.events[e]||e,!this.namespace||e.includes("::")?e:this.namespace+this.parent.delimiter+e}},{key:"dispatch",value:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return(t=this.parent).dispatch.apply(t,[this.getEventName(e)].concat(r))}},{key:"on",value:function(e,t){this.parent.addListener(this.getEventName(e),t)}},{key:"once",value:function(e,t){this.parent.once(this.getEventName(e),t)}},{key:"register",value:function(e,t){this.on(e,t)}},{key:"registerEventTemporary",value:function(e,t,n){n||(n=1),emitter.many(e,n,t)}}]),e}(),G=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="auth",r.events={login:"login",logout:"logout",codeSent:"code.sent",codeNotSent:"code.not-sent",verified:"verified",verificationFailed:"verification.failed",loggedIn:"logged.in",registered:"registered",registrationFailed:"registration.failed",loggedOut:"logged.out",failedLogout:"failed.logout",tokenFetched:"token.fetched",refreshFailed:"refresh.failed"},r.after_init(),r}return _(n,[{key:"login",value:function(e){return e?(e.type&&this.setTypeActionOnVerified(e.type),this.next_event=e.next_event||null,this.dispatch.apply(this,["login"].concat(Array.prototype.slice.call(arguments)))):(this.next_event=null,this.dispatch.apply(this,["login"].concat(Array.prototype.slice.call(arguments))))}},{key:"loggedIn",value:function(e){var t=this;salla.profile.info().then((function(e){salla.config.set("user",{id:e.data.id,type:"user",email:e.data.email,mobile:e.data.phone.code+e.data.phone.number,country_code:e.data.phone.country,language_code:e.data.language,currency_code:e.data.currency})})).finally((function(){return t.dispatch("loggedIn",e)}))}},{key:"setTypeActionOnVerified",value:function(e){this.type_action_on_verified=e}},{key:"getTypeActionOnVerified",value:function(){return this.type_action_on_verified||"redirect"}}]),n}(),V=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="cart",r.events={latestFetched:"latest.fetched",latestFailed:"latest.failed",updated:"updated",itemUpdated:"item.updated",itemUpdatedFailed:"item.updated.failed",itemAdded:"item.added",itemAddedFailed:"item.added.failed",itemDeleted:"item.deleted",itemDeletedFailed:"item.deleted.failed",submitted:"submitted",submitFailed:"submit.failed",imageDeleted:"image.deleted",imageNotDeleted:"image.not.deleted",detailsFetched:"details.fetched",detailsNotFetched:"details.not.fetched",successReset:"success.reset",couponAdded:"coupon.added",couponDeleted:"coupon.deleted",couponAdditionFailed:"coupon.addition.failed",couponDeletionFailed:"coupon.deletion.failed"},r.after_init(),r}return _(n,[{key:"updated",value:function(e){var t;return salla.cookie.set("fresh_summary",1),e&&"object"===y(e)?(e.offer&&salla.product.event.offerExisted(e.offer),salla.storage.set("cart.summary",{total:e.cart.total,sub_total:e.cart.sub_total,discount:e.cart.discount,real_shipping_cost:e.cart.real_shipping_cost,count:e.cart.count,shipping_cost:null!==(t=e.cart.free_shipping_bar)&&void 0!==t&&t.has_free_shipping?0:e.cart.real_shipping_cost}),this.dispatch("updated",e.cart)):(salla.logger.info("Cart summary not an object!",e),this.dispatch("updated"))}},{key:"latestFetched",value:function(e){return this.updated(e.data),this.dispatch("latestFetched",e)}},{key:"itemAdded",value:function(e,t){return this.updated(e.data),this.dispatch("itemAdded",e,t)}},{key:"itemDeleted",value:function(e,t){return this.updated(e.data),this.dispatch("itemDeleted",e,t)}},{key:"itemUpdated",value:function(e,t){return this.updated(e.data),this.dispatch("itemUpdated",e,t)}},{key:"couponAdded",value:function(e,t){return this.updated(e.data),this.dispatch("couponAdded",e,t)}},{key:"couponDeleted",value:function(e,t){return this.updated(e.data),this.dispatch("couponDeleted",e,t)}}]),n}(),$=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="order",r.events={canceled:"canceled",notCanceled:"not.canceled",orderCreated:"order.created",orderCreationFailed:"order.creation.failed",invoiceSent:"invoice.sent",invoiceNotSent:"invoice.not.sent"},r.after_init(),r}return _(n)}(),H=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="scope",r.events={fetched:"fetched",notFetched:"not.fetched",productAvailabilityFetched:"product-availability.fetched",productAvailabilityNotFetched:"product-availability.not.fetched",changeSucceeded:"changed",changeFailed:"not.changed"},r.after_init(),r}return _(n)}(),W=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="rating",r.events={orderNotFetched:"order.not.fetched",orderFetched:"order.fetched",storeRated:"store.rated",storeFailed:"store.failed",productsRated:"products.rated",productsFailed:"products.failed",shippingRated:"shipping.rated",shippingFailed:"shipping.failed"},r.after_init(),r}return _(n)}(),B=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="comment",r.events={added:"added",additionFailed:"addition.failed"},r.after_init(),r}return _(n)}(),Z=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="loyalty",r.events={exchangeSucceeded:"exchange.succeeded",exchangeFailed:"exchange.failed",programFetched:"program.fetched",programNotFetched:"program.not.fetched",resetSucceeded:"exchange-reset.succeeded",resetFailed:"exchange-reset.failed"},r.after_init(),r}return _(n)}(),Q=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="profile",r.events={updated:"updated",updateFailed:"update.failed",verificationCodeSent:"verification.code.sent",updateContactsFailed:"update.contacts.failed",verified:"verified",unverified:"unverified",infoFetched:"info.fetched",infoNotFetched:"info.not.fetched"},r.after_init(),r}return _(n)}(),J=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="product",r.events={priceUpdated:"price.updated",priceUpdateFailed:"price.updated.failed",availabilitySubscribed:"availability.subscribed",availabilitySubscribeFailed:"availability.subscribe.failed",categoriesFetched:"categories.fetched",categoriesFailed:"categories.failed",searchFailed:"search.failed",searchResults:"search.results",offerExisted:"offer.existed",fetchOffersFailed:"fetch.offers.failed",offersFetched:"offers.fetched",sizeGuideFetched:"size-guide.fetched",SizeGuideFetchFailed:"size-guide.failed",giftFetched:"gift.fetched",giftFetchFailed:"gift.failed",addGiftToCartSucceeded:"gift.add-to-cart.succeeded",addGiftToCartFailed:"gift.add-to-cart.failed",giftImageUploadSucceeded:"gift.image-upload.succeeded",giftImageUploadFailed:"gift.image-upload.failed"},r.after_init(),r}return _(n)}(),K=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="document",r.events={click:"click",change:"change",submit:"submit",keyup:"keyup",leaving:"leaving",request:"request",requestFailed:"request.failed"},r.after_init(),r}return _(n,[{key:"onClick",value:function(e,t){this.fireCallableFuns("click",e,t)}},{key:"onChange",value:function(e,t){this.fireCallableFuns("change",e,t)}},{key:"onSubmit",value:function(e,t){this.fireCallableFuns("submit",e,t)}},{key:"onKeyup",value:function(e,t){this.fireCallableFuns("keyup",e,t)}},{key:"fireCallableFuns",value:function(e,t,n){this.on(e,(function(e){"function"!=typeof t?"function"==typeof n&&e.target.matches(t)&&n(e):t(e)}))}},{key:"fireEvent",value:function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),a=2;a<n;a++)r[a-2]=arguments[a];return this.fireEventForElements.apply(this,[e,t,!1].concat(r))}},{key:"fireEventForAll",value:function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),a=2;a<n;a++)r[a-2]=arguments[a];return this.fireEventForElements.apply(this,[e,t,!0].concat(r))}},{key:"fireEventForElements",value:function(e,t,n){for(var r=this,a=arguments.length,i=new Array(a>3?a-3:0),o=3;o<a;o++)i[o-3]=arguments[o];if("string"==typeof e){if(n)return document.querySelectorAll(e).forEach((function(e){return r.fireEventForElements.apply(r,[e,t,!1].concat(i))}));e=document.querySelector(e)}if(e){var s=O(CustomEvent,[t].concat(i));return e.dispatchEvent(s)}salla.log("Failed To get element to fire event: "+t)}}]),n}(),X=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="wishlist",r.events={added:"added",removed:"removed",additionFailed:"addition.failed",removingFailed:"removing.failed"},r.after_init(),r}return _(n)}(),Y=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="currency",r.events={changed:"changed",failed:"failed",fetched:"fetched",failedToFetch:"failed.to.fetch"},r.after_init(),r}return _(n)}(),ee=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="twilight",r.events={initiated:"initiated"},r.after_init(),r}return _(n)}(),te=function(e){x(n,z);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="infiniteScroll",r.events={scrollThreshold:"scroll.threshold",request:"request",load:"load",append:"append",error:"error",last:"last",history:"history"},r.after_init(),r}return _(n)}(),ne=function(t){x(r,e);var n=C(r);function r(){var e;w(this,r);return(e=n.call(this,{wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1})).globalListners={},e.delimiter="::",e.auth=new G(P(e)),e.cart=new V(P(e)),e.order=new $(P(e)),e.scope=new H(P(e)),e.rating=new W(P(e)),e.comment=new B(P(e)),e.loyalty=new Z(P(e)),e.product=new J(P(e)),e.profile=new Q(P(e)),e.currency=new Y(P(e)),e.document=new K(P(e)),e.twilight=new ee(P(e)),e.wishlist=new X(P(e)),e.infiniteScroll=new te(P(e)),e.body=document.querySelector("body"),e.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],e.ingoreLogEvents=["document::click","document::keyup","document::change"],e.noneFireableActions=["document.request"],e.on("twilight::initiated",e.initiateSallaInAllClasses),e}return _(r,[{key:"initiateSallaInAllClasses",value:function(){var e=this;Object.keys(salla).forEach((function(t){"object"==y(t=salla[t])&&(e.callSallaInitiate(t),Object.keys(t).forEach((function(n){e.callSallaInitiate(t[n])})))}))}},{key:"callSallaInitiate",value:function(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}},{key:"createAndDispatch",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.dispatch.apply(this,[e].concat(n))}},{key:"dispatch",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var a,i,o=e.replace("::",".");if(!this.noneFireableActions.includes(o)&&"function"==typeof salla.call(o))return salla.log("'salla.".concat(o,"(...)' triggered using event '").concat(e,"'")),o=o.split("."),void(a=salla[o[0]])[o[1]].apply(a,n);(this.emit.apply(this,[e].concat(n)),window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign.apply(Object,[{event:e}].concat(I(n.values())))),this.ingoreLogEvents.includes(e)||!salla.config.get("debug")&&!this.logableEvents.includes(e))||(i=salla.logger).event.apply(i,[e].concat(n));var s=this;Object.keys(this.globalListners).forEach((function(t){var r;(r=s.globalListners)[t].apply(r,[e].concat(n))})),this.dispatchMobileEvent(e,v({},n.values()))}},{key:"dispatchEvents",value:function(e){if(e&&"object"===y(e))for(var t=0,n=Object.entries(e);t<n.length;t++){var r=T(n[t],2),a=r[0],i=r[1];this.dispatch(a,i)}else salla.log("No Events To Dispatch!",e)}},{key:"addListener",value:function(e,t){this.on(e,t)}},{key:"addEventListener",value:function(e,t){this.addListener(e,t)}},{key:"listen",value:function(e,t){this.addListener(e,t)}},{key:"registerGlobalListener",value:function(e,t){this.globalListners[e]=t}},{key:"dispatchMobileEvent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){salla.logger.warn(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){salla.logger.warn(e,"The native context does not exist yet")}}}]),r}(),re=function(){function e(t){w(this,e),this.parent=t,this.endpoints={},this.webEndpoints=[],this.namespace="BaseApi",this.endpointsMethods={},this.endpointsHeaders={};var n=/function (.{1,})\(/.exec(this.constructor.toString());this.className=(n&&n.length>1?n[1]:"").toLowerCase(),this.debounce={request:void 0,time:300,enabled:!0,exclude:[]}}return _(e,[{key:"after_init",value:function(){}},{key:"normalRequest",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=this,a=Array.isArray(e),i=a?this.getUrl.apply(this,I(e)):this.getUrl(e);e=a?e[0]:e,n=n||this.endpointsMethods[e]||"post";var o=this.endpointsHeaders[e];if("get"===n&&t instanceof FormData){var s={};Array.from(t.entries()).forEach((function(e){s[e[0]]=e[1]})),t={params:s}}o&&"get"===n&&(t=t?Object.assign(t,o):o);var l={namespace:this.namespace,action:e,url:i,payload:t,method:n,headers:o};try{salla.event.document.request(l)}catch(e){return salla.event.document.requestFailed(l),new Promise((function(){throw e}))}this.webEndpoints.includes(e)?i=salla.url.get(i):"http"!==i.substring(0,4)&&(i=salla.url.api(i));var c="undefined"!=typeof event?event.currentTarget:null,u=!1;return"SALLA-BUTTON"===(null==c?void 0:c.tagName)&&(u=!0),u&&(null==c||c.load()),this.parent[n](i,t,{headers:o}).then((function(e){return u&&(null==c||c.stop()),e.data&&e.request&&(e=e.data),r.handleAfterResponseActions(e),e})).catch((function(e){throw u&&(null==c||c.stop()),salla.event.document.requestFailed(l,e),r.handleErrorResponse(e),e}))}},{key:"request",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return!this.isFastRequestsAllowed()&&this.debounce.enabled?(this.debounce.request||(this.debounce.request=salla.helpers.debounce(this.normalRequest.bind(this),this.debounce.time)),this.debounce.request(e,t,n)):this.normalRequest(e,t,n)}},{key:"getUrl",value:function(e){for(var t=this.endpoints[e]||e,n=/{[^{}]+}/i,r=1;r<arguments.length;r++)t=t.replace(n,arguments[r]);return t}},{key:"handleAfterResponseActions",value:function(e){var t;if(e){var n=e.data,r=e.googleTags,a=void 0===r?null:r,i=n&&n.googleTags?n.googleTags:a;dataLayer&&i&&dataLayer.push(i),this.fireEventsForResponse(e),this.renderSections(e),this.showAlert(e),(null===(t=e.data)||void 0===t?void 0:t.token)&&salla.event.auth.tokenFetched(e.data.token)}}},{key:"fireEventsForResponse",value:function(e){var t,n,r=e.events||(null===(t=e.data)||void 0===t?void 0:t.events)||(null===(n=e.error)||void 0===n?void 0:n.events);"string"==typeof r&&(r=JSON.parse(r)),r&&Object.keys(r).forEach((function(e){return salla.event.dispatch(e,r[e])}))}},{key:"renderSections",value:function(e){e.sections&&Object.keys(e.sections).forEach((function(t){document.querySelectorAll(t.toSelector()).forEach((function(n){n.innerHTML=e.sections[t]}))}))}},{key:"handleErrorResponse",value:function(e){if(e.response&&e.response.data)return e.response.data.error&&e.response.data.error.fields&&!salla.config.get("sdk.notifier_handler_disabled",!1)?this.handleInvalidFields(e):this.handleAfterResponseActions(e.response.data)}},{key:"showAlert",value:function(e){var t,n;if(e&&!salla.config.get("sdk.notifier_handler_disabled",!1))return e.case&&e.msg?salla.notify.fire(e.msg,e.case,e):e.hasOwnProperty("success")&&null!==(t=e.data)&&void 0!==t&&t.message?salla.notify.fire(null===(n=e.data)||void 0===n?void 0:n.message,e.success?salla.notify.types.success:salla.notify.types.error,e):e.error&&e.error.message&&"FORBIDDEN"!==e.error.message?salla.error(e.error.message,e):void 0}},{key:"handleInvalidFields",value:function(e){var t=e.response.data.error.fields,n=[];Object.keys(t).forEach((function(e){var r=t[e];Array.isArray(r)?r.forEach((function(e){return n.push(e)})):n.push(r)}));var r=(n.length>1?"* ":"")+n.join("\n* ");salla.error(r,e)}},{key:"event",value:function(){return salla.event[this.className]}},{key:"getPossibleValue",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(e){if("object"!==y(e))return e;for(var r,a=0;a<t.length&&!(r=e[t[a]])&&!("undefined"!=typeof FormData&&e instanceof FormData&&(r=e.get(t[a])));a++);return"object"!=y(r=r||e)||n?r:void 0}}},{key:"isFastRequestsAllowed",value:function(){return salla.config.get("fastRequests")}},{key:"promise",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new Promise((function(n,r){return t?n(e):r(e)}))}},{key:"errorPromise",value:function(e){return this.promise(e,!1)}},{key:"successPromise",value:function(e){return this.promise(e,!0)}}]),e}(),ae=function(e){x(p,re);var t,n,r,a,i,o,s,l,c,u,d,h,f=C(p);function p(e){var t;return w(this,p),(t=f.call(this,e)).namespace="cart",t.endpoints={latest:"cart/latest",details:"cart/{cart}",quickAdd:"cart/{cart}/item/{product}/quick-add",addItem:"cart/{cart}/item/{product}/add",deleteItem:"cart/{cart}/item/{item}",updateItem:"cart/{cart}/item/{item}",deleteImage:"cart/{cart}/image/{image}",uploadImage:"cart/{cart}/image",status:"cart/{cart}/status",addCoupon:"cart/{id}/coupon",deleteCoupon:"cart/{id}/coupon"},t.endpointsMethods={latest:"get",details:"get",status:"get",updateItem:"post",deleteItem:"delete",deleteImage:"delete",deleteCoupon:"put"},t.webEndpoints=["latest"],t.latestCart=null,t.after_init(),t}return _(p,[{key:"getCurrentCartId",value:(h=b(g().mark((function e(){var t;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.latestCart){e.next=2;break}return e.abrupt("return",this.latestCart.cart.id);case 2:return e.next=4,this.latest();case 4:return t=e.sent,this.latestCart=t.data,e.abrupt("return",this.latestCart.cart.id);case 7:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"getUploadImageEndpoint",value:(d=b(g().mark((function e(t){return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=4;break}return e.next=3,this.getCurrentCartId();case 3:t=e.sent;case 4:return e.abrupt("return",salla.url.api(this.getUrl("uploadImage",t)));case 5:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"latest",value:function(){return this.request("latest",{params:{source:""}}).then((function(e){return salla.storage.set("cart",e.data.cart),salla.event.cart.latestFetched(e),e})).catch((function(e){throw salla.storage.set("cart",""),salla.event.cart.latestFailed(e),e}))}},{key:"details",value:(u=b(g().mark((function e(){var t;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getCurrentCartId();case 2:return t=e.sent,e.abrupt("return",this.request(["details",t]).then((function(e){return salla.cart.event.detailsFetched(e),e})).catch((function(e){throw salla.cart.event.detailsNotFetched(e),e})));case 4:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"quickAdd",value:(c=b(g().mark((function e(t){return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.addItem(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"addItem",value:(l=b(g().mark((function e(t){var n,r,a,i;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((n=this.getCartPayload(t)).id){e.next=5;break}return r='There is no product "id"!',salla.cart.event.itemAddedFailed(r),e.abrupt("return",this.errorPromise(r));case 5:return a=this.getPossibleValue(n.payload,["quantity","donating_amount"])?"addItem":"quickAdd",e.next=8,this.getCurrentCartId();case 8:return i=e.sent,e.abrupt("return",this.request([a,i,n.id],n.payload).then((function(e){return salla.cart.event.itemAdded(e,n.id),e})).catch((function(e){throw salla.cart.event.itemAddedFailed(e,n.id),e})));case 10:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"deleteItem",value:(s=b(g().mark((function e(t){var n,r,a;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((n=this.getCartPayload(t)).id){e.next=5;break}return r='There is no "id"!',salla.cart.event.itemDeletedFailed(r),e.abrupt("return",this.errorPromise(r));case 5:return e.next=7,this.getCurrentCartId();case 7:return a=e.sent,e.abrupt("return",this.request(["deleteItem",a,n.id]).then((function(e){return salla.cart.event.itemDeleted(e,n.id),e})).catch((function(e){throw salla.cart.event.itemDeletedFailed(e,n.id),e})));case 9:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"updateItem",value:(o=b(g().mark((function e(t){var n,r,a,i;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((r=this.getCartPayload(t)).id){e.next=5;break}return a='There is no "id"!',salla.cart.event.itemUpdatedFailed(a),e.abrupt("return",this.errorPromise(a));case 5:return e.next=7,this.getCurrentCartId();case 7:return i=e.sent,"Object"===(null===(n=r.payload.constructor)||void 0===n?void 0:n.name)?r.payload._method="PUT":r.payload.append("_method","PUT"),e.abrupt("return",this.request(["updateItem",i,r.id],r.payload).then((function(e){return salla.cart.event.itemUpdated(e,r.id),e})).catch((function(e){throw salla.cart.event.itemUpdatedFailed(e,r.id),e})));case 10:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"deleteImage",value:(i=b(g().mark((function e(t){var n,r;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.getPossibleValue(t,["id","image_id","photo_id"])){e.next=4;break}return n='There is no "id"!',salla.cart.event.imageNotDeleted(n),e.abrupt("return",this.errorPromise(n));case 4:return e.next=6,this.getCurrentCartId();case 6:return r=e.sent,e.abrupt("return",this.request(["deleteImage",r,t]).then((function(e){return salla.cart.event.imageDeleted(e,t),e})).catch((function(e){throw salla.cart.event.imageNotDeleted(e,t),e})));case 8:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"status",value:(a=b(g().mark((function e(t){return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.t0=t,e.t0){e.next=5;break}return e.next=4,this.getCurrentCartId();case 4:e.t0=e.sent;case 5:return t=e.t0,e.abrupt("return",this.request(["status",t],{params:{has_apple_pay:!!window.ApplePaySession}}));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"submit",value:(r=b(g().mark((function e(){var t=this;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=this,e.next=3,this.getCurrentCartId();case 3:e.t1=e.sent,e.t0.status.call(e.t0,e.t1).then((function(e){var n=e.data.next_step.to;if(!["checkout","refresh","login"].includes(n)){var r="Can't find next_step );";throw salla.cart.event.submitFailed(r),r}if(salla.cart.event.submitted(e),"login"===n)return salla.auth.setCanRedirect(!1),salla.event.dispatch("login::open"),void salla.auth.event.onLoggedIn((function(e){salla.event.dispatch("login::close"),t.submit()}));"checkout"===n?window.location.href=e.data.next_step.url+(window.ApplePaySession?"?has_apple_pay=true":""):window.location.reload()})).catch((function(e){throw salla.cart.event.submitFailed(e),e}));case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getCartPayload",value:function(e){var t,n=(null===(t=e)||void 0===t?void 0:t.data)||("object"==y(e)?e:void 0);return{id:e=n?this.getPossibleValue(n,["prod_id","product_id","item_id","id"]):e,payload:n="object"==y(n)?n:void 0}}},{key:"handleAfterResponseActions",value:function(e){if(403===e.status){salla.storage.remove("cart");var t=salla.lang.get("pages.checkout.try_again");throw salla.error(t),t}L(S(p.prototype),"handleAfterResponseActions",this).call(this,e)}},{key:"reset",value:function(){salla.storage.remove("cart"),salla.cart.event.successReset()}},{key:"addCoupon",value:(n=b(g().mark((function e(t){var n,r;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=t.data||t,t=this.getPossibleValue(t,["coupon"])){e.next=6;break}return(n=new Error('There is no "Coupon Code"!')).name="EmptyCoupon",salla.event.cart.couponAdditionFailed(n),e.abrupt("return",this.errorPromise(n));case 6:return e.next=8,salla.cart.api.getCurrentCartId();case 8:return r=e.sent,e.abrupt("return",this.request(["addCoupon",r],{coupon:t}).then((function(e){return salla.event.cart.couponAdded(e,r),e})).catch((function(e){throw salla.event.cart.couponAdditionFailed(e,r),e})));case 10:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"deleteCoupon",value:(t=b(g().mark((function e(){var t;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,salla.cart.api.getCurrentCartId();case 2:return t=e.sent,e.abrupt("return",this.request(["deleteCoupon",t],{}).then((function(e){return salla.event.cart.couponDeleted(e,t),e})).catch((function(e){throw salla.event.cart.couponDeletionFailed(e,t),e})));case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),p}(),ie=function(e){x(a,re);var t,n,r=C(a);function a(e){var t;return w(this,a),(t=r.call(this,e)).namespace="loyalty",t.endpoints={getProgram:"loyalty",exchange:"loyalty/exchange",reset:"loyalty/exchange"},t.endpointsMethods={getProgram:"get",reset:"put"},t.after_init(),t}return _(a,[{key:"getProgram",value:function(){return this.request("getProgram").then((function(e){return salla.loyalty.event.programFetched(e),e})).catch((function(e){throw salla.loyalty.event.programNotFetched(e),e}))}},{key:"exchange",value:(n=b(g().mark((function e(t){var n,r,a,i=arguments;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=i.length>1&&void 0!==i[1]?i[1]:null,t=this.getPossibleValue(t,["id","loyalty_prize_id","prize_id"])){e.next=6;break}return r="Unable to find cart id. Please provide one.",salla.loyalty.event.exchangeFailed(r),e.abrupt("return",this.errorPromise(r));case 6:if(e.t0=n,e.t0){e.next=11;break}return e.next=10,salla.cart.getCurrentCartId();case 10:e.t0=e.sent;case 11:if(n=e.t0){e.next=16;break}return a="Unable to find cart id. Please provide one.",salla.loyalty.event.exchangeFailed(a),e.abrupt("return",this.errorPromise(a));case 16:return e.abrupt("return",this.request("exchange",{loyalty_prize_id:t,cart_id:n}).then((function(e){return salla.loyalty.event.exchangeSucceeded(e,t),e})).catch((function(e){throw salla.loyalty.event.exchangeFailed(e,t),e})));case 17:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"reset",value:(t=b(g().mark((function e(){var t,n,r=arguments;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.length>0&&void 0!==r[0]?r[0]:null,e.t0=t,e.t0){e.next=6;break}return e.next=5,salla.cart.getCurrentCartId();case 5:e.t0=e.sent;case 6:if(t=e.t0){e.next=11;break}return n="Unable to find cart id. Please provide one.",salla.loyalty.event.resetFailed(n),e.abrupt("return",this.errorPromise(n));case 11:return e.abrupt("return",this.request("reset",{cart_id:t}).then((function(e){return salla.loyalty.event.resetSucceeded(e),e})).catch((function(e){throw salla.loyalty.event.resetFailed(e),e})));case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),a}(),oe=function(e){x(r,re);var t,n=C(r);function r(e){var t;return w(this,r),(t=n.call(this,e)).namespace="auth",t.canRedirect_=!0,t.endpoints={login:"auth/{type}/send_verification",resend:"auth/resend_verification",verify:"auth/{type}/verify",register:"auth/register",logout:"logout",refresh:"auth/refresh"},t.webEndpoints=["logout","auth/jwt","refresh"],t.endpointsMethods={logout:"get"},t.after_init(),t}return _(r,[{key:"setCanRedirect",value:function(e){salla.api.auth.canRedirect_=e}},{key:"canRedirect",value:function(){return salla.api.auth.canRedirect_}},{key:"login",value:function(e){e.data&&(e=e.data);var t=this.getPossibleValue(e,["type"]);if(!["email","mobile"].includes(t)){var n="Login type should be in: [email, mobile]";return salla.auth.event.codeNotSent(n),this.errorPromise(n)}return this.request(["login",t],e).then((function(e){return salla.auth.event.codeSent(e,t),e})).catch((function(e){throw salla.auth.event.codeNotSent(e,t),e}))}},{key:"verify",value:(t=b(g().mark((function e(t){var n,r,a,i,o,s=arguments;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=!(s.length>1&&void 0!==s[1])||s[1],a=this.getPossibleValue(t,["type"])){e.next=6;break}return i="Failed to know what's login type!",salla.auth.event.verificationFailed(i),e.abrupt("return",this.errorPromise(i));case 6:return r=!1!==this.getPossibleValue(t,["supportWebAuth"])&&r,salla.auth.event.next_event&&(t.next_event=salla.auth.event.next_event),e.next=10,this.request(["verify",a],t);case 10:if(200===(null==(o=e.sent)?void 0:o.status)){e.next=14;break}return salla.auth.event.verificationFailed(o,a),e.abrupt("return",this.errorPromise(o));case 14:if(e.t0=r,!e.t0){e.next=18;break}return e.next=18,this.request("auth/jwt");case 18:return"authenticated"===(null===(n=o.data)||void 0===n?void 0:n.case)&&salla.auth.event.loggedIn(o),salla.auth.event.verified(o,a),e.abrupt("return",this.successPromise(o));case 21:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"resend",value:function(e){var t;return(e=e.data||e).type=e.type||"mobile","mobile"!==e.type||e.phone&&e.country_code?"email"!==e.type||e.email?this.request("resend",e).then((function(t){return salla.auth.event.codeSent(t,e),t})).catch((function(t){throw salla.auth.event.codeNotSent(t,e),t})):(salla.auth.event.codeNotSent(t="There is no email!",e),this.errorPromise(t)):(salla.auth.event.codeNotSent(t="There is no phone or country_code!",e),this.errorPromise(t))}},{key:"register",value:function(e){var t;return e.data&&(t=e.element,e=e.data),salla.auth.event.next_event&&(e.next_event=salla.auth.event.next_event),this.request("register",e).then((function(e){var n;return salla.auth.event.registered.call(t,e),"authenticated"===(null===(n=e.data)||void 0===n?void 0:n.case)&&salla.auth.event.loggedIn(e),e})).catch((function(e){throw salla.auth.event.registrationFailed.call(t,e),e}))}},{key:"logout",value:function(){return this.request("logout").then((function(e){return salla.auth.event.loggedOut(e),salla.log("Reloading after 0.1 sec..."),setTimeout((function(){return location.reload()}),100),e})).catch((function(e){throw salla.auth.event.failedLogout(e),e}))}},{key:"refresh",value:function(){return this.request("refresh").catch((function(e){throw salla.auth.event.refreshFailed(e),e}))}}]),r}(),se=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="order",r.endpoints={cancel:"orders/cancel/{id}",createCartFromOrder:"reorder/{id}",sendInvoice:"orders/send/{id}"},r.endpointsMethods={createCartFromOrder:"get"},r.after_init(),r}return _(n,[{key:"show",value:function(e){var t=this.getPossibleValue((null==e?void 0:e.data)||e,["id","order_id"]);salla.event.dispatch("mobile::order.placed",{order_id:t}),location.href=this.getPossibleValue((null==e?void 0:e.data)||e,["url"])}},{key:"cancel",value:function(e){return e=e||salla.config.get("page.id"),this.request(["cancel",e],{params:{has_apple_pay:!!window.ApplePaySession}}).then((function(t){return salla.event.order.canceled(t,e),t})).catch((function(t){throw salla.event.order.notCanceled(t,e),t}))}},{key:"createCartFromOrder",value:function(e){return e=e||salla.config.get("page.id"),this.request(["createCartFromOrder",e]).then((function(t){return salla.storage.set("cart",{id:t.data.cart_id,user_id:salla.config.get("user.id")}),salla.event.order.orderCreated(t,e),window.location.href=t.data.url,t})).catch((function(t){throw salla.event.order.orderCreationFailed(t,e),t}))}},{key:"sendInvoice",value:function(e){var t=this.getPossibleValue(e,["id"])||salla.config.get("page.id");if(!t||isNaN(t)){var n="There is no id!";return salla.order.event.invoiceNotSent(n),this.errorPromise(n)}return this.request(["sendInvoice",t],e).then((function(e){return salla.event.order.invoiceSent(e,t),e})).catch((function(e){throw salla.event.order.invoiceNotSent(e,t),e}))}}]),n}(),le=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="product",r.previousQuery="",r.endpoints={getPrice:"products/{id}/price",availabilitySubscribe:"products/{id}/availability-notify",search:"products/search",categories:"products/categories/{?id}",purchaseNow:"checkout/quick-purchase/{id}",offers:"products/{product_id}/specialoffer",getSizeGuides:"products/{prod_id}/size-guides",giftDetail:"products/{product_id}/buy-as-gift",giftToCart:"products/{product_id}/buy-as-gift",giftImage:"products/buy-as-gift/image"},r.endpointsMethods={giftDetail:"get"},r.webEndpoints=["purchaseNow"],r.after_init(),r}return _(n,[{key:"getPrice",value:function(e){var t=e.data||e,n=this.getPossibleValue(t,["id","prod_id","product_id"]);return this.request(["getPrice",n],"object"==y(t)?t:void 0).then((function(e){return salla.product.event.priceUpdated(e,n),e})).catch((function(e){throw salla.product.event.priceUpdateFailed(e,n),e}))}},{key:"categories",value:function(e){return this.request(["categories",e||""],null,"get").then((function(e){return salla.product.event.categoriesFetched(e),e})).catch((function(e){throw salla.product.event.categoriesFailed(e),e}))}},{key:"availabilitySubscribe",value:function(e){var t=e.data||e;return e=this.getPossibleValue(t,["id","prod_id"]),this.request(["availabilitySubscribe",e],"object"==y(t)?t:void 0).then((function(t){return salla.product.event.availabilitySubscribed(t,e),t})).catch((function(t){throw salla.product.event.availabilitySubscribedFailed(t,e),t}))}},{key:"search",value:function(e){var t,n=e.data;if(n||(n={params:"string"==typeof e?{query:e}:e}),!(e=n instanceof FormData?n.get("query"):n.query||(null===(t=n.params)||void 0===t?void 0:t.query))){var r='There is no "query"!';return salla.product.event.searchFailed(r),this.errorPromise(r)}if(e===salla.api.product.previousQuery){var a="Query is same as previous one!";return salla.product.event.searchFailed(a),salla.api.product.previousQuery=null,this.errorPromise(a)}return salla.api.product.previousQuery=e,this.request("search",n,"get").then((function(t){return salla.product.event.searchResults(t,e),t})).catch((function(t){throw salla.product.event.searchFailed(t,e),t}))}},{key:"offers",value:function(e){var t;if(!(e=this.getPossibleValue((null===(t=e)||void 0===t?void 0:t.data)|e,["product_id","id"]))){var n='There is no "product_id"!';return salla.offer.event.fetchDetailsFailed(n),this.errorPromise(n)}return this.request(["offers",e]).then((function(t){return salla.product.event.offersFetched(t,e),t})).catch((function(t){throw salla.product.event.fetchOffersFailed(t,e),t}))}},{key:"purchaseNow",value:function(e){var t=this;if(salla.config.isGuest())return salla.auth.event.dispatch("login");var n=e.product_data,r=this.getPossibleValue(n,["id","prod_id"]);if(!e.is_applepay)return this.request(["quickPurchase",r],"object"==y(n)?n:void 0).then((function(e){return e})).catch((function(e){throw e}));salla.event.dispatch("payments::apple-pay.start-transaction",{amount:e.total,currency:e.currency,requiredShippingContactFields:e.require_shipping?["postalAddress"]:null,shippingMethods:e.require_shipping?[]:null,supportedNetworks:e.applepay_supported_networks,validateMerchant:{url:baseUrl+"checkout/applepay/validate",onFailed:function(e){e.response,console.log("validateMerchant Failed!")},onSuccess:function(e){return console.log("validateMerchant Success"),t.request(["quickPurchase",r],"object"==y(n)?n:void 0)}},authorized:{url:baseUrl+"/checkout/{id}/payments/submit",onFailed:function(e){console.log("authorized Failed!"),window.Salla.Payments.ApplePay.onCancel({},e.data.error.message)},onSuccess:function(e){console.log(e),window.location.href=e.redirect.url,console.log("authorized Success:: redirect to thank you page, order placed")}},shippingMethodSelected:e.require_shipping?{url:baseUrl+"/checkout/{id}/shipping/details",onFailed:function(e){console.log("select shipping method failed!")},onSuccess:function(e){console.log("select shipping method success")}}:null,shippingContactSelected:e.require_shipping?{url:baseUrl+"/checkout/{id}/address/add",onFailed:function(e){console.log("created contact failed!")},onSuccess:function(e){console.log("created contact success : ",e.data.address_id)}}:null,recalculateTotal:{url:baseUrl+"/checkout/{id}/payments/recalculate"},onError:function(e){console.log(e),salla.notify.error(e)}})}},{key:"getSizeGuides",value:function(e){return this.request("products/".concat(e,"/size-guides"),null,"get").then((function(t){return salla.product.event.sizeGuideFetched(t,e),t})).catch((function(t){throw salla.product.event.sizeGuideFetchFailed(t,e),t}))}},{key:"getGiftDetails",value:function(e){return this.request(["giftDetail",e]).then((function(t){return salla.product.event.giftFetched(t,e),t})).catch((function(t){throw salla.product.event.giftFetchFailed(t,e),t}))}},{key:"addGiftToCart",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.request(["giftToCart",e],t).then((function(t){return salla.product.event.addGiftToCartSucceeded(t,e),n&&(window.location.href=t.redirect),response})).catch((function(t){throw salla.product.event.addGiftToCartFailed(t,e),t}))}},{key:"uploadGiftImage",value:function(e){return this.request("giftImage",e).then((function(e){return salla.product.event.giftImageUploadSucceeded(e),e})).catch((function(e){throw salla.product.event.giftImageUploadFailed(e),e}))}}]),n}(),ce=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="profile",r.endpoints={info:"auth/user",update:"profile/update",updateContacts:"profile/contacts/update",verify:"profile/verify"},r.after_init(),r}return _(n,[{key:"info",value:function(){return this.request("info",null,"get").then((function(e){return salla.profile.event.infoFetched(e),e})).catch((function(e){throw salla.profile.event.infoNotFetched(e),e}))}},{key:"update",value:function(e){return this.request("update",e).then((function(e){return salla.profile.event.updated(e),e})).catch((function(e){throw salla.event.profile.updateFailed(e),e}))}},{key:"updateContacts",value:function(e){return this.request("updateContacts",e).then((function(e){return salla.profile.event.verificationCodeSent(e),e})).catch((function(e){throw salla.event.profile.updateContactsFailed(e),e}))}},{key:"verify",value:function(e){return this.request("verify",e).then((function(e){return salla.profile.event.verified(e),e})).catch((function(e){throw salla.event.profile.unVerified(e),e}))}}]),n}(),ue=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="comment",r.endpoints={add:"{type}/{id}/comments"},r.after_init(),r}return _(n,[{key:"add",value:function(e){var t;null!==(t=e)&&void 0!==t&&t.data&&(e=e.data);var n,r=Object.fromEntries(e),a=r.id,i=r.type,o=r.comment;return a?i&&["products","pages","product","page"].includes(i)?o?(i+=["product","page"].includes(i)?"s":"",this.request(["add",i,a],{comment:o}).then((function(e){return salla.event.comment.added(e,a),e})).catch((function(e){throw salla.event.comment.additionFailed(e,a),e}))):(salla.event.comment.additionFailed(n="can't find comment content!"),this.errorPromise(n)):(salla.event.comment.additionFailed(n="Failed to get type one of:(products, product, page, pages)!"),this.errorPromise(n)):(salla.event.comment.additionFailed(n="Failed to get id!"),this.errorPromise(n))}}]),n}(),de=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="currency",r.endpoints={change:"/",list:"currencies"},r.endpointsMethods={change:"get",list:"get"},r.webEndpoints=["change"],r.after_init(),r}return _(n,[{key:"change",value:function(e){if(!(e=this.getPossibleValue(e.data||e,["currency","code"]))){var t="Can't find currency code!";return salla.currency.event.failed(t),this.errorPromise(t)}return this.request("change",{params:{change_currency:"",currency:e}}).then((function(t){return salla.cookie.set("fresh_summary",1),salla.storage.set("cart",""),salla.currency.event.changed(t,e),t})).catch((function(t){throw salla.currency.event.failed(t,e),t}))}},{key:"list",value:function(){return this.request("list").then((function(e){return salla.currency.event.fetched(e),e})).catch((function(e){throw salla.currency.event.failedToFetch(e),e}))}}]),n}(),he=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="document",r}return _(n)}(),fe=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="rating",r.endpoints={store:"rating/store",products:"rating/products",shipping:"rating/shipping",order:"rating/{order_id}"},r.endpointsMethods={order:"get"},r.after_init(),r}return _(n,[{key:"order",value:function(e){var t="object"===y(e)?e:{},n=this.getPossibleValue((null==e?void 0:e.data)||e,["order_id","id"]);if(!n){var r='There is no "order_id"!';return salla.event.rating.orderNotFetched(r),this.errorPromise(r)}return this.request(["order",n],t).then((function(e){return salla.event.rating.orderFetched(e,n),e})).catch((function(e){throw salla.event.rating.orderNotFetched(e,n),e}))}},{key:"store",value:function(e){if(!(e=e.data||e)){var t='There is no "data"!';return salla.event.rating.storeFailed(t),this.errorPromise(t)}return this.request("store",e).then((function(t){return salla.event.rating.storeRated(t,e),t})).catch((function(t){throw salla.event.rating.storeFailed(t,e),t}))}},{key:"products",value:function(e){if(!(e=e.data||e)){var t='There is no "data"!';return salla.event.rating.productsFailed(t),this.errorPromise(t)}return this.request("products",e).then((function(t){return salla.event.rating.productsRated(t,e),t})).catch((function(t){throw salla.event.rating.productsFailed(t,e),t}))}},{key:"shipping",value:function(e){if(!(e=e.data||e)){var t='There is no "data"!';return salla.event.rating.shippingFailed(t),this.errorPromise(t)}return this.request("shipping",e).then((function(t){return salla.event.rating.shippingRated(t,e),t})).catch((function(t){throw salla.event.rating.shippingFailed(t,e),t}))}}]),n}(),pe=function(){function e(t){var n;if(w(this,e),salla.config.merge(t),t){var r;if(t._token&&(salla.api.defaults.headers.common["X-CSRF-TOKEN"]=t._token),this.injectMaintenanceAlert(),this.injectThemePreviewAlert(),this.injectEditAlert(),null!=t&&null!==(n=t.user)&&void 0!==n&&n.language_code)salla.lang.setLocale(null==t||null===(r=t.user)||void 0===r?void 0:r.language_code);salla.lang.loadStoreTranslations(),salla.twilight.event.initiated(t)}else salla.twilight.event.initiated(t)}return _(e,[{key:"injectMaintenanceAlert",value:function(){salla.config.get("maintenance")&&(document.querySelector(".store-notify")?salla.logger.warn(".store-notify element Existed before!"):salla.lang.onLoaded((function(){var e=document.createElement("div");e.classList.add("store-notify"),e.style="background-color: #d63031; color: #fff; padding: 10px 15px; text-align: center; font-size: 17px;",e.innerHTML='<p style="margin:0 !important;">'.concat(salla.lang.get("blocks.header.maintenance_alert"),"</p>"),document.body.prepend(e)})))}},{key:"injectThemePreviewAlert",value:function(){"preview"===salla.config.get("theme.mode")&&(document.querySelector("#s-theme_preview_bar")?salla.logger.warn("#s-theme_preview_bar element Existed before!"):salla.lang.onLoaded((function(){var e=document.createElement("div");e.id="s-theme_preview_bar",e.setAttribute("style","display: flex; justify-content: space-between; text-align: center; background-color: #232323; color: #fff; padding: 10px; font-size: 0.875rem; line-height: 1.25rem; position: relative;"),e.innerHTML='\n <div style="display:flex; align-items:center;">\n <img width="32" src="https://assets.salla.sa/cp/assets/images/logo-new.png">\n <span style="margin:0 10px;">'.concat(salla.lang.get("blocks.header.preview_mode"),': <span style="background:rgba(255,255,255,0.25);border-radius:15px; padding:2px 15px 4px">').concat(salla.config.get("theme.name"),'</span></span>\n </div>\n <a href="').concat(salla.url.get("preview_theme/cancel/preview"),'" style="line-height:32px; width:32px;"><i class="sicon-cancel"></i></a>\n '),document.body.prepend(e)})))}},{key:"injectEditAlert",value:function(){var e=salla.config.get("edit");e&&(document.querySelector("#s-edit-alert")?salla.logger.warn("#s-edit-alert element Existed before!"):salla.lang.onLoaded((function(){var t=document.createElement("div");t.id="s-edit-alert",t.innerHTML='\n <a href="'.concat(e,'" style="display:block; background-color:').concat(salla.config.get("theme.color.primary","#5cd5c4"),"; color:").concat(salla.config.get("theme.color.reverse","#fff"),'; padding: 10px; text-align:center; font-size: 0.875rem; line-height: 1.25rem;">\n <i class="sicon-edit"></i> \n ').concat(salla.lang.get("pages.products.quick_edit"),"\n </a>\n "),document.body.prepend(t)})))}},{key:"handleElementAjaxRequest",value:function(e,t){var n=this;if(!(t instanceof HTMLFormElement||t instanceof HTMLAnchorElement))return salla.logger.warn("trying to call ajax from non Element!!"),!1;e.preventDefault();var r=t.getAjaxFormData(e),a=r.method?r.method.toLowerCase():void 0;salla.api.document.request(r.url,r.formData,a).then((function(e){return e.data&&e.request&&(e=e.data),salla.api.document.handleAfterResponseActions(e),n.callAjaxEvent(r.events.success,e,r.formData),e})).catch((function(e){throw salla.api.document.handleErrorResponse(e),n.callAjaxEvent(r.events.fail,e,r.formData),e}))}},{key:"callAjaxEvent",value:function(e,t,n){if(e){if(n instanceof FormData){var r={};Array.from(n.entries()).forEach((function(e){r[e[0]]=e[1]})),n=r}window[e]?window[e](t,n):salla.event.dispatch(e,t,n)}}}]),e}(),ve=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="twilight",r.after_init(),r}return _(n,[{key:"init",value:function(e){var t=null==e?void 0:e.events;return salla.isInitiated||(delete e.events,new pe(e),salla.isInitiated=!0),t&&salla.event.dispatchEvents(t),this.successPromise(e)}},{key:"api",value:function(e){var t=null==e?void 0:e.events;return t&&salla.event.dispatchEvents(t),this.successPromise(e)}}]),n}(),ge=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="wishlist",r.endpoints={add:"products/favorites/{id}",remove:"products/favorites/{id}"},r.endpointsMethods={remove:"delete"},r.after_init(),r}return _(n,[{key:"toggle",value:function(e){return salla.storage.get("salla::wishlist",[]).includes(e)?this.remove(e):this.add(e)}},{key:"add",value:function(e){var t,n,r=this;return salla.config.isGuest()?(salla.wishlist.event.additionFailed(n=salla.lang.get("common.messages.must_login")),salla.error(n),this.errorPromise(n)):(e=this.getPossibleValue((null===(t=e)||void 0===t?void 0:t.data)||e,["product_id","id"]))?this.request(["add",e]).then((function(t){return r.updateWishlistStorage(e),salla.wishlist.event.added(t,e),t})).catch((function(t){throw salla.wishlist.event.additionFailed(t,e),t})):(salla.wishlist.event.additionFailed(n="Failed to get product id!"),this.errorPromise(n))}},{key:"remove",value:function(e){var t,n,r=this;return salla.config.isGuest()?(salla.wishlist.event.additionFailed(n=salla.lang.get("common.messages.must_login")),salla.error(n),this.errorPromise(n)):(e=this.getPossibleValue((null===(t=e)||void 0===t?void 0:t.data)||e,["product_id","id"]))?this.request(["remove",e]).then((function(t){return r.updateWishlistStorage(e,!1),salla.wishlist.event.removed(t,e),t})).catch((function(t){throw salla.wishlist.event.removingFailed(t,e),t})):(salla.wishlist.event.removingFailed(n="Failed to get id!"),this.errorPromise(n))}},{key:"updateWishlistStorage",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=salla.storage.get("salla::wishlist",[]);t?n.push(e):n.splice(n.indexOf(e),1),salla.storage.set("salla::wishlist",n)}}]),n}(),ye=function(e){x(n,re);var t=C(n);function n(e){var r;return w(this,n),(r=t.call(this,e)).namespace="scopes",r.endpoints={get:"scopes",change:"scopes",getProductAvailability:"scopes/availability?product_id={id}"},r.after_init(),r}return _(n,[{key:"get",value:function(){return this.request("scopes",null,"get").then((function(e){return salla.scope.event.fetched(e),e})).catch((function(e){throw salla.scope.event.notFetched(e),e}))}},{key:"change",value:function(e){return this.request("scopes",e).then((function(e){return salla.scope.event.changeSucceeded(e),e})).catch((function(e){throw salla.scope.event.changeFailed(e),e}))}},{key:"getProductAvailability",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.request("scopes/availability?product_id=".concat(e),null,"get").then((function(t){return salla.scope.event.productAvailabilityFetched(t,e),t})).catch((function(e){throw salla.scope.event.productAvailabilityNotFetched(e),resp}))}}]),n}(),me=function(){function e(n){var r=this;return w(this,e),n.on("twilight::initiated",(function(){return r.initiateRequest()})),n.on("profile::info.fetched",this.setCurrencyAndLanguage),n.on("auth::token.fetched",(function(e){return r.handleToken(e)})),n.on("document::request.failed",(function(e,t){salla.logger.warn(t,e)})),t.create({headers:{common:{"X-Requested-With":"XMLHttpRequest","S-SOURCE":"twilight","S-APP-VERSION":"v2.0.0","S-APP-OS":"browser"}}})}return _(e,[{key:"initiateRequest",value:function(){salla.api.defaults.baseURL=salla.config.get("store.api",salla.config.get("store.url")),salla.api.defaults.headers.common["Store-Identifier"]=salla.config.get("store.id"),salla.api.defaults.headers.common.currency=salla.config.get("user.currency_code","SAR"),salla.infiniteScroll.fetchOptions.headers["Accept-Language"]=salla.api.defaults.headers.common["accept-language"]=salla.lang.getLocale(),salla.api.defaults.headers.common["s-user-id"]=salla.config.get("user.id");var e=salla.storage.get("scope");e&&(salla.api.defaults.headers.common["s-scope-type"]=e.type,salla.api.defaults.headers.common["s-scope-id"]=e.id),this.injectTokenToTheRequests()}},{key:"injectTokenToTheRequests",value:function(){var e=salla.storage.get("token"),t=salla.config.isGuest(),r=salla.storage.get("cart");if(r&&(r.user_id!==salla.config.get("user.id")||r.store_id!==salla.config.get("store.id")))return salla.log("Auth:: The cart is not belong to current "+(r.user_id!==salla.config.get("user.id")?"user":"store")+"!"),void salla.cart.api.reset();if(!t||e){if(t&&e)return salla.log("Auth:: Token without user!"),salla.storage.remove("token"),void salla.cart.api.reset();if(!e)return salla.cart.api.reset(),void salla.auth.api.refresh();var a=n(e);return Date.now()/1e3>a.exp?(salla.log("Auth:: An expired token!"),salla.storage.remove("token"),salla.cart.api.reset(),void salla.auth.api.refresh()):a.sub!==salla.config.get("user.id")?(salla.log("Auth:: The user id is not match the token details!"),salla.storage.remove("token"),salla.cart.api.reset(),void salla.auth.api.refresh()):void this.setToken(e)}}},{key:"handleToken",value:function(e){salla.storage.set("token",e),this.setToken(e),salla.cart.api.reset()}},{key:"setToken",value:function(e){salla.api.defaults.headers.common.Authorization="Bearer "+e}},{key:"setCurrencyAndLanguage",value:function(e){salla.api.defaults.headers.common.currency=e.data.currency,salla.api.defaults.headers.common["accept-language"]=e.data.language,salla.infiniteScroll.fetchOptions.headers["Accept-Language"]=e.data.language}}]),e}(),be=function(e){x(n,me);var t=C(n);function n(e){var r,a;return w(this,n),(r=t.call(this,e)).apis={auth:new oe(P(r)),cart:new ae(P(r)),loyalty:new ie(P(r)),order:new se(P(r)),rating:new fe(P(r)),product:new le(P(r)),profile:new ce(P(r)),comment:new ue(P(r)),currency:new de(P(r)),document:new he(P(r)),twilight:new ve(P(r)),wishlist:new ge(P(r)),scope:new ye(P(r)),withoutNotifier:(a=b(g().mark((function e(t){return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return salla.config.set("sdk.notifier_handler_disabled",!0),e.next=3,t().finally((function(){salla.config.set("sdk.notifier_handler_disabled",!1)}));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)}))),function(e){return a.apply(this,arguments)})},Object.assign(P(r),r.apis),r.getHeaders=function(){return r.defaults.headers.common},r}return _(n)}(),we=_((function e(t,n){return w(this,e),this.api=t,this.event=n,new Proxy(this,{get:function(e,r){return"event"===r?n:"api"===r&&"twilight"!==(null==t?void 0:t.namespace)?t:t&&t[r]||e[r]}})})),ke=function(e){x(n,we);var t=C(n);function n(e,r){var a;return w(this,n),(a=t.call(this,e,r)).options={path:".infinite-scroll-btn",history:"push",status:".infinite-scroll-status",append:".list-block"},a.fetchOptions={headers:{"S-INFINITE-SCROLL":!0}},a.instances=[],a}return _(n,[{key:"initiate",value:function(e,t,n){n=this.getCustomOptions(t,n);var a="string"!=typeof e?e:document.querySelector(e),i=n.path;if(a&&i&&("string"!=typeof i||document.querySelector(i))){var o=new r(a,n);return o.on("scrollThreshold",salla.infiniteScroll.event.scrollThreshold),o.on("request",salla.infiniteScroll.event.request),o.on("load",salla.infiniteScroll.event.load),o.on("append",salla.infiniteScroll.event.append),o.on("error",salla.infiniteScroll.event.error),o.on("last",salla.infiniteScroll.event.last),o.on("history",salla.infiniteScroll.event.history),this.instances.push(o),o}salla.logger.warn(a?"Path Option (a link that has next page link) Not Existed!":"Container For InfiniteScroll not Existed!")}},{key:"getCustomOptions",value:function(e,t){return(t="object"==y(e)&&e||t||this.options).fetchOptions=this.fetchOptions,t.path=t.path||this.options.path,t.button=t.button||t.path,t.status=t.status||this.options.status,t.hasOwnProperty("history")||(t.history=this.options.history),t.nextPage=t.nextPage||t.next_page,t.append="string"==typeof e&&e||t.append||this.options.append,t}}]),n}();function _e(e,t,n){return e instanceof FormData?e.append(t,n):e[t]=n,e}function Fe(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e+="";for(var n,r=["٠","١","٢","٣","٤","٥","٦","٧","٨","٩"],a=["0","1","2","3","4","5","6","7","8","9"],i=(t=t||!salla.config.get("store.settings.arabic_numbers_enabled"))?r:a,o=t?a:r,s=0;s<i.length;s++)n=new RegExp(i[s],"g"),e=e.replace(n,o[s]);return e}function xe(e){var t=(e.match(/\./g)||[]).length;return t&&1!==t?xe(e.replace(/\.(.+)\./g,".$1")):e}String.prototype.toStudlyCase=function(){return this.trim().replace(/([^a-zA-Z\d].)/g,(function(e){return e.toUpperCase().replace(/[^a-zA-Z\d]/g,"")}))},String.prototype.toDatasetName=function(){return this.startsWith("data-")?this.substr(5).toStudlyCase():this.toStudlyCase()},String.prototype.toSelector=function(){return this.trim().startsWith(".")||this.trim().startsWith("#")?this:"#"+this},String.prototype.replaceArray=function(e,t){for(var n,r=this,a=0;a<e.length;a++)n=new RegExp(e[a],"g"),r=r.replace(n,t[a]);return r},String.prototype.rtrim=function(e){return void 0===e&&(e="\\s"),this.replace(new RegExp("["+e+"]*$"),"")},String.prototype.ltrim=function(e){return void 0===e&&(e="\\s"),this.replace(new RegExp("^["+e+"]*"),"")},String.prototype.digitsOnly=function(){return salla.helpers.digitsOnly(this)},Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){for(var t=this;t;){if(t.matches(e))return t;t=t.parentElement}}),Element.prototype.getElementSallaData=function(e){if(this.getAttribute){if(this.hasAttribute("data-json"))try{return JSON.parse(this.getAttribute("data-json"))}catch(e){}var t=this.getAttribute("data-function");if(t&&window[t]){if("function"==typeof window[t]){for(var n,r=arguments.length,a=new Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];return this.getFilteredData((n=window[t]).call.apply(n,[this].concat(a)))}return this.getFilteredData(window[t])}var o=this.hasAttribute("data-form-selector")?document.querySelector(this.dataset.formSelector):void 0;if((o="FORM"===this.tagName?this:o||this.closest("form")||this.closest("[salla-form-data]")||this)&&"FORM"===o.tagName)return this.getFilteredData(new FormData(o),null,o);var s=o.querySelectorAll("[name]");if(!s.length)return this.getFilteredData();var l=Object.assign({},this.dataset);return s.forEach((function(e){if(!["checkbox","radio"].includes(e.type)||e.checked)try{var t=salla.helpers.inputData(e.name,e.value,l);l[t.name]=t.value}catch(t){salla.log(e.name+" can't be send")}})),this.getFilteredData(l)}},Element.prototype.canEventFireHook=function(e){return!!this.hasAttribute&&this.hasAttribute(salla.api.hooksPrefix+e.type)},Element.prototype.hasAttributeStartsWith=function(e,t){e=e.toLowerCase();for(var n=0;n<this.attributes.length;n++){var r=this.attributes[n].name.toLowerCase();if(0===r.indexOf(e))return!t||r}return!1},HTMLFormElement.prototype.getAjaxFormData=function(e){var t=this.querySelectorAll('input[type="file"]');t.forEach((function(e){e.files.length||e.setAttribute("disabled","")}));var n=new FormData(this);return t.forEach((function(e){e.files.length||e.removeAttribute("disabled")})),{formData:this.getFilteredData(n,e),url:this.getAttribute("action"),method:this.getAttribute("method")||"post",events:{success:this.dataset.onSuccess,fail:this.dataset.onFail}}},Element.prototype.getFilteredData=function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return t=t||(null==r?void 0:r.dataset)||this.dataset,r&&this.name&&void 0!==this.value&&(t=_e(t,this.name,this.value)),["filterBeforeSubmit","filterBeforeSend"].forEach((function(a){var i=(null==r?void 0:r.dataset[a])||e.dataset[a];if(i){var o=window[i];if("function"==typeof o){if(!o(t,r||e,n)&&t)throw"Data failed to be pass verify function window.".concat(i,"(formData, element, event)!");return o(t,r||e,n)}salla.log("window."+i+"() not found!")}})),t},HTMLAnchorElement.prototype.getAjaxFormData=function(e){return{formData:this.getFilteredData(null,e),url:this.getAttribute("href"),method:this.dataset.type||"get",events:{success:this.dataset.onSuccess,fail:this.dataset.onFail}}};var Se="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},Ae=Array.isArray,Ee="object"==y(Se)&&Se&&Se.Object===Object&&Se,Oe="object"==("undefined"==typeof self?"undefined":y(self))&&self&&self.Object===Object&&self,Pe=Ee||Oe||Function("return this")(),je=Pe.Symbol,Ce=je,qe=Object.prototype,Le=qe.hasOwnProperty,Te=qe.toString,Ie=Ce?Ce.toStringTag:void 0;var De=function(e){var t=Le.call(e,Ie),n=e[Ie];try{e[Ie]=void 0;var r=!0}catch(e){}var a=Te.call(e);return r&&(t?e[Ie]=n:delete e[Ie]),a},Ne=Object.prototype.toString;var Re=De,Ue=function(e){return Ne.call(e)},Me=je?je.toStringTag:void 0;var ze=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Me&&Me in Object(e)?Re(e):Ue(e)};var Ge=ze,Ve=function(e){return null!=e&&"object"==y(e)};var $e=function(e){return"symbol"==y(e)||Ve(e)&&"[object Symbol]"==Ge(e)},He=Ae,We=$e,Be=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ze=/^\w*$/;var Qe=function(e,t){if(He(e))return!1;var n=y(e);return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!We(e))||(Ze.test(e)||!Be.test(e)||null!=t&&e in Object(t))};var Je=function(e){var t=y(e);return null!=e&&("object"==t||"function"==t)},Ke=ze,Xe=Je;var Ye,et=function(e){if(!Xe(e))return!1;var t=Ke(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t},tt=Pe["__core-js_shared__"],nt=(Ye=/[^.]+$/.exec(tt&&tt.keys&&tt.keys.IE_PROTO||""))?"Symbol(src)_1."+Ye:"";var rt=function(e){return!!nt&&nt in e},at=Function.prototype.toString;var it=et,ot=rt,st=Je,lt=function(e){if(null!=e){try{return at.call(e)}catch(e){}try{return e+""}catch(e){}}return""},ct=/^\[object .+?Constructor\]$/,ut=Function.prototype,dt=Object.prototype,ht=ut.toString,ft=dt.hasOwnProperty,pt=RegExp("^"+ht.call(ft).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var vt=function(e){return!(!st(e)||ot(e))&&(it(e)?pt:ct).test(lt(e))},gt=function(e,t){return null==e?void 0:e[t]};var yt=function(e,t){var n=gt(e,t);return vt(n)?n:void 0},mt=yt(Object,"create"),bt=mt;var wt=function(){this.__data__=bt?bt(null):{},this.size=0};var kt=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},_t=mt,Ft=Object.prototype.hasOwnProperty;var xt=function(e){var t=this.__data__;if(_t){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return Ft.call(t,e)?t[e]:void 0},St=mt,At=Object.prototype.hasOwnProperty;var Et=mt;var Ot=wt,Pt=kt,jt=xt,Ct=function(e){var t=this.__data__;return St?void 0!==t[e]:At.call(t,e)},qt=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Et&&void 0===t?"__lodash_hash_undefined__":t,this};function Lt(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Lt.prototype.clear=Ot,Lt.prototype.delete=Pt,Lt.prototype.get=jt,Lt.prototype.has=Ct,Lt.prototype.set=qt;var Tt=Lt;var It=function(){this.__data__=[],this.size=0};var Dt=function(e,t){return e===t||e!=e&&t!=t};var Nt=function(e,t){for(var n=e.length;n--;)if(Dt(e[n][0],t))return n;return-1},Rt=Nt,Ut=Array.prototype.splice;var Mt=Nt;var zt=Nt;var Gt=Nt;var Vt=It,$t=function(e){var t=this.__data__,n=Rt(t,e);return!(n<0)&&(n==t.length-1?t.pop():Ut.call(t,n,1),--this.size,!0)},Ht=function(e){var t=this.__data__,n=Mt(t,e);return n<0?void 0:t[n][1]},Wt=function(e){return zt(this.__data__,e)>-1},Bt=function(e,t){var n=this.__data__,r=Gt(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};function Zt(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Zt.prototype.clear=Vt,Zt.prototype.delete=$t,Zt.prototype.get=Ht,Zt.prototype.has=Wt,Zt.prototype.set=Bt;var Qt=Zt,Jt=yt(Pe,"Map"),Kt=Tt,Xt=Qt,Yt=Jt;var en=function(e){var t=y(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};var tn=function(e,t){var n=e.__data__;return en(t)?n["string"==typeof t?"string":"hash"]:n.map},nn=tn;var rn=tn;var an=tn;var on=tn;var sn=function(){this.size=0,this.__data__={hash:new Kt,map:new(Yt||Xt),string:new Kt}},ln=function(e){var t=nn(this,e).delete(e);return this.size-=t?1:0,t},cn=function(e){return rn(this,e).get(e)},un=function(e){return an(this,e).has(e)},dn=function(e,t){var n=on(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this};function hn(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}hn.prototype.clear=sn,hn.prototype.delete=ln,hn.prototype.get=cn,hn.prototype.has=un,hn.prototype.set=dn;var fn=hn;function pn(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function n(){var r=arguments,a=t?t.apply(this,r):r[0],i=n.cache;if(i.has(a))return i.get(a);var o=e.apply(this,r);return n.cache=i.set(a,o)||i,o};return n.cache=new(pn.Cache||fn),n}pn.Cache=fn;var vn=pn;var gn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,yn=/\\(\\)?/g,mn=function(e){var t=vn(e,(function(e){return 500===n.size&&n.clear(),e})),n=t.cache;return t}((function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(gn,(function(e,n,r,a){t.push(r?a.replace(yn,"$1"):n||e)})),t})),bn=mn;var wn=function(e,t){for(var n=-1,r=null==e?0:e.length,a=Array(r);++n<r;)a[n]=t(e[n],n,e);return a},kn=Ae,_n=$e,Fn=je?je.prototype:void 0,xn=Fn?Fn.toString:void 0;var Sn=function e(t){if("string"==typeof t)return t;if(kn(t))return wn(t,e)+"";if(_n(t))return xn?xn.call(t):"";var n=t+"";return"0"==n&&1/t==-Infinity?"-0":n},An=Sn;var En=Ae,On=Qe,Pn=bn,jn=function(e){return null==e?"":An(e)};var Cn=$e;var qn=function(e,t){return En(e)?e:On(e,t)?[e]:Pn(jn(e))},Ln=function(e){if("string"==typeof e||Cn(e))return e;var t=e+"";return"0"==t&&1/e==-Infinity?"-0":t};var Tn=function(e,t){for(var n=0,r=(t=qn(t,e)).length;null!=e&&n<r;)e=e[Ln(t[n++])];return n&&n==r?e:void 0};var In=function(e,t,n){var r=null==e?void 0:Tn(e,t);return void 0===r?n:r};function Dn(e,t,n){var r=e[0];return n&&0==e.length?Array.isArray(n)?(n.push(t),n):[n,t]:Array.isArray(n)?(n.push(t),n):"string"==typeof n?[n,t]:n?(n[r]=Dn(e.slice(1),t,n[r]),n):r?F({},r,Dn(e.slice(1),t)):""===r?[t]:t}function Nn(e){return salla.config.get("store.url",window.location.href.split("/").slice(0,-1).join("/")).rtrim("/")+"/"+e.ltrim("/")}window.onbeforeunload=function(e){if(salla.document.event.leaving(e),!salla.config.get("canLeave"))return e.preventDefault(),!1};var Rn={digitsOnly:function(e){return Fe(e,!0).replace(/[^0-9.]/g,"").replace("..",".").rtrim(".")},inputDigitsOnly:function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if("string"==typeof t)return document.querySelectorAll(t).forEach((function(t){return e(t,n)}));if(t){var r=salla.helpers.digitsOnly(t.value);return t.min&&r<t.min?t.value=t.min:t.max&&r>t.max?t.value=t.max:t.maxLength>=1&&r.toString().length>t.maxLength?t.value=r.toString().substring(0,t.maxLength):t.value=n||t.dataset.hasOwnProperty("digitsWithDecimal")?xe(r):r.replace(/\D/g,"")}salla.logger.warn("Can't find Object With Id: "+t)},number:Fe,money:function(e){return Fe((null==e?void 0:e.amount)|e)+" "+salla.config.currency(null==e?void 0:e.currency).symbol},setNested:function(e,t,n){for(var r=e,a=t.split("."),i=a.length,o=0;o<i-1;o++){var s=a[o];r[s]||(r[s]={}),r=r[s]}return r[a[i-1]]=n,e},getNested:function(e,t,n){var r=In(e,t);return void 0!==r?r:n},inputData:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e.includes("[")){var r=e.split("]").join("").split("[");return{name:r[0],value:Dn(r.slice(1),t,n[r[0]])}}return{name:e,value:t}},url:{get:Nn,asset:function(e){return function(e){return window.location.origin+"/"+e.ltrim("/")}("themes/"+salla.config.get("theme.name")+"/"+e.ltrim("/"))},cdn:function(e){return"https://cdn.salla.network/"+e.ltrim("/")},is_page:function(e){return e&&salla.config.get("page.slug")===e},api:function(e){return salla.config.get("store.api",Nn("")).rtrim("/")+"/"+e.ltrim("/")}},addParamToUrl:function(e,t){if(!t||!e)return window.location.href;var n=new RegExp("([?&])"+e+"=[^&]+[&]?","g"),r=window.location.href.replace(n,"$1").replace(/&$|\?$/,"");return(r+=(r.includes("?")?"&":"?")+e+"="+encodeURIComponent(t)).replace(/&$|\?$/,"")},debounce:function(e,t){t=t||100;var n,r=[];return function(){for(var a=arguments.length,i=new Array(a),o=0;o<a;o++)i[o]=arguments[o];return clearTimeout(n),n=setTimeout((function(){var t=e.apply(void 0,i);r.forEach((function(e){return e(t)})),r=[]}),t),new Promise((function(e){return r.push(e)}))}}},Un=function(){function e(){w(this,e)}return _(e,[{key:"toggleClassIf",value:function(e,t,n,r){var a=this;return document.querySelectorAll(e).forEach((function(e){return a.toggleElementClassIf(e,t,n,r)})),this}},{key:"toggleElementClassIf",value:function(e,t,n,r){var a,i;t=Array.isArray(t)?t:t.split(" "),n=Array.isArray(n)?n:n.split(" ");var o=r(e);return null==e||(a=e.classList).remove.apply(a,I(o?n:t)),null==e||(i=e.classList).add.apply(i,I(o?t:n)),this}},{key:"isValidEmail",value:function(e){return/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(e).toLowerCase())}},{key:"element",value:function(e){return"object"==y(e)?e:document.querySelector(e)}},{key:"watchElement",value:function(e,t){return this[e]=this.element(t),this}},{key:"watchElements",value:function(e){var t=this;return Object.entries(e).forEach((function(e){return t.watchElement(e[0],e[1])})),this}},{key:"on",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return"object"==y(t)?(this.element(t).addEventListener(e,n,r),this):(document.querySelectorAll(t).forEach((function(t){return t.addEventListener(e,n,r)})),this)}},{key:"onClick",value:function(e,t){return this.on("click",e,t)}},{key:"onKeyUp",value:function(e,t){return this.on("keyup",e,t)}},{key:"onEnter",value:function(e,t){return this.onKeyUp(e,(function(e){return 13===e.keyCode&&t(e)})),this}},{key:"all",value:function(e,t){return document.querySelectorAll(e).forEach(t),this}},{key:"hideElement",value:function(e){return this.element(e).style.display="none",this}},{key:"showElement",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"block";return this.element(e).style.display=t,this}},{key:"removeClass",value:function(e,t){var n;return(n=this.element(e).classList).remove.apply(n,I(Array.from(arguments).slice(1))),this}},{key:"addClass",value:function(e,t){var n;return(n=this.element(e).classList).add.apply(n,I(Array.from(arguments).slice(1))),this}},{key:"debounce",value:function(e){this.debounce_||(this.debounce_=salla.helpers.debounce((function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return e.apply(void 0,n)}),500));for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return this.debounce_.apply(this,[e].concat(n))}}]),e}(),Mn=function(){function e(){w(this,e)}var t;return _(e,[{key:"submit",value:(t=b(g().mark((function e(t){var n,r,a,i,o,s,l,c,u=arguments;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=u.length>1&&void 0!==u[1]?u[1]:null,a=r,"SubmitEvent"!==(null==r||null===(n=r.constructor)||void 0===n?void 0:n.name)){e.next=10;break}if(r.preventDefault(),"FORM"===(null===(i=r.target)||void 0===i?void 0:i.tagName)){e.next=7;break}return salla.logger.warn("Failed find the target element for submit action. make sure you submit a form element"),e.abrupt("return",new Promise((function(){throw"Failed find the target element for submit action. make sure you submit a form element"})));case 7:"SALLA-BUTTON"===(null==r||null===(o=r.submitter)||void 0===o||null===(s=o.parentElement)||void 0===s?void 0:s.tagName)&&r.submitter.parentElement.load(),a=r.target.getElementSallaData(),salla.log("Data from element",a);case 10:if(!/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/gm.test(t)){e.next=12;break}return e.abrupt("return",salla.twilight.request(t,a,"post").finally((function(){var e;loaderSupported&&(null==r||null===(e=r.submitter)||void 0===e||e.parentElement.stop())})));case 12:return l=t.split("."),c=l.splice(-1),e.next=16,salla.call(l.join("."))[c](a).finally((function(){var e,t;return null==r||null===(e=r.submitter)||void 0===e||null===(t=e.parentElement)||void 0===t?void 0:t.stop()})).catch((function(e){throw salla.logger.warn(e),e}));case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"onSubmit",value:function(e,t){return salla.form.submit(e,t),!1}},{key:"onChange",value:function(e,t){var n;return null!=t&&t.currentTarget?"FORM"!==(null==t||null===(n=t.currentTarget)||void 0===n?void 0:n.tagName)||t.currentTarget.checkValidity()?(salla.form.submit(e,t.currentTarget.getElementSallaData()),!0):(salla.logger.warn("Trying to trigger '".concat(e,"' without filling required fields!")),!1):(salla.logger.warn("Trying to trigger '".concat(e,"' without event!")),!1)}}]),e}(),zn=function(){function e(t){var n=this;w(this,e),t.on("cookies::remove",(function(e){return n.remove(e)})),t.on("cookies::add",(function(e,t){return n.set(e,t)}))}return _(e,[{key:"get",value:function(e){var t;return null===(t=document.cookie.split("; ").find((function(t){return t.startsWith(e+"=")})))||void 0===t?void 0:t.split("=")[1]}},{key:"set",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,r="";if(n){var a=new Date;a.setTime(a.getTime()+24*n*60*60*1e3),r="; expires="+a.toUTCString()}return document.cookie="".concat(e,"=").concat(t).concat(r,'"; path=/; secure; SameSite=Lax"'),this}},{key:"remove",value:function(e){return document.cookie="".concat(e,"=; Max-Age=0; path=/;"),this}}]),e}(),Gn=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w(this,e),this.triedToGetCurrencies_=!1,this.languages_=[],this.triedToGetLanguages_=!1,this.currencies_={},this.default_properties={debug:"undefined"!=typeof process&&"development"===process.env.NODE_ENV,token:null,fastRequests:!0,canLeave:!0,store:{api:"https://api.salla.dev/store/v1/"},currencies:{SAR:{code:"SAR",name:"ريال سعودي",symbol:"ر.س",amount:1,country_code:"sa"}}},this.properties_=v(v({},this.default_properties),t)}var t,n;return _(e,[{key:"merge",value:function(e){return Object.assign(this.properties_,e),this.properties_.store=v(v({},this.default_properties.store),this.properties_.store),this}},{key:"set",value:function(e,t){return e.includes(".")?(salla.helpers.setNested(this.properties_,e,t),this):(this.properties_[e]=t,this)}},{key:"get",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return e.includes(".")?salla.helpers.getNested(this.properties_,e,t):this.properties_.hasOwnProperty(e)?this.properties_[e]||t:t||void 0}},{key:"isUser",value:function(){return"user"===this.get("user.type")}},{key:"isGuest",value:function(){return!this.isUser()}},{key:"languages",value:(n=b(g().mark((function e(){var t,n,r,a=this;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.triedToGetLanguages_){e.next=2;break}return e.abrupt("return",this.languages_);case 2:return this.triedToGetLanguages_=!0,r=!0,e.next=6,salla.document.api.request("languages",null,"get");case 6:if(e.t1=t=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===t;case 10:if(!e.t0){e.next=14;break}e.next=15;break;case 14:null===(n=t.data)||void 0===n||n.map((function(e){r&&(a.languages_=[],r=!1),e.code=e.code||e.iso_code,e.url=salla.url.get(e.code),e.is_rtl=e.is_rtl||e.rtl,a.languages_.push(e)}));case 15:return this.set("languages",this.languages_),e.abrupt("return",this.languages_);case 17:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"currencies",value:(t=b(g().mark((function e(){var t,n,r,a=this;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.triedToGetCurrencies_){e.next=2;break}return e.abrupt("return",this.currencies_);case 2:return this.triedToGetCurrencies_=!0,r=!0,e.next=6,salla.currency.api.list();case 6:if(e.t1=t=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===t;case 10:if(!e.t0){e.next=14;break}e.next=15;break;case 14:null===(n=t.data)||void 0===n||n.map((function(e){r&&(a.currencies_={},r=!1),e.country_code=e.code.substr(0,2).toLowerCase(),a.currencies_[e.code]=e}));case 15:return this.set("currencies",this.currencies_),e.abrupt("return",this.currencies_);case 17:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"currency",value:function(e){return e=e||this.get("user.currency_code"),this.get("currencies."+e)||Object.values(this.get("currencies"))[0]}}]),e}(),Vn=function(e){x(n,a);var t=C(n);function n(e){var r;return w(this,n),(e=e||{}).messages=e.messages||window.translations,e.locale=e.locale||(window.locale||navigator.language||navigator.userLanguage||"ar").split("-")[0],e.fallback=e.fallback||e.locale,(r=t.call(this,e)).translationsLoaded=!1,r}return _(n,[{key:"onLoaded",value:function(e){if(this.translationsLoaded)return e();salla.event.once("languages::translations.loaded",e)}},{key:"loadStoreTranslations",value:function(){if(this.messages)window.addEventListener("load",(function(e){salla.event.dispatch("languages::translations.loaded"),salla.logger.info("The messages of transactions is already loaded")}));else if(salla.url.get("")){var e=salla.config.get("theme.translations_hash",salla.config.get("store.id","twilight"));this.loadScript(salla.url.get("languages/assets/".concat(e,".js")))}else this.loadScript("https://cdn.salla.network/js/translations.js",!1)}},{key:"setMessages",value:function(e){L(S(n.prototype),"setMessages",this).call(this,e),salla.event.dispatch("languages::translations.loaded"),this.translationsLoaded=!0}},{key:"loadScript",value:function(e){var t=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=document.createElement("script");r.src=e,r.onload=function(){return window.translations?t.setMessages(window.translations):n?(salla.logger.info("Failed to load Translations for store, lets try load it from cdn"),t.loadScript("https://cdn.salla.network/js/translations.js",!1)):void salla.logger.warn("Failed to load Translations from the cdn\nor: salla.lang.setMessages({....}), see https://docs.salla.dev for more information's.")},document.head.appendChild(r)}},{key:"get",value:function(e,t,r){return window.translations&&(e="trans."+e),L(S(n.prototype),"get",this).call(this,e,t,r)}},{key:"set",value:function(e,t){return salla.helpers.setNested(this.messages[this.getLocale()+".trans"],e,t),this}}]),n}(),$n=i.createStore([o,s,l,c],[]),Hn=function(){function e(t){var n=this;w(this,e),t.on("storage::item.remove",(function(e){return n.remove(e)})),t.on("storage::item.set",(function(e,t){return n.set(e,t)})),this.store=$n}return _(e,[{key:"set",value:function(e,t){if(e.includes(".")){var n=e.split(".")[0],r=F({},n,$n.get(n));return r=salla.helpers.setNested(r,e,t),$n.set(n,r[n])}return $n.set(e,t)}},{key:"remove",value:function(e){return $n.remove(e)}},{key:"get",value:function(e,t){if(e.includes(".")){var n=e.split(".")[0];return salla.helpers.getNested(F({},n,$n.get(n)),e)}return $n.get(e,t)}}]),e}(),Wn=new ne,Bn=new be(Wn);window.Salla=window.salla={notify:f,api:Bn,event:Wn,helpers:Rn,config:new Gn,storage:new Hn(Wn),cookie:new zn(Wn),lang:new Vn,form:new Mn,cart:new we(Bn.cart,Wn.cart),auth:new we(Bn.auth,Wn.auth),gift:new we(Bn.gift,Wn.gift),order:new we(Bn.order,Wn.order),scope:new we(Bn.scope,Wn.scope),rating:new we(Bn.rating,Wn.rating),comment:new we(Bn.comment,Wn.comment),loyalty:new we(Bn.loyalty,Wn.loyalty),product:new we(Bn.product,Wn.product),profile:new we(Bn.profile,Wn.profile),currency:new we(Bn.currency,Wn.currency),document:new we(Bn.document,Wn.document),twilight:new we(Bn.twilight,Wn.twilight),wishlist:new we(Bn.wishlist,Wn.wishlist),logger:M,log:M.log,success:f.success,error:f.error,onReady:function(e){return salla.isInitiated?e():salla.event.once("twilight::initiated",e)},isInitiated:!1,AppHelpers:Un,infiniteScroll:new ke(void 0,Wn.infiniteScroll),money:Rn.money,url:Rn.url,init:function(e){return Bn.twilight.init(e)},call:function(e){for(var t=salla,n=e.split(".");n.length&&(t=t[n.shift()]););return t}};var Zn=salla;export{Zn as default};
4
4
  //# sourceMappingURL=index.js.map