import*as e from"react";import{omitThemingProps as t}from"../../../system/dist/esm/system.utils.js";import{useId as s}from"../../../hooks/dist/esm/use-id.js";import{createContext as r}from"../../../react-utils/dist/esm/context.js";import{forwardRef as o}from"../../../system/dist/esm/forward-ref.js";import{useMultiStyleConfig as i}from"../../../system/dist/esm/use-style-config.js";import{cx as a,dataAttr as l}from"../../../utils/dist/esm/dom.js";import{StylesProvider as n,useStyles as d}from"../../../system/dist/esm/providers.js";import{chakra as m}from"../../../system/dist/esm/system.js";import{__DEV__ as u}from"../../../utils/dist/esm/assertion.js";import{useBoolean as c}from"../../../hooks/dist/esm/use-boolean.js";import{mergeRefs as f}from"../../../react-utils/dist/esm/refs.js";import{scheduleMicrotask as p}from"../../../utils/dist/esm/function.js";function v(){return(v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e}).apply(this,arguments)}function h(e,t){if(null==e)return{};var s,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)s=i[r],t.indexOf(s)>=0||(o[s]=e[s]);return o}var[b,y]=r({strict:!1,name:"FormControlContext"});var j=o(((r,o)=>{var d=i("Form",r),u=function(t){var{id:r,isRequired:o,isInvalid:i,isDisabled:a,isReadOnly:n}=t,d=h(t,["id","isRequired","isInvalid","isDisabled","isReadOnly"]),m=s(),u=r||"field-"+m,b=u+"-label",y=u+"-feedback",j=u+"-helptext",[k,x]=e.useState(!1),[g,P]=e.useState(!1),[F,R]=c(),C=e.useCallback((function(e,t){return void 0===e&&(e={}),void 0===t&&(t=null),v({id:j},e,{ref:f(t,(e=>{e&&P(!0)}))})}),[j]),T=e.useCallback((function(e,t){var s,r;return void 0===e&&(e={}),void 0===t&&(t=null),v({},e,{ref:t,"data-focus":l(F),"data-disabled":l(a),"data-invalid":l(i),"data-readonly":l(n),id:null!=(s=e.id)?s:b,htmlFor:null!=(r=e.htmlFor)?r:u})}),[u,a,F,i,n,b]),O=e.useCallback((function(e,t){return void 0===e&&(e={}),void 0===t&&(t=null),v({id:y},e,{ref:f(t,(e=>{e&&x(!0)})),"aria-live":"polite"})}),[y]),H=e.useCallback((function(e,t){return void 0===e&&(e={}),void 0===t&&(t=null),v({},e,d,{ref:t,role:"group"})}),[d]),I=e.useCallback((function(e,t){return void 0===e&&(e={}),void 0===t&&(t=null),v({},e,{ref:t,role:"presentation","aria-hidden":!0,children:e.children||"*"})}),[]),N=e.useCallback((()=>{p(R.on)}),[R]);return{isRequired:!!o,isInvalid:!!i,isReadOnly:!!n,isDisabled:!!a,isFocused:!!F,onFocus:N,onBlur:R.off,hasFeedbackText:k,setHasFeedbackText:x,hasHelpText:g,setHasHelpText:P,id:u,labelId:b,feedbackId:y,helpTextId:j,htmlProps:d,getHelpTextProps:C,getErrorMessageProps:O,getRootProps:H,getLabelProps:T,getRequiredIndicatorProps:I}}(t(r)),{getRootProps:y}=u,j=h(u,["getRootProps","htmlProps"]),k=a("chakra-form-control",r.className),x=e.useMemo((()=>j),[j]);return e.createElement(b,{value:x},e.createElement(n,{value:d},e.createElement(m.div,v({},y({},o),{className:k,__css:{width:"100%",position:"relative"}}))))}));u&&(j.displayName="FormControl");var k=o(((t,s)=>{var r=y(),o=d(),i=a("chakra-form__helper-text",t.className);return e.createElement(m.div,v({},null==r?void 0:r.getHelpTextProps(t,s),{__css:o.helperText,className:i}))}));u&&(k.displayName="FormHelperText");export{j as FormControl,k as FormHelperText,y as useFormControlContext};
//# sourceMappingURL=form-control.js.map
