"use strict";

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