"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var Actions = _interopRequireWildcard(require("../../../actions"));
var _excluded = ["name", "hideContent", "hideIcon", "onClick", "isDisabled"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var ActionGroupItem = function ActionGroupItem(_ref) {
  var item = _ref.item,
    size = _ref.size,
    appearance = _ref.appearance,
    asDropDownItems = _ref.asDropDownItems,
    onActionItemClick = _ref.onActionItemClick;
  var name = item.name,
    hideContent = item.hideContent,
    hideIcon = item.hideIcon,
    onClick = item.onClick,
    isDisabled = item.isDisabled,
    props = (0, _objectWithoutProperties2.default)(item, _excluded);
  var handleOnClick = (0, _react.useCallback)(function () {
    if (onActionItemClick) {
      onActionItemClick();
    }
    if (onClick) {
      onClick();
    }
  }, [onActionItemClick, onClick]);
  var Action = name in Actions ? Actions[name] : undefined;
  if (!Action) {
    return null;
  }
  var actionProps = _objectSpread({}, props);
  if (hideContent && !asDropDownItems) {
    actionProps.content = '';
  }
  if (hideIcon) {
    actionProps.icon = undefined;
  }
  if (item !== null && item !== void 0 && item.entryPointWrapper) {
    actionProps.wrapper = item.entryPointWrapper;
  }
  return /*#__PURE__*/_react.default.createElement(Action, (0, _extends2.default)({
    asDropDownItem: asDropDownItems,
    size: size,
    appearance: appearance,
    onClick: handleOnClick,
    isDisabled: isDisabled
  }, actionProps));
};
var _default = exports.default = ActionGroupItem;