"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.StageActions = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _designSystem = require("@wix/design-system");
var _mobxReactLite = require("mobx-react-lite");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _getDefaultActionCellProps = require("../CollectionItemActions/getDefaultActionCellProps");
var _state = require("../../state");
var _ActionModal = require("../ActionModal");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/Kanban/StageActions.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 _StageActions({
  state,
  stageKey,
  stageActionCell
}) {
  const keyedItem = state.stagesCollectionState.getKeyedItem(stageKey);
  const stageActionsState = (0, _react.useMemo)(() => {
    if (!keyedItem) {
      return null;
    }
    return new _state.ItemActionsState({
      keyedItem,
      fade: 'static',
      collection: state.stagesCollectionState,
      reportBi: state.toolbar.reportBi
    });
  }, [keyedItem, state.stagesCollectionState, state.toolbar.reportBi]);
  if (!keyedItem || !stageActionsState) {
    return null;
  }
  const resolvedActionCell = typeof stageActionCell === 'function' ? stageActionCell(keyedItem.item, keyedItem.indexWithinPage, stageActionsState.actionCellAPI) : stageActionCell;
  const secondaryActions = resolvedActionCell == null ? void 0 : resolvedActionCell.secondaryActions;
  if (!(secondaryActions != null && secondaryActions.length)) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, stageActionsState.confirmModal.value && /*#__PURE__*/_react.default.createElement(_ActionModal.MessageActionModal, (0, _extends2.default)({
    state: stageActionsState.confirmModal
  }, stageActionsState.confirmModal.value, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 65,
      columnNumber: 9
    }
  })), /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu, (0, _extends2.default)({}, (0, _getDefaultActionCellProps.getDefaultActionCellProps)(), {
    textSize: "small",
    minWidth: "223px",
    dataHook: `kanban-stage-more-actions-${stageKey}`,
    triggerElement: ({
      toggle
    }) => {
      return /*#__PURE__*/_react.default.createElement(_designSystem.IconButton, {
        skin: "dark",
        priority: "tertiary",
        size: "small",
        dataHook: `kanban-stage-more-actions-trigger-${stageKey}`,
        onClick: e => {
          e.stopPropagation();
          toggle();
        },
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 77,
          columnNumber: 13
        }
      }, /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.MoreSmall, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 87,
          columnNumber: 15
        }
      }));
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 70,
      columnNumber: 7
    }
  }), secondaryActions.map((secondaryAction, index) => {
    if (secondaryAction.divider) {
      return /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.Divider, {
        key: index,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 94,
          columnNumber: 20
        }
      });
    }
    const action = secondaryAction;
    const {
      icon: prefixIcon,
      skin,
      ...rest
    } = action;
    return /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.MenuItem, (0, _extends2.default)({
      key: index,
      dataHook: `kanban-stage-more-actions-item-${stageKey}`,
      skin: skin,
      prefixIcon: prefixIcon
    }, rest, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 100,
        columnNumber: 13
      }
    }));
  })));
}
const StageActions = exports.StageActions = (0, _mobxReactLite.observer)(_StageActions);
//# sourceMappingURL=StageActions.js.map