"use strict";

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _ReviewLink = _interopRequireDefault(require("./ReviewLink"));

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

var _i18n = require("../i18n");

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

var getHeading = function getHeading(heading, headingLevel) {
  var Heading = "h".concat(headingLevel) || "h3";

  if (heading) {
    return /*#__PURE__*/_react.default.createElement(Heading, {
      className: "ds-c-review__heading"
    }, heading);
  }
};

var Review = function Review(props) {
  var _props$editText;

  var classes = (0, _classnames.default)('ds-c-review', props.className);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: classes
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "ds-c-review__content"
  }, getHeading(props.heading, props.headingLevel), /*#__PURE__*/_react.default.createElement("div", {
    className: "ds-c-review__body"
  }, props.children)), props.editContent, !props.editContent && props.editHref && /*#__PURE__*/_react.default.createElement(_ReviewLink.default, {
    onClick: props.onEditClick,
    href: props.editHref,
    ariaLabel: props.editAriaLabel
  }, (_props$editText = props.editText) !== null && _props$editText !== void 0 ? _props$editText : (0, _i18n.t)('review.editText')));
};

exports.Review = Review;
Review.propTypes = {
  /**
     * `Review` component's body content.
     */
  children: _propTypes.default.node.isRequired,
  className: _propTypes.default.string,

  /**
     * Optional label to give screenreaders longer, more descriptive text to
     * explain the context of an edit link.
     */
  editAriaLabel: _propTypes.default.string,

  /**
     * An optional node in place of the edit link. If this defined, no edit link will be shown.
     */
  editContent: _propTypes.default.node,

  /**
     * Href for the edit link. If this is undefined, no edit link will be shown.
     */
  editHref: _propTypes.default.string,
  editText: _propTypes.default.node,
  heading: _propTypes.default.node,

  /**
     * Heading type to override default `<h3>`.
     */
  headingLevel: _propTypes.default.oneOf(['1', '2', '3', '4', '5']),

  /**
     * An optional function that is executed on edit link click. The event and
     * props.editHref value are passed to this function.
     */
  onEditClick: _propTypes.default.func
};
Review.defaultProps = {
  headingLevel: '3'
};
var _default = Review;
exports.default = _default;