"use strict";

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

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

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 CommonList =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(CommonList, _React$Component);

  function CommonList() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = CommonList.prototype;

  _proto.rowClickHandler = function rowClickHandler(fn) {
    return function (event) {
      var isInsideStopper = false;
      var currentNode = event.target;
      var rootNode = event.currentTarget;
      var stopperAttribute;

      while (currentNode && currentNode !== rootNode) {
        stopperAttribute = currentNode.dataset ? currentNode.dataset.stopRowClick : currentNode.getAttribute('data-stop-row-click'); // for IE <= 10

        isInsideStopper = String(stopperAttribute).toLowerCase() === 'true';

        if (isInsideStopper) {
          break;
        } else {
          currentNode = currentNode.parentNode;
        }
      }

      if (isInsideStopper) {
        event.stopPropagation();
      } else {
        fn(event);
      }
    };
  };

  _proto.renderEmpty = function renderEmpty() {
    return this.props.noResultsText;
  };

  _proto.renderEmptyListMessage = function renderEmptyListMessage() {
    if (!this.isEmptyListMessageVisible()) {
      return null;
    }

    var _this$props = this.props,
        emptyListText = _this$props.emptyListText,
        noResultsText = _this$props.noResultsText;

    if (emptyListText && this.isEmptyList()) {
      return _react.default.createElement("div", {
        className: "grid-empty-list-message",
        "data-test-automation-id": "emptyListMessage"
      }, emptyListText);
    }

    return _react.default.createElement("div", {
      className: "grid-empty-list-message",
      "data-test-automation-id": "noResultsMessage"
    }, noResultsText);
  };

  _proto.renderBlockedMessage = function renderBlockedMessage() {
    if (this.props.isBlocked) {
      return _react.default.createElement("div", {
        className: "grid-blocked-list-container"
      }, _react.default.createElement("div", {
        className: "grid-blocked-list-message"
      }, this.props.blockedText));
    }
  };

  _proto.renderItem = function renderItem() {
    throw new Error('Overwrite renderItem method to use List');
  };

  _proto.render = function render() {
    return this.hasItems() ? this.renderItems() : this.renderEmpty();
  };

  return CommonList;
}(_react.default.Component);

exports.CommonList = CommonList;
(0, _defineProperty2.default)(CommonList, "defaultProps", {
  isBlocked: false,
  emptyListText: null,
  noResultsText: 'TRANSLATE:NO_RESULTS',
  blockedText: 'TRANSLATE:PLEASE_WAIT_WHILE_LOADING'
});
(0, _defineProperty2.default)(CommonList, "propTypes", {
  isBlocked: _propTypes.default.bool,
  emptyListText: _propTypes.default.node,
  noResultsText: _propTypes.default.node,
  blockedText: _propTypes.default.string
});