"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.Label = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _Hint = require("../Hint");
var _InlineError = require("../InlineError");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
 * The Label component describes individual form fields (as a `<label>`) or fieldsets (as
 * a `<legend>`). They are built in to all form fields in the design system, but they can
 * also be used on their own to create custom fields.
 *
 * For information about how and when to use this component,
 * [refer to its full documentation page](https://design.cms.gov/components/label/).
 */
const Label = props => {
  const {
    fieldId,
    id,
    children,
    component,
    hint,
    hintId,
    className,
    inversed,
    errorMessage,
    errorId,
    requirementLabel,
    ...labelProps
  } = props;
  if (process.env.NODE_ENV !== 'production' && (hint || hintId)) {
    console.warn("[Deprecated]: Hints are now their own component called 'Hint'. Please render your 'Hint' directly instead of passing them to 'Label'.");
  }
  if (process.env.NODE_ENV !== 'production' && errorMessage) {
    console.warn("[Deprecated]: Passing 'errorMessage' to the 'Label' component is now deprecated. Please render your error message directly with the 'InlineError' component instead.");
  }
  let hintElement;
  if (hint || requirementLabel) {
    hintElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Hint.Hint, {
      requirementLabel: requirementLabel,
      inversed: inversed,
      id: hintId,
      children: hint
    });
  }
  let errorElement = errorMessage;
  if (typeof errorMessage === 'string') {
    errorElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(_InlineError.InlineError, {
      id: errorId,
      children: errorMessage
    });
  }
  let htmlFor = fieldId;
  if (component === 'legend' && fieldId) {
    console.warn('The `for` attribute is invalid for legends. Omitting `fieldId` from rendered element.');
    htmlFor = undefined;
  }
  const ComponentType = component;
  const classes = (0, _classnames.default)('ds-c-label', className, inversed && 'ds-c-label--inverse');
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ComponentType, {
      className: classes,
      htmlFor: htmlFor,
      id: id,
      ...labelProps,
      children: children
    }), hintElement, errorElement]
  });
};
exports.Label = Label;
Label.defaultProps = {
  component: 'label'
};
var _default = exports.default = Label;