import _pt from "prop-types";
import React from 'react';
import ReviewLink from './ReviewLink';
import classNames from 'classnames';
import { t } from '../i18n';

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

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

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

  var classes = classNames('ds-c-review', props.className);
  return /*#__PURE__*/React.createElement("div", {
    className: classes
  }, /*#__PURE__*/React.createElement("div", {
    className: "ds-c-review__content"
  }, getHeading(props.heading, props.headingLevel), /*#__PURE__*/React.createElement("div", {
    className: "ds-c-review__body"
  }, props.children)), props.editContent, !props.editContent && props.editHref && /*#__PURE__*/React.createElement(ReviewLink, {
    onClick: props.onEditClick,
    href: props.editHref,
    ariaLabel: props.editAriaLabel
  }, (_props$editText = props.editText) !== null && _props$editText !== void 0 ? _props$editText : t('review.editText')));
};
Review.propTypes = {
  /**
     * `Review` component's body content.
     */
  children: _pt.node.isRequired,
  className: _pt.string,

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

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

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

  /**
     * Heading type to override default `<h3>`.
     */
  headingLevel: _pt.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: _pt.func
};
Review.defaultProps = {
  headingLevel: '3'
};
export default Review;