import{r as u,j as g}from"./vendor-ClLR6ncd.js";import{d as I,l as d,j as l}from"./lodash-ZyeDnt0e.js";import{T as j}from"./index-OtVJl4GC.js";const O=/^\d+$/,$=t=>t.trim()==="",h=t=>`${t} must be a non-empty string`,B=t=>!O.test(t),w=t=>`${t} must be a positive integer`,b=t=>Object.values(t).some(({error:s})=>!!s),m=u.createContext();function C(){return u.useContext(m)}function S(t){return Object.assign({},...Object.entries(t).map(([s,e])=>({[s]:{...typeof e=="string"?{value:e}:{value:"",error:"",...e},init:!0}})))}const E={},f=(t,s,e)=>d([l([t,"value"],s),l([t,"init"],!1),l([t,"error"],e[t].isInvalid?e[t].isInvalid(s)&&e[t].errorMessage:"")])(e);function R({initOptions:t,queryHook:s=E,children:e}){const[i,a]=u.useState(S(t)),p=u.useMemo(()=>Object.assign({},...Object.keys(t).map(o=>({[o]:r=>a(n=>f(o,r,n))}))),[a,t]),v=u.useMemo(()=>Object.assign({},...Object.entries(p).map(([o,r])=>({[o]:n=>r(n.target.value)}))),[p]),{data:c}=s;u.useEffect(()=>{c&&a(o=>Object.keys(c).filter(r=>I(o,[r,"init"])).reduce((r,n)=>f(n,typeof c[n]=="function"?c[n](r):c[n],r),o))},[a,c,p]);const x={options:i,invalid:b(i),optionsSetter:p,optionsTargetValueSetter:v,queryHook:s};return g.jsx(m.Provider,{value:x,children:e})}function V({optionName:t,helperText:s,...e}){const{options:i,optionsSetter:a}=C();return g.jsx(j,{setter:a[t],value:i[t].value,error:!!i[t].error,helperText:i[t].error||s,...e})}export{V as C,R as I,B as a,h as e,$ as i,w as n,C as u};
