"use strict";

exports.__esModule = true;
exports.reportOnKanbanPopoverMenuShow = exports.createKanbanSecondaryActionCellPropsWithBI = exports.createKanbanPrimaryActionCellPropsWithBI = void 0;
var _react = require("react");
var _mobx = require("mobx");
var _KanbanStateBIReporter = require("../../state/KanbanState/KanbanStateBIReporter");
const calcCtaCount = actionCellProps => {
  const {
    secondaryActions
  } = actionCellProps;
  return (secondaryActions == null ? void 0 : secondaryActions.length) || 0;
};
const createKanbanSecondaryActionCellPropsWithBI = ({
  state,
  actionCellProps,
  keyedItem,
  extensionMenuItems,
  stageId
}) => {
  const {
    secondaryActions = []
  } = actionCellProps;
  const stageIndex = state.getStageIndexByKey(stageId);
  const stageName = state.getStageNameByKey(stageId);
  const moreSecondaryItems = (extensionMenuItems == null ? void 0 : extensionMenuItems.menuItems.map(menuItem => {
    return {
      ...menuItem,
      icon: menuItem.prefixIcon || /*#__PURE__*/(0, _react.createElement)('div')
    };
  })) || [];
  const allActions = [...secondaryActions, ...moreSecondaryItems];
  return allActions.map((_action, index) => {
    const biIndex = index;
    if (_action.divider) {
      return _action;
    }
    const onClick = (0, _mobx.action)(() => {
      state.kanbanStateBIReporter.reportCardCTAClicked({
        itemId: keyedItem.id,
        itemIndex: keyedItem.index,
        ctaName: _action.biName || _action.text || 'Secondary Action',
        ctaType: _KanbanStateBIReporter.KanbanCtaType.MORE_ACTIONS_OPTION,
        stageIndex,
        stageId,
        stageName,
        ctaIndex: biIndex,
        numCtas: calcCtaCount(actionCellProps)
      });
      _action.onClick == null || _action.onClick();
    });
    const {
      biName: _biName,
      ...secondaryActionProperties
    } = _action;
    return {
      ...secondaryActionProperties,
      onClick
    };
  }) || [];
};
exports.createKanbanSecondaryActionCellPropsWithBI = createKanbanSecondaryActionCellPropsWithBI;
const createKanbanPrimaryActionCellPropsWithBI = ({
  state,
  actionCellProps,
  keyedItem,
  stageId
}) => {
  const {
    primaryAction
  } = actionCellProps;
  const stageIndex = state.getStageIndexByKey(stageId);
  const stageName = state.getStageNameByKey(stageId);
  if (primaryAction && !Array.isArray(primaryAction)) {
    const onClick = (0, _mobx.action)(() => {
      state.kanbanStateBIReporter.reportCardCTAClicked({
        itemId: keyedItem.id,
        itemIndex: keyedItem.index,
        ctaName: (primaryAction == null ? void 0 : primaryAction.biName) || (primaryAction == null ? void 0 : primaryAction.text) || 'Primary Action',
        ctaType: _KanbanStateBIReporter.KanbanCtaType.PRIMARY_BUTTON,
        stageId,
        stageIndex,
        stageName
      });
      primaryAction == null || primaryAction.onClick();
    });
    const {
      biName,
      ...primaryActionProperties
    } = primaryAction;
    return {
      ...primaryActionProperties,
      onClick
    };
  }
  return primaryAction;
};
exports.createKanbanPrimaryActionCellPropsWithBI = createKanbanPrimaryActionCellPropsWithBI;
const reportOnKanbanPopoverMenuShow = ({
  state,
  keyedItem,
  stageId
}) => {
  const stageIndex = state.getStageIndexByKey(stageId);
  const stageName = state.getStageNameByKey(stageId);
  state.kanbanStateBIReporter.reportCardCTAClicked({
    itemId: keyedItem.id,
    itemIndex: keyedItem.index,
    ctaName: 'More Actions',
    ctaType: _KanbanStateBIReporter.KanbanCtaType.SECONDARY_DROPDOWN,
    stageId,
    stageIndex,
    stageName
  });
};
exports.reportOnKanbanPopoverMenuShow = reportOnKanbanPopoverMenuShow;
//# sourceMappingURL=KanbanCardActionsHelper.js.map