!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e=Object.prototype.hasOwnProperty,t="~";function n(){}function r(){}function s(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,n,r,o,c){if("function"!=typeof r)throw new TypeError("The listener must be a function");var i=new s(r,o||e,c),a=t?t+n:n;if(Array.isArray(e._caches[a])&&e._caches[a].length){var h=e._caches[a];if(c){if(h[0])try{i.fn.apply(e,h[0])}catch(e){console.error(e),window.__SL_Track__.error("Shopline.event",{error:{eventName:a,message:null==e?void 0:e.message,stack:null==e?void 0:e.stack}})}return e}Array.isArray(h)&&h.forEach((function(t){try{i.fn.apply(e,t)}catch(e){console.error(e),window.__SL_Track__.error("Shopline.event",{error:{eventName:a,message:null==e?void 0:e.message,stack:null==e?void 0:e.stack}})}}))}return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],i]:e._events[a].push(i):(e._events[a]=i,e._eventsCount++),e}function c(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function i(){this._events=new n,this._eventsCount=0,this._caches=new r}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(t=!1)),Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(t=!1)),i.prototype.eventNames=function(){var n,r,s=[];if(0===this._eventsCount)return s;for(r in n=this._events)e.call(n,r)&&s.push(t?r.slice(1):r);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(n)):s},i.prototype.listeners=function(e){var n=this._events[t?t+e:e];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,s=n.length,o=Array(s);s>r;r++)o[r]=n[r].fn;return o},i.prototype.listenerCount=function(e){var n=this._events[t?t+e:e];return n?n.fn?1:n.length:0},i.prototype.emit=function(e,n,r,s,o,c){var i=t?t+e:e;switch(this._caches[i]||(this._caches[i]=[]),f=arguments.length){case 1:this._caches[i].push([]);break;case 2:this._caches[i].push([n]);break;case 3:this._caches[i].push([n,r]);break;case 4:this._caches[i].push([n,r,s]);break;case 5:this._caches[i].push([n,r,s,o]);break;case 6:this._caches[i].push([n,r,s,o,c])}if(!this._events[i])return!1;var a,h,l=this._events[i],f=arguments.length;if(l.fn){l.once&&this.removeListener(e,l.fn,void 0,!0);try{switch(f){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,n),!0;case 3:return l.fn.call(l.context,n,r),!0;case 4:return l.fn.call(l.context,n,r,s),!0;case 5:return l.fn.call(l.context,n,r,s,o),!0;case 6:return l.fn.call(l.context,n,r,s,o,c),!0}for(h=1,a=Array(f-1);f>h;h++)a[h-1]=arguments[h];l.fn.apply(l.context,a)}catch(e){console.error(e),window.__SL_Track__.error("Shopline.event",{error:{eventName:i,message:null==e?void 0:e.message,stack:null==e?void 0:e.stack}})}}else{var u,_=l.length;for(h=0;_>h;h++){l[h].once&&this.removeListener(e,l[h].fn,void 0,!0);try{switch(f){case 1:l[h].fn.call(l[h].context);break;case 2:l[h].fn.call(l[h].context,n);break;case 3:l[h].fn.call(l[h].context,n,r);break;case 4:l[h].fn.call(l[h].context,n,r,s);break;default:if(!a)for(u=1,a=Array(f-1);f>u;u++)a[u-1]=arguments[u];l[h].fn.apply(l[h].context,a)}}catch(e){console.error(e),window.__SL_Track__.error("Shopline.event",{error:{eventName:i,message:null==e?void 0:e.message,stack:null==e?void 0:e.stack}})}}}return!0},i.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},i.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},i.prototype.removeListener=function(e,n,r,s){var o=t?t+e:e;if(this._caches[o]&&!n&&delete this._caches[o],!this._events[o])return this;if(!n)return c(this,o),this;var i=this._events[o];if(i.fn)i.fn!==n||s&&!i.once||r&&i.context!==r||c(this,o);else{for(var a=0,h=[],l=i.length;l>a;a++)(i[a].fn!==n||s&&!i[a].once||r&&i[a].context!==r)&&h.push(i[a]);h.length?this._events[o]=1===h.length?h[0]:h:c(this,o)}return this},i.prototype.removeAllListeners=function(e){var r;return e?this._events[r=t?t+e:e]&&c(this,r):(this._events=new n,this._eventsCount=0),this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prefixed=t,i.EventEmitter=i,"undefined"!=typeof module&&(module.exports=i),window.Shopline.event||(window.Shopline.event=new i)}));