var _excluded = ["fieldId", "id", "children", "component", "hint", "hintId", "className", "inversed", "errorMessage", "errorId", "requirementLabel"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import classNames from 'classnames';
import { Hint } from '../Hint';
import { InlineError } from '../InlineError';
/**
 * 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/).
 */
export var Label = function Label(props) {
  var fieldId = props.fieldId,
    id = props.id,
    children = props.children,
    component = props.component,
    hint = props.hint,
    hintId = props.hintId,
    className = props.className,
    inversed = props.inversed,
    errorMessage = props.errorMessage,
    errorId = props.errorId,
    requirementLabel = props.requirementLabel,
    labelProps = _objectWithoutProperties(props, _excluded);
  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.");
  }
  var hintElement;
  if (hint || requirementLabel) {
    hintElement = /*#__PURE__*/React.createElement(Hint, {
      requirementLabel: requirementLabel,
      inversed: inversed,
      id: hintId
    }, hint);
  }
  var errorElement = errorMessage;
  if (typeof errorMessage === 'string') {
    errorElement = /*#__PURE__*/React.createElement(InlineError, {
      id: errorId
    }, errorMessage);
  }
  var htmlFor = fieldId;
  if (component === 'legend' && fieldId) {
    console.warn('The `for` attribute is invalid for legends. Omitting `fieldId` from rendered element.');
    htmlFor = undefined;
  }
  var ComponentType = component;
  var classes = classNames('ds-c-label', className, inversed && 'ds-c-label--inverse');
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ComponentType, _extends({
    className: classes,
    htmlFor: htmlFor,
    id: id
  }, labelProps), children), hintElement, errorElement);
};
Label.defaultProps = {
  component: 'label'
};
export default Label;