"use strict";function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest()}function _nonIterableRest(){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 _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r}finally{try{if(!f&&null!=t.return&&(u=t.return(),Object(u)!==u))return}finally{if(o)throw n}}return a}}function _arrayWithHoles(r){if(Array.isArray(r))return r}function _typeof(o){"@babel/helpers - typeof";return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o})(o)}affiliatewp.attach("modal",{instance:null,contents:[],supportedContents:["image","video","html","ajax"],settings:{enableHashNavigation:!0,draggable:!0,showThumbs:!0,slug:"",startIndex:0,groupAttr:"data-grouped",groupAll:!1,autoFocus:!0,dragToClose:!0,idle:3500,parentEl:null,keyboard:{Escape:"close",Delete:"close",Backspace:"close",PageUp:"next",PageDown:"prev",ArrowUp:"prev",ArrowDown:"next",ArrowRight:"next",ArrowLeft:"prev"}},eventQueue:{},show:function(){var contents=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],settings=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.updateSettings(settings),this.setContents(contents),this.instance&&_typeof(this.instance.hasOwnProperty("destroy"))&&(this.instance.destroy(),this.instance=null),this.initializeModal(),this.initializeCustomEvents(),this},bind:function(selectorOrElement,filterSelectorOrSettings){var settings=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},events={on:this.getEventsObject()};if((1===arguments.length||2===arguments.length&&"object"===_typeof(filterSelectorOrSettings))&&"string"!=typeof selectorOrElement)throw new Error("AffiliateWPModal.bind: Expected string as the first argument, got ".concat(_typeof(selectorOrElement)));if(arguments.length>=2&&"string"==typeof filterSelectorOrSettings&&!(selectorOrElement instanceof Element))throw new Error("AffiliateWPModal.bind: Expected Element as the first argument, got ".concat(_typeof(selectorOrElement)));if(arguments.length>=2&&selectorOrElement instanceof Element&&"string"!=typeof filterSelectorOrSettings)throw new Error("AffiliateWPModal.bind: Expected string as the second argument, got ".concat(_typeof(filterSelectorOrSettings)));return 1===arguments.length?(Fancybox.bind(selectorOrElement,events),this):2===arguments.length&&"object"===_typeof(filterSelectorOrSettings)?(Fancybox.bind(selectorOrElement,affiliatewp.parseArgs(this.parseSettings(filterSelectorOrSettings),events)),this):2===arguments.length&&"string"==typeof filterSelectorOrSettings?(Fancybox.bind(selectorOrElement,filterSelectorOrSettings,events),this):arguments.length>=3?(Fancybox.bind(selectorOrElement,filterSelectorOrSettings,affiliatewp.parseArgs(this.parseSettings(settings),events)),this):this},maybeStartFromHash:function(){var HashPlugin=Fancybox.Plugins.Hash;if(HashPlugin&&!this.instance){var _HashPlugin$parseURL=HashPlugin.parseURL(),hash=_HashPlugin$parseURL.hash,slug=_HashPlugin$parseURL.slug,index=_HashPlugin$parseURL.index;if(hash&&slug===this.settings.slug)return this.settings.startIndex=index-1,void this.show();var slideIndex=this.contents.findIndex(function(slide){return slide.slug===slug});hash&&slideIndex>-1&&(this.settings.startIndex=slideIndex,this.show())}},setContents:function(){var _this=this,contents=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(!Array.isArray(contents))throw new Error("Contents must be an array of objects.");return contents=contents.filter(function(item,index){return item.hasOwnProperty("src")?!(!item.hasOwnProperty("type")||!_this.supportedContents.includes(item.type))||(console.error("Modal invalid type for item index ".concat(index,". Ignoring item...")),!1):(console.error("Modal src not found for item index ".concat(index,". Ignoring item...")),!1)}),this.contents=contents,this},updateSettings:function(settings){var _this2=this;if("object"!==_typeof(settings))throw new Error("Settings must be an object.");return Object.entries(this.parseSettings(settings)).forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),key=_ref2[0],value=_ref2[1];_this2.settings[key]=value}),this},parseSettings:function(settings){var settingsMap={enableHashNavigation:{type:"boolean",fancyboxName:"Hash",defaultValueOnTrue:!0,defaultValueOnFalse:!1},showThumbs:{type:"boolean",fancyboxName:"Thumbs",defaultValueOnTrue:!0,defaultValueOnFalse:!1},draggable:{type:"boolean",fancyboxName:"Carousel",defaultValueOnTrue:null,defaultValueOnFalse:{Panzoom:{touch:!1}}}};return Object.entries(settings).reduce(function(result,_ref3){var _ref4=_slicedToArray(_ref3,2),settingName=_ref4[0],settingValue=_ref4[1];if(settingsMap.hasOwnProperty(settingName)){var settingOptions=settingsMap[settingName];"boolean"===settingOptions.type&&settingValue===!0&&null!==settingOptions.defaultValueOnTrue&&(result[settingOptions.fancyboxName]=settingOptions.defaultValueOnTrue),"boolean"===settingOptions.type&&settingValue===!1&&null!==settingOptions.defaultValueOnFalse&&(result[settingOptions.fancyboxName]=settingOptions.defaultValueOnFalse)}return result[settingName]=settingValue,result},{})},onInit:function(callback){return this.addToEventQueue("init",callback),this},onDone:function(callback){return this.addToEventQueue("done",callback),this},onLoading:function(callback){return this.addToEventQueue("loading",callback),this},onClose:function(callback){return this.addToEventQueue("close",callback),this},initializeModal:function(){Array.isArray(this.contents)&&this.contents.length&&(this.instance=new Fancybox(this.contents,this.settings))},getCustomEvents:function(){return{close:"onClose",init:"onInit",done:"onDone",loading:"onLoading"}},initializeCustomEvents:function(){var _this3=this;null!==this.instance&&Object.entries(this.getEventsObject()).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),eventName=_ref6[0],callback=_ref6[1];_this3.instance.on(eventName,callback)})},getEventsObject:function(){var _this4=this,customEvents=this.getCustomEvents(),events={};return Object.entries(customEvents).forEach(function(_ref7){var _ref8=_slicedToArray(_ref7,2),eventName=_ref8[0],methodName=_ref8[1];"function"==typeof _this4[methodName]&&(events[eventName]=function(){_this4.executeEventQueue(eventName)})}),events},addToEventQueue:function(eventName,callback){this.eventQueue[eventName]||(this.eventQueue[eventName]=[]),this.eventQueue[eventName].push(callback)},executeEventQueue:function(eventName){var callbacks=this.eventQueue.hasOwnProperty(eventName)?this.eventQueue[eventName]:[];Array.isArray(callbacks)&&callbacks.forEach(function(callback){"function"==typeof callback&&callback()})}});