"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

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

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

var _js = require("../../globals/js");

var _iconsReact = require("@wfp/icons-react");

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var prefix = _js.settings.prefix;
/*
import {
  CheckmarkOutline32,
  WarningAlt32,
  Information32,
} from '@carbon/icons-react';
*/

var iconLookup = {
  warning: {
    icon: _iconsReact.WarningAlt32
  },
  error: {
    icon: _iconsReact.WarningSolidGlyph
  },
  info: {
    icon: _iconsReact.InfoSolidGlyph
  },
  success: {
    icon: _iconsReact.CheckmarkGlyph
  }
};
/**
 *  The Blockquote element indicates that the enclosed text is an extended quotation or information. It is rendered visually by a surrounding box. */

var Blockquote = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2.default)(Blockquote, _React$Component);

  var _super = _createSuper(Blockquote);

  function Blockquote(props) {
    var _this;

    (0, _classCallCheck2.default)(this, Blockquote);
    _this = _super.call(this, props);
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "toggleBlockquote", function () {
      if (_this.props.toggleable) _this.setState({
        open: !_this.state.open
      });
    });
    _this.state = {
      open: false
    };
    return _this;
  }

  (0, _createClass2.default)(Blockquote, [{
    key: "render",
    value:
    /*showInnerHtml = content => {
      return { __html: content };
    };*/
    function render() {
      var _classNames;

      var _this$props = this.props,
          actionButtons = _this$props.actionButtons,
          className = _this$props.className,
          contentClassName = _this$props.contentClassName,
          children = _this$props.children,
          error = _this$props.error,
          style = _this$props.style,
          title = _this$props.title,
          toggleable = _this$props.toggleable,
          icon = _this$props.icon,
          light = _this$props.light,
          code = _this$props.code,
          warning = _this$props.warning,
          withIcon = _this$props.withIcon,
          info = _this$props.info,
          kind = _this$props.kind;
      var blockquoteClass = (0, _classnames.default)((_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote"), true), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--toggleable"), toggleable), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--light"), light), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--code"), code), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--no-content"), !children), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--error"), kind === 'error' || error), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--warning"), kind === 'warning' || warning), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--success"), kind === 'success'), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--info"), kind === 'info' || info), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--with-icon"), withIcon || icon), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--blockquote--toggle--open"), this.state.open), (0, _defineProperty2.default)(_classNames, "".concat(className), className), _classNames));
      var blockquoteContentClass = (0, _classnames.default)("".concat(prefix, "--blockquote__content"), (0, _defineProperty2.default)({}, "".concat(className), contentClassName)); // @deprecated Only kind is allowed

      var lookup = warning || kind === 'warning' ? iconLookup['warning'] : error || kind === 'error' ? iconLookup['error'] : kind === 'success' ? iconLookup['success'] : iconLookup['info'];
      var Icon = lookup.icon;
      var iconElement = /*#__PURE__*/_react.default.isValidElement(icon) ? /*#__PURE__*/_react.default.createElement("div", {
        className: "".concat(prefix, "--blockquote__icon ").concat(prefix, "--blockquote__icon--custom")
      }, icon) : withIcon || icon ? /*#__PURE__*/_react.default.createElement(Icon, {
        width: 48,
        height: 48,
        description: "Blockquote Icon",
        className: "".concat(prefix, "--blockquote__icon")
      }) : null;
      return /*#__PURE__*/_react.default.createElement("div", {
        className: blockquoteClass
      }, iconElement && /*#__PURE__*/_react.default.createElement("div", {
        className: "".concat(prefix, "--blockquote__icon-wrapper")
      }, iconElement), /*#__PURE__*/_react.default.createElement("div", {
        className: blockquoteContentClass,
        style: style
      }, (title || toggleable) && /*#__PURE__*/_react.default.createElement("div", {
        onClick: this.toggleBlockquote,
        onKeyDown: this.toggleBlockquote,
        className: "".concat(prefix, "--blockquote__title"),
        role: "button",
        tabIndex: 0
      }, title ? title : this.state.open ? 'Hide content' : 'Show content'), /*#__PURE__*/_react.default.createElement("div", {
        className: "".concat(prefix, "--blockquote__inside")
      }, children)), actionButtons && /*#__PURE__*/_react.default.createElement("div", {
        className: "wfp--blockquote__action-buttons"
      }, actionButtons));
    }
  }]);
  return Blockquote;
}(_react.default.Component);

Blockquote.propTypes = {
  /**
   * Specify a className of your `Blockquote`
   */
  className: _propTypes.default.string,

  /**
   * Specify the content of your `Blockquote`
   */
  children: _propTypes.default.node,

  /**
   * Show content formated as code
   */
  code: _propTypes.default.bool,

  /**
   * Display light version of Blockquote
   */
  light: _propTypes.default.bool,

  /**
   * Show options to show and hide the Blockquote when title is clicked
   */
  toggleable: _propTypes.default.bool,

  /**
   * Show title for Blockquote
   */
  title: _propTypes.default.node,

  /**
   * Specify the type of your Blockquote Options are `info` `error` `warning` `info`
   */
  kind: _propTypes.default.oneOf(['info', 'warning', 'error', 'success']),

  /**
   * Specify if an Icon should be displayed
   */
  withIcon: _propTypes.default.bool,

  /**
   * Specify a custom icon. Can be either a `Icon` object or React component
   */
  icon: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.object])
};
var _default = Blockquote;
exports.default = _default;