import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import { filterKeyCodes } from '../../utils/functions';
import { CatalogItemIcon } from './CatalogItemIcon';
import { CatalogSimplePrice } from './CatalogSimplePrice';
export var CatalogGridItem =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(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;

    _defineProperty(_assertThisInitialized(_this), "handleKeyDown", 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.createElement(CatalogSimplePrice, {
        isCentered: true,
        pricePurchase: pricePurchase,
        priceAnnual: priceAnnual,
        priceMonthly: priceMonthly,
        isPriceFrom: isPriceFrom
      });
    }

    return React.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.isValidElement(icon)) {
      return icon;
    }

    return React.createElement(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.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.createElement("div", {
      className: "rc-catalog-grid-item__name",
      "data-test-automation-id": "name"
    }, name), this.renderDescription());
  };

  return CatalogGridItem;
}(React.PureComponent);

_defineProperty(CatalogGridItem, "propTypes", {
  testAutomationId: PropTypes.string,
  name: PropTypes.string.isRequired,
  description: PropTypes.string,
  icon: PropTypes.string,
  color: PropTypes.string,
  onClick: PropTypes.func,
  price: PropTypes.shape({
    pricePurchase: PropTypes.object,
    priceAnnual: PropTypes.object,
    priceMonthly: PropTypes.object,
    isPriceFrom: PropTypes.bool
  })
});

_defineProperty(CatalogGridItem, "defaultProps", {
  testAutomationId: 'catalogGridItem',
  description: null,
  icon: null,
  color: null,
  price: null,
  onClick: function onClick() {}
});