(()=>{"use strict";class e{static ucFirst(e){return e.charAt(0).toUpperCase()+e.slice(1)}static lcFirst(e){return e.charAt(0).toLowerCase()+e.slice(1)}static toDashCase(e){return e.replace(/([A-Z])/g,"-$1").replace(/^-/,"").toLowerCase()}static toLowerCamelCase(t,r){let s=e.toUpperCamelCase(t,r);return e.lcFirst(s)}static toUpperCamelCase(t,r){return r?t.split(r).map(t=>e.ucFirst(t.toLowerCase())).join(""):e.ucFirst(t.toLowerCase())}static parsePrimitive(e){try{return/^\d+(.|,)\d+$/.test(e)&&(e=e.replace(",",".")),JSON.parse(e)}catch(t){return e.toString()}}}class t{static isNode(e){return"object"==typeof e&&null!==e&&(e===document||e===window||e instanceof Node)}static hasAttribute(e,r){if(!t.isNode(e))throw Error("The element must be a valid HTML Node!");return"function"==typeof e.hasAttribute&&e.hasAttribute(r)}static getAttribute(e,r){let s=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(s&&!1===t.hasAttribute(e,r))throw Error('The required property "'.concat(r,'" does not exist!'));if("function"!=typeof e.getAttribute){if(s)throw Error("This node doesn't support the getAttribute function!");return}return e.getAttribute(r)}static getDataAttribute(r,s){let i=!(arguments.length>2)||void 0===arguments[2]||arguments[2],o=s.replace(/^data(|-)/,""),n=e.toLowerCamelCase(o,"-");if(!t.isNode(r)){if(i)throw Error("The passed node is not a valid HTML Node!");return}if(void 0===r.dataset){if(i)throw Error("This node doesn't support the dataset attribute!");return}let l=r.dataset[n];if(void 0===l){if(i)throw Error('The required data attribute "'.concat(s,'" does not exist on ').concat(r,"!"));return l}return e.parsePrimitive(l)}static querySelector(e,r){let s=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(s&&!t.isNode(e))throw Error("The parent node is not a valid HTML Node!");let i=e.querySelector(r)||!1;if(s&&!1===i)throw Error('The required element "'.concat(r,'" does not exist in parent node!'));return i}static querySelectorAll(e,r){let s=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(s&&!t.isNode(e))throw Error("The parent node is not a valid HTML Node!");let i=e.querySelectorAll(r);if(0===i.length&&(i=!1),s&&!1===i)throw Error('At least one item of "'.concat(r,'" must exist in parent node!'));return i}}class r{static iterate(e,t){if(e instanceof Map||Array.isArray(e))return e.forEach(t);if(e instanceof FormData){for(var r of e.entries())t(r[1],r[0]);return}if(e instanceof NodeList)return e.forEach(t);if(e instanceof HTMLCollection)return Array.from(e).forEach(t);if(e instanceof Object)return Object.keys(e).forEach(r=>{t(e[r],r)});throw Error("The element type ".concat(typeof e," is not iterable!"))}}class s{static serialize(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if("FORM"!==e.nodeName){if(t)throw Error("The passed element is not a form!");return{}}return new FormData(e)}static serializeJson(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1],i=s.serialize(e,t);if(i==={})return i;let o={};return r.iterate(i,(e,t)=>o[t]=e),o}}class i{get(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"application/json",s=this._createPreparedRequest("GET",e,r);return this._sendRequest(s,null,t)}post(e,t,r){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";s=this._getContentType(t,s);let i=this._createPreparedRequest("POST",e,s);return this._sendRequest(i,t,r)}delete(e,t,r){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";s=this._getContentType(t,s);let i=this._createPreparedRequest("DELETE",e,s);return this._sendRequest(i,t,r)}patch(e,t,r){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";s=this._getContentType(t,s);let i=this._createPreparedRequest("PATCH",e,s);return this._sendRequest(i,t,r)}abort(){if(this._request)return this._request.abort()}_registerOnLoaded(e,t){t&&e.addEventListener("loadend",()=>{t(e.responseText,e)})}_sendRequest(e,t,r){return this._registerOnLoaded(e,r),e.send(t),e}_getContentType(e,t){return e instanceof FormData&&(t=!1),t}_createPreparedRequest(e,t,r){return this._request=new XMLHttpRequest,this._request.open(e,t),this._request.setRequestHeader("X-Requested-With","XMLHttpRequest"),r&&this._request.setRequestHeader("Content-type",r),this._request}constructor(){this._request=null}}class o extends window.PluginBaseClass{init(){this._registerEvents()}_registerEvents(){this.$emitter.publish("beforeConfirmNewsletterRegistrationGuestRegisterEvents"),this._submitNewsletterGuestFormClickEvent(),this.$emitter.publish("afterConfirmNewsletterRegistrationGuestRegisterEvents")}_submitNewsletterGuestFormClickEvent(){let e=t.querySelector(document,this.options.elementSelectorConfirmNewsletterGuestFormCheckbox,!1),r=this._submitNewsletterGuestForm.bind(this);e&&(this.$emitter.publish("beforeConfirmNewsletterRegistrationGuestSubmitNewsletterGuestFormClickEvent"),e.removeEventListener("click",r),e.addEventListener("click",r),this.$emitter.publish("afterConfirmNewsletterRegistrationGuestSubmitNewsletterGuestFormClickEvent"))}_submitNewsletterGuestForm(){let e=t.querySelector(document,this.options.elementSelectorConfirmNewsletterGuestAction,!1),r=t.getDataAttribute(e,"data-subscribe"),o=t.getDataAttribute(e,"data-unsubscribe"),n=t.querySelector(document,this.options.elementSelectorConfirmNewsletterGuestFormCheckbox,!1);if(n.checked?e.value=r:e.value=o,n){this.$emitter.publish("beforeConfirmNewsletterRegistrationGuestSubmitNewsletterGuestForm"),this.client=new i;let e=t.querySelector(document,this.options.elementSelectorConfirmNewsletterGuestForm,!1),r=e.getAttribute("action"),o=s.serialize(e);this.client.post(r.toLowerCase(),o,e=>{let t=JSON.parse(e);if(t.length>0){this.$emitter.publish("beforeConfirmNewsletterRegistrationGuestSubmitNewsletterGuestFormCallback");let e=!1,r=!1;for(let s=0;s<t.length;s+=1)"success"===t[s].type?r=!0:"danger"===t[s].type&&(e=!0);r?(this._removeClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapper,this.options.hiddenClass),this._removeClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperSuccess,this.options.hiddenClass),this._addClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperDanger,this.options.hiddenClass),this._addClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperError,this.options.hiddenClass),n.checked?(this._addClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperUnsubscribe,this.options.hiddenClass),this._removeClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperSubscribe,this.options.hiddenClass)):(this._addClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperSubscribe,this.options.hiddenClass),this._removeClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperUnsubscribe,this.options.hiddenClass))):e&&(this._removeClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapper,this.options.hiddenClass),this._addClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperSuccess,this.options.hiddenClass),this._addClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperUnsubscribe,this.options.hiddenClass),this._addClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperSubscribe,this.options.hiddenClass),this._removeClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperDanger,this.options.hiddenClass),this._removeClass(this.options.elementSelectorConfirmNewsletterGuestAlertsWrapperError,this.options.hiddenClass)),this.$emitter.publish("afterConfirmNewsletterRegistrationGuestSubmitNewsletterGuestFormCallback")}},this.options.contentType),this.$emitter.publish("afterConfirmNewsletterRegistrationGuestSubmitNewsletterGuestForm")}}_addClass(e,r){let s=t.querySelector(document,e);s&&!s.classList.contains(r)&&s.classList.add(r)}_removeClass(e,r){let s=t.querySelector(document,e);s&&s.classList.contains(r)&&s.classList.remove(r)}}o.options={contentType:"application/x-www-form-urlencoded",elementSelectorConfirmNewsletterGuestAction:"#confirmNewsletterAction",elementSelectorConfirmNewsletterGuestAlertsWrapper:".js-newsletter-wrapper",elementSelectorConfirmNewsletterGuestAlertsWrapperDanger:".js-newsletter-wrapper .alert-danger",elementSelectorConfirmNewsletterGuestAlertsWrapperError:".js-newsletter-wrapper .alert-danger .alert-content-error",elementSelectorConfirmNewsletterGuestAlertsWrapperSubscribe:".js-newsletter-wrapper .alert-success .alert-content-subscribe",elementSelectorConfirmNewsletterGuestAlertsWrapperSuccess:".js-newsletter-wrapper .alert-success",elementSelectorConfirmNewsletterGuestAlertsWrapperUnsubscribe:".js-newsletter-wrapper .alert-success .alert-content-unsubscribe",elementSelectorConfirmNewsletterGuestForm:".cms-block-newsletter-form #confirmNewsletterForm",elementSelectorConfirmNewsletterGuestFormCheckbox:'[data-confirm-newsletter-registration="true"]',hiddenClass:"d-none"},window.PluginManager.register("ConfirmNewsletterRegistrationGuestPlugin",o,o.options.elementSelectorConfirmNewsletterGuestFormCheckbox)})();