import*as e from"@wordpress/interactivity";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const n=(o={getConfig:()=>e.getConfig,getContext:()=>e.getContext,getElement:()=>e.getElement,store:()=>e.store},r={},t.d(r,o),r);var o,r;function s(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}!function e(t,n){function o(e,o,r){if("undefined"!=typeof document){"number"==typeof(r=s({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var i in r)r[i]&&(a+="; "+i,!0!==r[i]&&(a+="="+r[i].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+a}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],o={},r=0;r<n.length;r++){var s=n[r].split("="),a=s.slice(1).join("=");try{var i=decodeURIComponent(s[0]);if(o[i]=t.read(a,i),e===i)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",s({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,s({},this.attributes,t))},withConverter:function(t){return e(s({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const{state:a}=(0,n.store)("popper",{state:{get debugData(){const e=(0,n.getContext)();return JSON.stringify(e.response.data.debug,void 0,2)},get message(){const e=(0,n.getContext)();return e.response?.data?.errors.length?e.response?.data?.message:e.response&&e.successMessage?e.successMessage:e.response?.data?.message},get errors(){const e=(0,n.getContext)();return e.response?.data?.errors||[]}},actions:{sendForm:e=>{e.preventDefault(),e.stopPropagation(),(0,n.getContext)().isLoading=!0,(async()=>{const{ref:e}=(0,n.getElement)(),t=(0,n.getContext)(),o=(0,n.getConfig)(),{id:r}=e.dataset,s=new FormData(e);s.append("action","popper"),s.append("_nonce",o.nonce),s.append("_popper_id",r);try{t.isLoading=!0;const n=await fetch(o.ajax_url,{method:"POST",body:s}),r=await n.json();t.response=r,t.isLoading=!1,((e,t)=>{const{data:n}=t;if(n.redirect_url&&t.success)return window.location=n.redirect_url,!1;if(n.hide&&t.success){const t=e.querySelector(".popper-message");e.insertAdjacentElement("beforebegin",t),setTimeout((()=>{e.style.display="none",t.scrollIntoView({behavior:"smooth"})}),"300")}n.debug&&t.success&&console.log(n.debug),t.success&&(window.dispatchEvent(new CustomEvent("popper-form-success",{detail:void 0})),e.reset())})(e,r)}catch(e){t.isLoading=!1,t.response="string"==typeof e||e instanceof String?{data:{message:e},success:!1}:{data:{message:"An error occurred"},success:!1}}})()}}});