import{o as e}from"./rolldown-runtime.C0FnF6B9.js";import{r as t}from"./emotion-is-prop-valid.esm.CuYlOKOk.js";import{T as n,pt as r,q as i}from"./Tooltip.CcubhKj6.js";import{c as a}from"./useFocusRing.DKgtHVTa.js";var o=e(t(),1),s={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valueMissing:!1,valid:!0},c={...s,customError:!0,valid:!1},l={isInvalid:!1,validationDetails:s,validationErrors:[]},u=(0,o.createContext)({}),d=`__reactAriaFormValidationState`;function f(e){if(e.__reactAriaFormValidationState){let{realtimeValidation:t,displayValidation:n,updateValidation:r,resetValidation:i,commitValidation:a}=e[d];return{realtimeValidation:t,displayValidation:n,updateValidation:r,resetValidation:i,commitValidation:a}}return p(e)}function p(e){let{isInvalid:t,validationState:n,name:r,value:i,builtinValidation:a,validate:s,validationBehavior:d=`aria`}=e;n&&(t||=n===`invalid`);let f=t===void 0?null:{isInvalid:t,validationErrors:[],validationDetails:c},p=(0,o.useMemo)(()=>!s||i==null?null:g(h(s,i)),[s,i]);a?.validationDetails.valid&&(a=void 0);let v=(0,o.useContext)(u),y=(0,o.useMemo)(()=>r?Array.isArray(r)?r.flatMap(e=>m(v[e])):m(v[r]):[],[v,r]),[b,x]=(0,o.useState)(v),[S,C]=(0,o.useState)(!1);v!==b&&(x(v),C(!1));let w=(0,o.useMemo)(()=>g(S?[]:y),[S,y]),T=(0,o.useRef)(l),[E,D]=(0,o.useState)(l),O=(0,o.useRef)(l),k=()=>{if(!A)return;j(!1);let e=p||a||T.current;_(e,O.current)||(O.current=e,D(e))},[A,j]=(0,o.useState)(!1);return(0,o.useEffect)(k),{realtimeValidation:f||w||p||a||l,displayValidation:d===`native`?f||w||E:f||w||p||a||E,updateValidation(e){d===`aria`&&!_(E,e)?D(e):T.current=e},resetValidation(){let e=l;_(e,O.current)||(O.current=e,D(e)),d===`native`&&j(!1),C(!0)},commitValidation(){d===`native`&&j(!0),C(!0)}}}function m(e){return e?Array.isArray(e)?e:[e]:[]}function h(e,t){if(typeof e==`function`){let n=e(t);if(n&&typeof n!=`boolean`)return m(n)}return[]}function g(e){return e.length?{isInvalid:!0,validationErrors:e,validationDetails:c}:null}function _(e,t){return e===t||!!e&&!!t&&e.isInvalid===t.isInvalid&&e.validationErrors.length===t.validationErrors.length&&e.validationErrors.every((e,n)=>e===t.validationErrors[n])&&Object.entries(e.validationDetails).every(([e,n])=>t.validationDetails[e]===n)}var v=(0,o.createContext)(null);function y(e,t,s){let{validationBehavior:c,focus:l}=e;r(()=>{if(c===`native`&&s?.current&&`setCustomValidity`in s.current&&!s.current.disabled){let e=t.realtimeValidation.isInvalid?t.realtimeValidation.validationErrors.join(` `)||`Invalid value.`:``;s.current.setCustomValidity(e),s.current.hasAttribute(`title`)||(s.current.title=``),t.realtimeValidation.isInvalid||t.updateValidation(x(s.current))}});let u=(0,o.useRef)(!1),d=n(()=>{u.current||t.resetValidation()}),f=n(e=>{t.displayValidation.isInvalid||t.commitValidation();let n=s?.current?.form;!e.defaultPrevented&&s&&n&&S(n)===s.current&&(l?l():s.current?.focus(),a(`keyboard`)),e.preventDefault()}),p=n(()=>{t.commitValidation()});(0,o.useEffect)(()=>{let e=s?.current;if(!e)return;let t=e.form,n=t?.reset;return t&&(t.reset=()=>{u.current=!window.event||window.event.type===`message`&&i(window.event)instanceof MessagePort,n?.call(t),u.current=!1}),e.addEventListener(`invalid`,f),e.addEventListener(`change`,p),t?.addEventListener(`reset`,d),()=>{e.removeEventListener(`invalid`,f),e.removeEventListener(`change`,p),t?.removeEventListener(`reset`,d),t&&(t.reset=n)}},[s,c])}function b(e){let t=e.validity;return{badInput:t.badInput,customError:t.customError,patternMismatch:t.patternMismatch,rangeOverflow:t.rangeOverflow,rangeUnderflow:t.rangeUnderflow,stepMismatch:t.stepMismatch,tooLong:t.tooLong,tooShort:t.tooShort,typeMismatch:t.typeMismatch,valueMissing:t.valueMissing,valid:t.valid}}function x(e){return{isInvalid:!e.validity.valid,validationDetails:b(e),validationErrors:e.validationMessage?[e.validationMessage]:[]}}function S(e){for(let t=0;t<e.elements.length;t++){let n=e.elements[t];if(n.validity?.valid===!1)return n}return null}export{f as a,l as i,v as n,d as r,y as t};