(()=>{"use strict";const e=function(e,t){var s,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],n=arguments.length>4&&void 0!==arguments[4]&&arguments[4];try{s=new CustomEvent(t,{bubbles:o,cancelable:n,detail:r})}catch(e){(s=document.createEvent("CustomEvent")).initCustomEvent(t,o,n,r)}e.dispatchEvent(s)};function t(t){t.preventDefault();const s=t.target,r=s.querySelector(".smf-focus-point"),o=s.querySelector(".smf-form"),n=s.querySelector(".smf-action"),a=new FormData(s),c=n.querySelector('[data-clicked="true"]'),l=t.submitter||c,i=l?l.querySelector(".smf-sending"):void 0;i&&i.setAttribute("aria-hidden","false"),c&&c.removeAttribute("data-clicked");const m={status:"init",inputs:[].slice.call(s.querySelectorAll("input[name]:not([disabled]), textarea[name]:not([disabled]), select[name]:not([disabled])")).map((e=>{let t;return"checkbox"===e.type||"radio"===e.type?e.checked&&(t=e.value):t=e.value,void 0!==t&&{name:e.getAttribute("name"),value:t}})).filter((e=>e)),formData:a},d=e=>{o.innerHTML=e},u=e=>{n.innerHTML=e},f=()=>{r&&window.scrollTo(0,window.pageYOffset+r.getBoundingClientRect().top)},v=(r=null)=>{s.setAttribute("data-screen","systemerror");const o=document.createElement("div");o.classList.add("smf-system-error-content");const n=s.querySelector(".smf-system-error-content-ready");if(o.textContent=n.textContent,r){const e=document.createElement("br"),t=document.createElement("span");t.classList.add("smf-system-error-status-text"),t.textContent=`(status: ${r})`,o.appendChild(e),o.appendChild(t)}d(o.outerHTML),u(""),f(),m.status="systemerror",e(t.target,"smf.systemerror",m)};e(t.target,"smf.beforesubmit",m);const y=new XMLHttpRequest;y.onreadystatechange=()=>{4===y.readyState&&(200===y.status&&y.status?(r=>{if(i&&i.setAttribute("aria-hidden","true"),void 0===(r=JSON.parse(r)).method)return void v();const o=r.method;if(s.setAttribute("data-screen",o),u(r.action),[].slice.call(s.querySelectorAll(".smf-placeholder")).forEach((e=>{e.innerHTML=""})),(e=>""===e||"back"===e||"invalid"===e||"confirm"===e)(o)){(e=>{for(const t in e){const r=e[t];s.querySelector(`.smf-placeholder[data-name="${t}"]`).innerHTML=r}})(r.controls);const e=[].slice.call(s.querySelectorAll(".smf-error-messages"));0{if(0{for(let t=e;t;t=t.parentElement)if(t.classList.contains("smf-placeholder"))return t})(e[0]),s=!!t&&t.querySelector("input, select, textarea, button, .smf-file-control");s&&s.focus()}})(e):f()}else(e=>"complete"===e||"systemerror"===e)(o)?(d(r.message),f(),u(r.action)):(d(""),u(""));switch(m.status=o,m.status){case"back":e(t.target,"smf.back",m);break;case"confirm":e(t.target,"smf.confirm",m);break;case"complete":e(t.target,"smf.complete",m);break;case"invalid":e(t.target,"smf.invalid",m);break;case"systemerror":e(t.target,"smf.systemerror",m)}e(t.target,"smf.submit",m)})(JSON.parse(y.response)):v(y?.statusText))},y.open("POST",snowmonkeyforms.view_json_url,!0),y.send(a)}document.addEventListener("change",(e=>{const t=e.target;if(t.classList.contains("smf-file-control__control")){const e=t.closest(".smf-file-control"),s=e.querySelector(".smf-file-control__filename--has-file"),r=t.files;if(0{const t=e.target;if(t.classList.contains("smf-file-control__clear")){const e=t.closest(".smf-file-control");e.classList.remove("smf-file-control--set"),e.classList.remove("smf-file-control--uploaded"),e.querySelector(".smf-file-control__control").value="";const s=t.closest(".smf-placeholder").querySelector(".smf-file-control__value");s&&s.remove()}}),!1);const s=(e,t)=>{for(let s=e;s;s=s.parentElement)if(s.classList.contains(t))return s};document.addEventListener("click",(e=>{const t=e.target;if(t.getAttribute("data-action")&&t.setAttribute("data-clicked","true"),"back"===t.getAttribute("data-action")){const e=s(t,"smf-action");if(e){const t=e.querySelector('[type="hidden"][name="snow-monkey-forms-meta[method]"]');t&&t.setAttribute("value","back")}}}),!1),[].slice.call(document.querySelectorAll(".snow-monkey-form")).forEach((e=>{e.addEventListener("submit",t,!1)})),["change","keyup"].forEach((e=>{document.addEventListener(e,(e=>{const t=e.target;if("1"===t.getAttribute("data-invalid")){t.removeAttribute("data-invalid"),[].slice.call(t.querySelectorAll('[data-invalid="1"]')).forEach((e=>e.removeAttribute("data-invalid")));const e=s(t,"smf-placeholder");if(e){const t=e.querySelector(".smf-error-messages");t&&t.parentNode.removeChild(t)}}}),!1)}))})();