"use strict";const d=require("react"),q=require("./useFocusVisible-DfE3Z6QO.cjs.js"),V=require("./mergeProps-CxnHrnow.cjs.js"),p={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valueMissing:!1,valid:!0},C={...p,customError:!0,valid:!1},$={isInvalid:!1,validationDetails:p,validationErrors:[]},B=d.createContext({}),x="__formValidationState"+Date.now();function T(t){if(t[x]){let{realtimeValidation:e,displayValidation:a,updateValidation:r,resetValidation:c,commitValidation:l}=t[x];return{realtimeValidation:e,displayValidation:a,updateValidation:r,resetValidation:c,commitValidation:l}}return U(t)}function U(t){let{isInvalid:e,validationState:a,name:r,value:c,builtinValidation:l,validate:v,validationBehavior:s="aria"}=t;a&&(e||(e=a==="invalid"));let f=e!==void 0?{isInvalid:e,validationErrors:[],validationDetails:C}:null,n=d.useMemo(()=>{if(!v||c==null)return null;let o=F(v,c);return L(o)},[v,c]);l?.validationDetails.valid&&(l=void 0);let i=d.useContext(B),u=d.useMemo(()=>r?Array.isArray(r)?r.flatMap(o=>S(i[o])):S(i[r]):[],[i,r]),[b,A]=d.useState(i),[w,E]=d.useState(!1);i!==b&&(A(i),E(!1));let g=d.useMemo(()=>L(w?[]:u),[w,u]),D=d.useRef($),[y,I]=d.useState($),m=d.useRef($),R=()=>{if(!O)return;h(!1);let o=n||l||D.current;M(o,m.current)||(m.current=o,I(o))},[O,h]=d.useState(!1);return d.useEffect(R),{realtimeValidation:f||g||n||l||$,displayValidation:s==="native"?f||g||y:f||g||n||l||y,updateValidation(o){s==="aria"&&!M(y,o)?I(o):D.current=o},resetValidation(){let o=$;M(o,m.current)||(m.current=o,I(o)),s==="native"&&h(!1),E(!0)},commitValidation(){s==="native"&&h(!0),E(!0)}}}function S(t){return t?Array.isArray(t)?t:[t]:[]}function F(t,e){if(typeof t=="function"){let a=t(e);if(a&&typeof a!="boolean")return S(a)}return[]}function L(t){return t.length?{isInvalid:!0,validationErrors:t,validationDetails:C}:null}function M(t,e){return t===e?!0:!!t&&!!e&&t.isInvalid===e.isInvalid&&t.validationErrors.length===e.validationErrors.length&&t.validationErrors.every((a,r)=>a===e.validationErrors[r])&&Object.entries(t.validationDetails).every(([a,r])=>e.validationDetails[a]===r)}function P(...t){let e=new Set,a=!1,r={...p};for(let v of t){var c,l;for(let s of v.validationErrors)e.add(s);a||(a=v.isInvalid);for(let s in r)(c=r)[l=s]||(c[l]=v.validationDetails[s])}return r.valid=!a,{isInvalid:a,validationErrors:[...e],validationDetails:r}}function j(t,e,a){let{validationBehavior:r,focus:c}=t;V.$f0a04ccd8dbdd83b$export$e5c5a5f917a5871c(()=>{if(r==="native"&&a?.current&&!a.current.disabled){let n=e.realtimeValidation.isInvalid?e.realtimeValidation.validationErrors.join(" ")||"Invalid value.":"";a.current.setCustomValidity(n),a.current.hasAttribute("title")||(a.current.title=""),e.realtimeValidation.isInvalid||e.updateValidation(k(a.current))}});let l=d.useRef(!1),v=V.$8ae05eaa5c114e9c$export$7f54fc3180508a52(()=>{l.current||e.resetValidation()}),s=V.$8ae05eaa5c114e9c$export$7f54fc3180508a52(n=>{var i;e.displayValidation.isInvalid||e.commitValidation();let u=a==null||(i=a.current)===null||i===void 0?void 0:i.form;if(!n.defaultPrevented&&a&&u&&N(u)===a.current){var b;c?c():(b=a.current)===null||b===void 0||b.focus(),q.$507fabe10e71c6fb$export$8397ddfc504fdb9a("keyboard")}n.preventDefault()}),f=V.$8ae05eaa5c114e9c$export$7f54fc3180508a52(()=>{e.commitValidation()});d.useEffect(()=>{let n=a?.current;if(!n)return;let i=n.form,u=i?.reset;return i&&(i.reset=()=>{l.current=!window.event||window.event.type==="message"&&window.event.target instanceof MessagePort,u?.call(i),l.current=!1}),n.addEventListener("invalid",s),n.addEventListener("change",f),i?.addEventListener("reset",v),()=>{n.removeEventListener("invalid",s),n.removeEventListener("change",f),i?.removeEventListener("reset",v),i&&(i.reset=u)}},[a,s,f,v,r])}function Q(t){let e=t.validity;return{badInput:e.badInput,customError:e.customError,patternMismatch:e.patternMismatch,rangeOverflow:e.rangeOverflow,rangeUnderflow:e.rangeUnderflow,stepMismatch:e.stepMismatch,tooLong:e.tooLong,tooShort:e.tooShort,typeMismatch:e.typeMismatch,valueMissing:e.valueMissing,valid:e.valid}}function k(t){return{isInvalid:!t.validity.valid,validationDetails:Q(t),validationErrors:t.validationMessage?[t.validationMessage]:[]}}function N(t){for(let e=0;e<t.elements.length;e++){let a=t.elements[e];if(!a.validity.valid)return a}return null}exports.$e5be200c675c3b3a$export$75ee7c75d68f5b0e=P;exports.$e5be200c675c3b3a$export$a763b9476acd3eb=x;exports.$e5be200c675c3b3a$export$aca958c65c314e6c=p;exports.$e5be200c675c3b3a$export$dad6ae84456c676a=$;exports.$e5be200c675c3b3a$export$fc1a364ae1f3ff10=T;exports.$e93e671b31057976$export$b8473d3665f3a75a=j;
//# sourceMappingURL=useFormValidation-BfTV0EQ1.cjs.js.map
