"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FieldSet = void 0;

var _react = _interopRequireDefault(require("react"));

var _ = require("..");

var _classnames = _interopRequireDefault(require("classnames"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * Accessibility-following wrapping component for a native fieldset element
 */
var FieldSet = function FieldSet(_ref) {
  var legend = _ref.legend,
      id = _ref.id,
      _ref$showLegend = _ref.showLegend,
      showLegend = _ref$showLegend === void 0 ? true : _ref$showLegend,
      _ref$legendStyle = _ref.legendStyle,
      legendStyle = _ref$legendStyle === void 0 ? 'normal' : _ref$legendStyle,
      status = _ref.status,
      optional = _ref.optional,
      className = _ref.className,
      children = _ref.children,
      hint = _ref.hint,
      childrenGroupClassName = _ref.childrenGroupClassName,
      disabled = _ref.disabled;
  var legendId = "fieldset-legend-".concat(id);
  var hintId = "".concat(id, "-hint");
  var ariaLabeler = legendId;

  if (hint) {
    ariaLabeler = "".concat(ariaLabeler, " ").concat(hintId);
  }

  if (status) {
    ariaLabeler = "".concat(ariaLabeler, " ").concat(status.id);
  }

  return /*#__PURE__*/_react.default.createElement("fieldset", {
    className: (0, _classnames.default)('usa-fieldset', _defineProperty({}, "usa-fieldset--".concat(status && status.type), status), className),
    id: id,
    "aria-labelledby": ariaLabeler,
    "aria-invalid": status && status.type === 'error',
    disabled: disabled
  }, /*#__PURE__*/_react.default.createElement("legend", {
    id: legendId
  }, /*#__PURE__*/_react.default.createElement("span", {
    className: (0, _classnames.default)({
      'usa-label': showLegend,
      'usa-sr-only': !showLegend,
      'text-bold font-sans-lg': showLegend && legendStyle === 'title'
    })
  }, legend, optional && /*#__PURE__*/_react.default.createElement("span", {
    className: "usa-hint"
  }, "\xA0(optional)"))), hint && /*#__PURE__*/_react.default.createElement("span", {
    className: "usa-hint text-italic",
    id: hintId
  }, hint), status && /*#__PURE__*/_react.default.createElement(_.FormStatus, status), /*#__PURE__*/_react.default.createElement("div", {
    className: childrenGroupClassName
  }, children));
};

exports.FieldSet = FieldSet;