"use strict";

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

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

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

;

var Button = function Button(props) {
  var content = props.content,
      onClick = props.onClick,
      rawData = props.rawData,
      rawIndex = props.rawIndex,
      visible = props.visible,
      _a = props.cancelBubble,
      cancelBubble = _a === void 0 ? false : _a,
      _b = props.disabled,
      disabled = _b === void 0 ? false : _b;
  var handler;
  var isVisible = true;
  var Component = content;
  var data = {
    item: rawData,
    index: rawIndex
  };

  if ( /*#__PURE__*/_react["default"].isValidElement(Component)) {
    Component = /*#__PURE__*/_react["default"].cloneElement(Component, {
      disabled: disabled
    });
  } else if (typeof Component === 'function') {
    Component = Component(data, disabled);
  }

  if (typeof visible === 'function') {
    isVisible = visible(data);
  }

  if (typeof visible === 'boolean') {
    isVisible = visible;
  }

  handler = function handler(e) {
    if (cancelBubble) {
      e.stopPropagation();
    }

    if (!disabled && onClick) {
      onClick(e, rawData, rawIndex);
    }
  };

  if (isVisible) {
    return /*#__PURE__*/_react["default"].createElement("span", {
      className: (0, _classnames["default"])(disabled && 'lp-datagrid-actions-disabled', 'lp-datagrid-actions'),
      onClick: handler
    }, Component);
  }

  return null;
};

var _default = Button;
exports["default"] = _default;