'use strict';

var React = require('react');
var jsxRuntime = require('react/jsx-runtime');

const FieldLabelContext = /*#__PURE__*/React.createContext(undefined);
const FieldLabelContextProvider = FieldLabelContext.Provider;
const InputIdContext = /*#__PURE__*/React.createContext(undefined);
const InputIdContextProvider = InputIdContext.Provider;
const InputDescribedByContext = /*#__PURE__*/React.createContext(undefined);
const InputDescribedByProvider = InputDescribedByContext.Provider;
const InputInvalidContext = /*#__PURE__*/React.createContext(undefined);
const InputInvalidProvider = InputInvalidContext.Provider;
function useInputAttributes({
  nonLabelable
} = {}) {
  const labelId = React.useContext(FieldLabelContext)?.id;
  return {
    id: React.useContext(InputIdContext),
    'aria-labelledby': nonLabelable ? labelId : undefined,
    'aria-describedby': React.useContext(InputDescribedByContext),
    'aria-invalid': React.useContext(InputInvalidContext)
  };
}
function useFieldLabelRef() {
  return React.useContext(FieldLabelContext)?.ref;
}
const TextareaCharacterCountContext = /*#__PURE__*/React.createContext(undefined);
const TextareaCharacterCountProvider = TextareaCharacterCountContext.Provider;
function useTextareaCharacterCount(current, max) {
  const setCharacterCount = React.useContext(TextareaCharacterCountContext);
  React.useEffect(() => {
    if (setCharacterCount && max != null) {
      setCharacterCount({
        current,
        max
      });
      return () => setCharacterCount(null);
    }
  }, [setCharacterCount, current, max]);
}
function withInputAttributes(Component, args) {
  function ComponentWithInputAttributes(props) {
    return /*#__PURE__*/jsxRuntime.jsx(Component, {
      inputAttributes: useInputAttributes(args),
      ...props
    });
  }
  ComponentWithInputAttributes.displayName = `withInputAttributes(${Component.displayName || Component.name || 'Component'})`;
  return ComponentWithInputAttributes;
}

exports.FieldLabelContextProvider = FieldLabelContextProvider;
exports.InputDescribedByProvider = InputDescribedByProvider;
exports.InputIdContextProvider = InputIdContextProvider;
exports.InputInvalidProvider = InputInvalidProvider;
exports.TextareaCharacterCountProvider = TextareaCharacterCountProvider;
exports.useFieldLabelRef = useFieldLabelRef;
exports.useInputAttributes = useInputAttributes;
exports.useTextareaCharacterCount = useTextareaCharacterCount;
exports.withInputAttributes = withInputAttributes;
//# sourceMappingURL=contexts.js.map
