import{r as t,c as s,h as o,g as r}from"./p-dfbe004d.js";function i(t){const s=new FormData(t),o={};return s.forEach(((t,s)=>{o[s]=t})),o}const n=class{constructor(o){t(this,o),this.scSubmit=s(this,"scSubmit",7),this.scFormSubmit=s(this,"scFormSubmit",7),this.scFormChange=s(this,"scFormChange",7),this.novalidate=!1}async getFormData(){return new FormData(this.formElement)}async getFormJson(){return i(this.formElement)}async handleChange(){this.scFormChange.emit(i(this.formElement))}async submit(){return this.submitForm()}getFormControls(){return[...this.form.querySelectorAll("*")]}async validate(){const t=this.getFormControls().filter((t=>"function"==typeof t.reportValidity));if(!this.novalidate)for(const s of t)if((s.offsetWidth||s.offsetHeight||s.getClientRects().length)&&!await s.reportValidity())return!1;return!0}submitForm(){const t=document.createElement("button");this.formElement&&(t.type="submit",t.style.position="absolute",t.style.width="0",t.style.height="0",t.style.clip="rect(0 0 0 0)",t.style.clipPath="inset(50%)",t.style.overflow="hidden",t.style.whiteSpace="nowrap",this.formElement.append(t),t.click(),t.remove())}render(){return o("div",{part:"base",class:"form",role:"form"},o("form",{part:"form",ref:t=>this.formElement=t,onSubmit:async t=>{if(t.preventDefault(),!await this.validate())return!1;this.scSubmit.emit(),this.scFormSubmit.emit()},novalidate:this.novalidate},o("slot",null)))}get form(){return r(this)}};n.style="sc-form{display:block}:host{display:block}::slotted(*:not(:last-child)),sc-form form>*:not(:last-child){margin-bottom:var(--sc-form-row-spacing, 0.75em)}::slotted(*:not(:last-child)).wp-block-spacer,sc-form form>*:not(:last-child).wp-block-spacer{margin-bottom:0}";export{n as sc_form}