import{r as l}from"./wp-i18n-shim-DUX0OV_V.js";function C(e,s){if(!(!s||!e))return s.split(".").reduce((t,f)=>t==null?void 0:t[f],e)}function k(e){if(e)return e.split(".").pop()}function V(e={},s=null){const[t,f]=l.useState({}),m=l.useCallback((c,r=null)=>{const a=r||Object.keys(e),i={};for(const o of a){const n=e[o];if(!n)continue;const u=C(c,o),p=k(o);for(const d of n)if(!d.check(u,c)){const g=d.dynamicMessage?d.dynamicMessage(u,c):d.message;i[p]={field:o,first_message:g,messages:[g]};break}}return f(i),s&&s(i),Object.keys(i).length>0&&setTimeout(()=>{var u;const o=Object.keys(i)[0],n=document.querySelector(`[name="${o}"], [data-field="${o}"], #${o}`);n&&(n.scrollIntoView({behavior:"smooth",block:"center"}),(u=n.focus)==null||u.call(n))},100),{isValid:Object.keys(i).length===0,errors:i}},[e,s]),y=l.useCallback(()=>{f({}),s&&s({})},[s]),b=l.useCallback(c=>{var a;const r=k(c);return((a=t[r])==null?void 0:a.first_message)||null},[t]),h=l.useCallback(c=>{const r=k(c);return!!t[r]},[t]);return{errors:t,validate:m,clearErrors:y,getError:b,hasError:h}}export{V as u};
//# sourceMappingURL=useValidation-B5n8rnWA.js.map
