(()=>{"use strict";const{INITIAL_STEP:e,NONCE:t}=window.awpcpOnboardingWizardVars,n="awpcp-onboarding",o="hidden",s="awpcp-current",c={INITIAL:e,SUCCESS:"success"},{getElements:a,addElements:r}=function(e={}){if("object"!=typeof e||null===e)throw new Error("createPageElements: initialElements must be a non-null object");let t=e;return{getElements:function(){return t},addElements:function(e){if("object"!=typeof e||null===e)throw new Error("addElements: newElements must be a non-null object");t={...t,...e}}}}({onboardingWizardPage:document.getElementById(`${n}-wizard-page`),container:document.getElementById(`${n}-container`),rootline:document.getElementById(`${n}-rootline`),steps:document.querySelectorAll(`.${n}-step`),skipStepButtons:document.querySelectorAll(`.${n}-skip-step`),consentTrackingButton:document.getElementById(`${n}-consent-tracking`),collapsible:document.querySelector(".awpcp-collapsible")}),i=new URL(window.location.href),l=i.searchParams,d=e=>l.get(e),p=e=>(l.delete(e),i.search=l.toString(),i.toString()),u=(e,t="pushState")=>{const r=document.querySelector(`.${n}-step[data-step-name="${e}"]`);if(!r)return;const d=document.querySelector(`.${n}-step.${s}`);var p;d&&(d.classList.remove(s),p=d,p?.classList.add(o),d.classList.remove("awpcp-fadein-up")),r.classList.add(s),(e=>{e?.classList.remove(o)})(r),r.classList.add("awpcp-fadein-up");const{onboardingWizardPage:u}=a();u.setAttribute("data-current-step",e),((e,t,n="pushState")=>{if(l.set(e,t),i.search=l.toString(),["pushState","replaceState"].includes(n)){const o={[e]:t};window.history[n](o,"",i)}i.toString()})("step",e,t),function(e){const{rootline:t}=a(),n=t.querySelector(`.awpcp-onboarding-rootline-item[data-step="${e}"]`);t.querySelectorAll(".awpcp-onboarding-rootline-item").forEach(e=>{e.classList.remove(g),e.classList.remove(s)});let o=n.previousElementSibling;if(o)for(;o;)o.classList.add(g),o=o.previousElementSibling;e===c.SUCCESS?n.classList.add(g):n.classList.add(s)}(e)},m=()=>{const e=document.querySelector(`.${n}-step.${s}`),t=e?.nextElementSibling;t&&u(t.dataset.stepName)};const g="awpcp-completed-step",S=e=>{e.preventDefault();const t=e.currentTarget;t.classList.toggle("awpcp-open");const n=t.nextElementSibling;n.classList.toggle(o),n.classList.toggle("awpcp-fadein-down")},w=async e=>{e.preventDefault();const n=new FormData;let o;n.append("action","awpcp_onboarding_consent_tracking"),n.append("nonce",t);try{const e=await fetch(ajaxurl,{method:"POST",body:n});o=await e.json()}catch(e){console.error("Error:",e)}o.success?m():console.error(o||"Request failed")};window.addEventListener("popstate",e=>{const t=e.state?.step||d("step");u(t,"replaceState")});const f=function(){!function(){const e=d("step")||c.INITIAL;p("key"),p("success"),u(e,"replaceState")}(),function(){const{onboardingWizardPage:e,container:t}=a();e.classList.remove("awpcp-hide-js"),t.classList.toggle("awpcp-fadein-up")}(),function(){const{skipStepButtons:e}=a();e.forEach(e=>{e.addEventListener("click",m)})}(),function(){const{collapsible:e}=a();e.addEventListener("click",S)}(),function(){const{consentTrackingButton:e}=a();e.addEventListener("click",w)}()};var E;E=()=>{f()},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",E):E())})();
//# sourceMappingURL=onboarding-wizard.js.map