import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
export var CommonList =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(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.createElement("div", {
        className: "grid-empty-list-message",
        "data-test-automation-id": "emptyListMessage"
      }, emptyListText);
    }

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

  _proto.renderBlockedMessage = function renderBlockedMessage() {
    if (this.props.isBlocked) {
      return React.createElement("div", {
        className: "grid-blocked-list-container"
      }, React.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.Component);

_defineProperty(CommonList, "defaultProps", {
  isBlocked: false,
  emptyListText: null,
  noResultsText: 'TRANSLATE:NO_RESULTS',
  blockedText: 'TRANSLATE:PLEASE_WAIT_WHILE_LOADING'
});

_defineProperty(CommonList, "propTypes", {
  isBlocked: PropTypes.bool,
  emptyListText: PropTypes.node,
  noResultsText: PropTypes.node,
  blockedText: PropTypes.string
});