(()=>{"use strict";var i={n:s=>{var t=s&&s.__esModule?()=>s.default:()=>s;return i.d(t,{a:t}),t},d:(s,t)=>{for(var e in t)i.o(t,e)&&!i.o(s,e)&&Object.defineProperty(s,e,{enumerable:!0,get:t[e]})},o:(i,s)=>Object.prototype.hasOwnProperty.call(i,s),r:i=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(i,"__esModule",{value:!0})}},s={};i.r(s),i.d(s,{default:()=>o});const t=window.AFFWP.portal.alpineForm;var e=i.n(t);const a=window.AFFWP.portal.sdk,o=i=>({...e(),...{sectionId:i,isLoading:!0,isValidating:!1,isSubmitting:!1,showingSuccessMessage:!1,exportFields(){return this.fields.reduce(((i,s)=>(i[s.id]=s.value,i)),{})},hasValidations(i){const s=this.getField(i);return!1!==s&&!0===s.hasValidations},async validateControl(i){if(!1===this.hasValidations(i))return;this.isValidating=!0;const s=await(0,a.validateControl)(i,this.exportFields()),t=s.validations.passed.map((i=>i.id));this.removeErrors(t),this.addErrors(s.validations.failed),this.isValidating=!1},setupSubmit:()=>({"x-bind:disabled"(){return this.hasErrors()||this.isLoading||this.isValidating||this.isSubmitting}}),setupField(i,s="",t=""){const a=e().setupField.bind(this)(i,s,t),o=a["x-on:input"].bind(this),n=["checkbox","select","radio"].includes(s),d={"x-on:input"(s){if(o(s),n)this.validateControl(i);else{const s=this.fields.findIndex((s=>s.id===i));void 0!==this.fields[s].validating&&window.clearTimeout(this.fields[s].validating),this.isLoading=!0,this.fields[s].validating=window.setTimeout((()=>{this.validateControl(i),delete this.fields[s].validating,this.isLoading=!1}),200)}},"x-on:blur"(){this.validateControl(i),this.isLoading=!1}};return{...a,...d}},async submitForm(){this.isSubmitting=!0;const i=await(0,a.submitSection)(this.sectionId,this.exportFields());this.removeErrors(i.validations.passed),this.addErrors(i.validations.failed),this.isSubmitting=!1,this.hasErrors()||this.flashSuccessMessage()},async flashSuccessMessage(){this.showingSuccessMessage=!0,await new Promise((i=>setTimeout(i,1e3))),this.showingSuccessMessage=!1},setupForm:()=>({async"x-on:submit"(i){i.preventDefault(),this.submitForm()}}),async init(){const i=await(0,a.portalSectionFields)(this.sectionId);this.fields=i.fields.map((i=>("checkbox"===i.type&&("on"===i.value&&(i.value=!0),"off"===i.value&&(i.value=!1)),i))),this.isLoading=!1}}});((window.AFFWP=window.AFFWP||{}).portal=window.AFFWP.portal||{}).portalForm=s})();