"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CollectionItemActions = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _ActionModal = require("../ActionModal");
var _DisabledActionCellMenu = require("../ActionCell/DisabledActionCellMenu");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _CollectionItemActionsHelper = require("./CollectionItemActionsHelper");
var _getDefaultActionCellProps = require("./getDefaultActionCellProps");
var _useExtensionMenuItems = require("../../hooks/useExtensionMenuItems");
var _useIsMobile = require("../../hooks/useIsMobile");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CollectionItemActions/CollectionItemActions.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (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 (const 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 _CollectionItemActions({
  state,
  renderActionCell
}) {
  const isMobile = (0, _useIsMobile.useIsMobile)();
  const {
    confirmModal
  } = state;
  const toolbarState = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const {
    toolbarBIReporter
  } = toolbarState;
  const actionCellProps = (renderActionCell == null ? void 0 : renderActionCell(state)) ?? {};
  const {
    secondaryMenuDisabled,
    secondaryMenuDisabledTooltip,
    ...tableActionCellProps
  } = actionCellProps;
  const keyedItem = state.actionCellAPI.keyedItem;
  const existingExtension = actionCellProps.containerId ? toolbarState.menuItemExtensions.get(actionCellProps.containerId) : undefined;
  const extensionMenuItems = (0, _useExtensionMenuItems.useExtensionMenuItems)({
    containerId: actionCellProps.containerId,
    extension: existingExtension
  });
  (0, _react.useEffect)(() => {
    if (extensionMenuItems && actionCellProps.containerId) {
      toolbarState.menuItemExtensions.set(actionCellProps.containerId, extensionMenuItems);
    }
  }, [extensionMenuItems, actionCellProps.containerId]);
  if (secondaryMenuDisabled) {
    return /*#__PURE__*/_react.default.createElement(_DisabledActionCellMenu.DisabledActionCellMenu, {
      dataHook: "collection-action-cell-disabled",
      tooltipContent: secondaryMenuDisabledTooltip ?? toolbarState.container.translate('cairo.disabled'),
      size: actionCellProps.size ?? 'medium',
      ariaLabel: toolbarState.container.translate('cairo.moreActions'),
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 65,
        columnNumber: 7
      }
    });
  }
  const secondaryActionCellPropsWithBI = (0, _CollectionItemActionsHelper.createSecondaryActionCellPropWithBi)({
    toolbarBIReporter,
    actionCellProps,
    keyedItem,
    extensionMenuItems
  });
  let primaryActionCellPropsWithBI = !isMobile ? (0, _CollectionItemActionsHelper.createPrimaryActionCellPropsWithBI)(toolbarBIReporter, actionCellProps, keyedItem) : [];
  if (Array.isArray(primaryActionCellPropsWithBI) && primaryActionCellPropsWithBI.length > 1) {
    primaryActionCellPropsWithBI = primaryActionCellPropsWithBI.map((action, index) => {
      return {
        ...action,
        priority: index === primaryActionCellPropsWithBI.length - 1 ? 'primary' : 'secondary'
      };
    });
  }
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, confirmModal.value && /*#__PURE__*/_react.default.createElement(_ActionModal.MessageActionModal, (0, _extends2.default)({
    state: confirmModal
  }, confirmModal.value, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 115,
      columnNumber: 9
    }
  })), /*#__PURE__*/_react.default.createElement(_designSystem.TableActionCell, (0, _extends2.default)({
    dataHook: "collection-action-cell"
  }, tableActionCellProps, {
    popoverMenuProps: {
      ...(0, _getDefaultActionCellProps.getDefaultActionCellProps)(),
      onShow: () => (0, _CollectionItemActionsHelper.reportOnPopoverMenuShow)(toolbarBIReporter, actionCellProps, state.keyedItem),
      ...actionCellProps.popoverMenuProps,
      ...(0, _getDefaultActionCellProps.getDefaultActionCellProps)()
    },
    primaryAction: primaryActionCellPropsWithBI,
    secondaryActions: secondaryActionCellPropsWithBI,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 117,
      columnNumber: 7
    }
  })));
}
const CollectionItemActions = exports.CollectionItemActions = (0, _mobxReactLite.observer)(_CollectionItemActions);
//# sourceMappingURL=CollectionItemActions.js.map