import { createContext, useContext } from 'react';
import { jsx } from 'react/jsx-runtime';

const FieldLabelContext = /*#__PURE__*/createContext(undefined);
const FieldLabelContextProvider = FieldLabelContext.Provider;
const InputIdContext = /*#__PURE__*/createContext(undefined);
const InputIdContextProvider = InputIdContext.Provider;
const InputDescribedByContext = /*#__PURE__*/createContext(undefined);
const InputDescribedByProvider = InputDescribedByContext.Provider;
const InputInvalidContext = /*#__PURE__*/createContext(undefined);
const InputInvalidProvider = InputInvalidContext.Provider;
function useInputAttributes({
  nonLabelable
} = {}) {
  const labelId = useContext(FieldLabelContext)?.id;
  return {
    id: useContext(InputIdContext),
    'aria-labelledby': nonLabelable ? labelId : undefined,
    'aria-describedby': useContext(InputDescribedByContext),
    'aria-invalid': useContext(InputInvalidContext)
  };
}
function useFieldLabelRef() {
  return useContext(FieldLabelContext)?.ref;
}
function withInputAttributes(Component, args) {
  function ComponentWithInputAttributes(props) {
    return /*#__PURE__*/jsx(Component, {
      inputAttributes: useInputAttributes(args),
      ...props
    });
  }
  ComponentWithInputAttributes.displayName = `withInputAttributes(${Component.displayName || Component.name || 'Component'})`;
  return ComponentWithInputAttributes;
}

export { FieldLabelContextProvider, InputDescribedByProvider, InputIdContextProvider, InputInvalidProvider, useFieldLabelRef, useInputAttributes, withInputAttributes };
//# sourceMappingURL=contexts.mjs.map
