document.addEventListener("DOMContentLoaded",function(){const e=document.getElementById("wpvofw-feedback-container"),t=document.getElementById("wpvofw-order-feedback-form");if(t){const n=t.querySelector(".wpvofw-rating");u(t),f(e),n!==null&&d(t,n)}});function u(e){const t=document.querySelector(".wpvofw-content");e!==null&&e.addEventListener("submit",function(n){n.preventDefault();const a=feedback_form_data.ajaxurl,c=feedback_form_data.currentpageurl;let s=new FormData(e);s.append("action","wpvofw_submit_feedback"),s.append("currentpageurl",c),fetch(a,{method:"post",credentials:"same-origin",body:s}).then(i=>{if(i.ok)return i.json();throw new Error("Error: "+i.status)}).then(i=>{if(i.status=="error"){t.querySelector(".wpvofw-info").innerHTML="<span class = 'wpvofw-error'>"+i.message+"</span>",i.errors&&i.errors.forEach(function(l){const o=e.querySelector('[name="'+l.key+'"]');o&&o.classList.add("invalid")});return}else t.innerHTML="<span>"+i.message+"</span>",t.querySelector("span").classList.add("wpvofw-success")}).catch(function(i){console.error(i)})})}function f(e){if(e.classList.contains("wpvofw-type-floating")){const t=e.querySelector(".wpvofw-topbar"),n=e.querySelector(".wpvofw-close-btn"),a=e.clientHeight;if(t){const c=t.clientHeight;t.addEventListener("click",function(s){n.classList.contains("rotate")?(e.style.maxHeight=a+"px",n.classList.remove("rotate")):(e.style.maxHeight=c+"px",n.classList.add("rotate"))})}}}function d(e,t){let n=t.getAttribute("data-rating-style");if(n)switch(n){case"number":w(t,e);break;case"star":v(t,e);break;case"smiley":p(t,e);break}}function w(e,t){let n=e.querySelectorAll("span");n.forEach(function(a){a.addEventListener("click",function(){let c=parseInt(this.getAttribute("data-rating"));t.querySelector("#wpvofw-rating").value=c,n.forEach(function(s){s.classList.remove("wpvofw-selected")}),a.classList.add("wpvofw-selected")})})}function v(e,t){if(e.classList.contains("wpvofw-star-rating")){let n=e.querySelectorAll("span");n.forEach(function(a,c){a.addEventListener("mouseenter",function(){for(let s=0;s<=c;s++)n[s].classList.add("wpvofw-selected");for(let s=c+1;s<n.length;s++)n[s].classList.remove("wpvofw-selected")}),a.addEventListener("click",function(){let s=parseInt(this.getAttribute("data-rating"));t.querySelector("#wpvofw-rating").value=s})})}}function p(e,t){let n=e.querySelectorAll(".emoji");n.forEach(function(a){a.addEventListener("click",function(){n.forEach(function(s){s.classList.remove("wpvofw-active")}),a.classList.add("wpvofw-active");let c=parseInt(this.getAttribute("data-rating"));t.querySelector("#wpvofw-rating").value=c})})}
//# sourceMappingURL=frontend.js.map
