"use strict";

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

exports.__esModule = true;
exports.CatalogGridItem = void 0;

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

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

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

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

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

var _functions = require("../../utils/functions");

var _CatalogItemIcon = require("./CatalogItemIcon");

var _CatalogSimplePrice = require("./CatalogSimplePrice");

var CatalogGridItem =
/*#__PURE__*/
function (_React$PureComponent) {
  (0, _inheritsLoose2.default)(CatalogGridItem, _React$PureComponent);

  function CatalogGridItem() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleKeyDown", (0, _functions.filterKeyCodes)(_this.props.onClick));
    return _this;
  }

  var _proto = CatalogGridItem.prototype;

  _proto.renderDescription = function renderDescription() {
    var _this$props = this.props,
        description = _this$props.description,
        price = _this$props.price;

    if (!description && !price) {
      return null;
    }

    if (price) {
      var pricePurchase = price.pricePurchase,
          priceAnnual = price.priceAnnual,
          priceMonthly = price.priceMonthly,
          isPriceFrom = price.isPriceFrom;
      return _react.default.createElement(_CatalogSimplePrice.CatalogSimplePrice, {
        isCentered: true,
        pricePurchase: pricePurchase,
        priceAnnual: priceAnnual,
        priceMonthly: priceMonthly,
        isPriceFrom: isPriceFrom
      });
    }

    return _react.default.createElement("div", {
      className: "rc-catalog-grid-item__desc",
      "data-test-automation-id": "description"
    }, description);
  };

  _proto.renderIcon = function renderIcon() {
    var _this$props2 = this.props,
        icon = _this$props2.icon,
        color = _this$props2.color;

    if (_react.default.isValidElement(icon)) {
      return icon;
    }

    return _react.default.createElement(_CatalogItemIcon.CatalogItemIcon, {
      isRound: true,
      size: 90,
      iconName: icon,
      backgroundColor: color
    });
  };

  _proto.render = function render() {
    var _this$props3 = this.props,
        testAutomationId = _this$props3.testAutomationId,
        name = _this$props3.name,
        onClick = _this$props3.onClick;
    return _react.default.createElement("div", {
      "data-test-automation-id": testAutomationId,
      className: "rc-catalog-grid-item__block",
      role: "button",
      onClick: onClick,
      onKeyDown: this.handleKeyDown,
      tabIndex: 0
    }, this.renderIcon(), _react.default.createElement("div", {
      className: "rc-catalog-grid-item__name",
      "data-test-automation-id": "name"
    }, name), this.renderDescription());
  };

  return CatalogGridItem;
}(_react.default.PureComponent);

exports.CatalogGridItem = CatalogGridItem;
(0, _defineProperty2.default)(CatalogGridItem, "propTypes", {
  testAutomationId: _propTypes.default.string,
  name: _propTypes.default.string.isRequired,
  description: _propTypes.default.string,
  icon: _propTypes.default.string,
  color: _propTypes.default.string,
  onClick: _propTypes.default.func,
  price: _propTypes.default.shape({
    pricePurchase: _propTypes.default.object,
    priceAnnual: _propTypes.default.object,
    priceMonthly: _propTypes.default.object,
    isPriceFrom: _propTypes.default.bool
  })
});
(0, _defineProperty2.default)(CatalogGridItem, "defaultProps", {
  testAutomationId: 'catalogGridItem',
  description: null,
  icon: null,
  color: null,
  price: null,
  onClick: function onClick() {}
});