"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.SecondaryActions = SecondaryActions;
var _react = _interopRequireDefault(require("react"));
var _ActionControl = require("../ActionControl/ActionControl");
var _react2 = require("@wix/bex-core/react");
var _useSelector = require("../../useSelector");
var _bi = require("@wix/bex-core/bi");
var _usePageButtonBiParams = require("../usePageButtonBiParams");
var _useIsMobile = require("../../hooks/useIsMobile");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/SecondaryActions/SecondaryActions.tsx";
function SecondaryActions({
  subItems,
  ...props
}) {
  const {
    initTask,
    reportBi
  } = (0, _react2.useWixPatternsContainer)();
  (0, _useSelector.useSelector)(() => initTask.status);
  const subItemsGrouped = subItems ? Array.isArray(subItems == null ? void 0 : subItems[0]) ? subItems : [subItems] : subItems;
  const {
    pageType,
    location
  } = (0, _usePageButtonBiParams.usePageButtonBiParams)();
  const isMobile = (0, _useIsMobile.useIsMobile)();
  return /*#__PURE__*/_react.default.createElement(_ActionControl.ActionControl, {
    priority: "secondary",
    size: isMobile ? 'small' : undefined,
    onPopoverClick: () => {
      reportBi((0, _bi.cairoPageCtaClicked)({
        location,
        pageType,
        ctaName: props.biName ?? '',
        ctaType: 'secondary page dropdown',
        additionalInfo: props.biAdditionalInfo
      }));
    },
    actionItem: {
      dataHook: 'secondary-actions',
      ...props,
      subItems: subItemsGrouped == null ? void 0 : subItemsGrouped.map(subItems => subItems == null ? void 0 : subItems.map(subItem => ({
        ...subItem,
        onClick: () => {
          reportBi((0, _bi.cairoPageCtaClicked)({
            location,
            pageType,
            ctaName: subItem.biName ?? '',
            ctaType: 'secondary page option',
            additionalInfo: subItem.biAdditionalInfo
          }));
          subItem.onClick == null || subItem.onClick();
        }
      }))),
      onClick: () => {
        reportBi((0, _bi.cairoPageCtaClicked)({
          location,
          pageType,
          ctaName: props.biName ?? '',
          ctaType: 'secondary page button',
          additionalInfo: props.biAdditionalInfo
        }));
        props.onClick == null || props.onClick();
      }
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 28,
      columnNumber: 5
    }
  });
}
//# sourceMappingURL=SecondaryActions.js.map