"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CollectionPageActionsBar = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _designSystem = require("@wix/design-system");
var _providers = require("../../providers");
var _mobxReactLite = require("mobx-react-lite");
var _MoreActionsText = require("../../components/MoreActions/MoreActionsText");
var _useIsMobile = require("../../hooks/useIsMobile");
var _pushFactoryIfNotExistsOrAddToTopOfGroup = require("./pushFactoryIfNotExistsOrAddToTopOfGroup");
var _transformSecondaryActionsToMoreActions = require("./transformSecondaryActionsToMoreActions");
var _MoreActions = require("../../components/MoreActions");
var _react2 = require("@wix/bex-core/react");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/state/CollectionPage/CollectionPageActionsBar.tsx";
function withFeaturedActions(items, featuredActions) {
  if (!featuredActions) {
    return items;
  }
  let result = items;
  for (const factory of featuredActions) {
    result = (0, _pushFactoryIfNotExistsOrAddToTopOfGroup.pushFactoryIfNotExistsOrAddToTopOfGroup)(result, factory);
  }
  return result;
}
const WideModeMoreActions = (0, _mobxReactLite.observer)(({
  child
}) => {
  const {
    primaryToolbar
  } = (0, _providers.useCollectionPageContext)();
  const featuredActions = primaryToolbar == null ? void 0 : primaryToolbar.getPageFeaturedActions();
  const forceMoreActions = featuredActions != null && featuredActions.length ? /*#__PURE__*/_react.default.createElement(_MoreActions.MoreActions, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 37,
      columnNumber: 7
    }
  }) : undefined;
  const moreActions = child.props.moreActions ?? forceMoreActions;
  if (!moreActions) {
    return null;
  }
  const {
    type: MoreActionsType,
    props: moreActionsProps
  } = moreActions;
  const items = withFeaturedActions(moreActionsProps.items, featuredActions);
  if (child.props.secondaryActions) {
    return /*#__PURE__*/_react.default.createElement(MoreActionsType, (0, _extends2.default)({}, moreActionsProps, {
      items: items,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 49,
        columnNumber: 14
      }
    }));
  }
  return /*#__PURE__*/_react.default.createElement(_MoreActionsText.MoreActionsText, (0, _extends2.default)({}, moreActionsProps, {
    items: items,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 52,
      columnNumber: 12
    }
  }));
});
const NarrowModeMoreActions = (0, _mobxReactLite.observer)(({
  child
}) => {
  var _child$props$moreActi;
  const {
    primaryToolbar
  } = (0, _providers.useCollectionPageContext)();
  const featuredActions = primaryToolbar == null ? void 0 : primaryToolbar.getPageFeaturedActions();
  const moreActionsProps = (_child$props$moreActi = child.props.moreActions) == null ? void 0 : _child$props$moreActi.props;
  const moreActionsItems = withFeaturedActions(moreActionsProps == null ? void 0 : moreActionsProps.items, featuredActions);
  const items = (0, _transformSecondaryActionsToMoreActions.mergeActionsForNarrowMode)(child.props.secondaryActions, moreActionsItems);
  if (items.length === 0) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_MoreActions.MoreActions, {
    items: items,
    containerId: moreActionsProps == null ? void 0 : moreActionsProps.containerId,
    exploreAppsModalProps: moreActionsProps == null ? void 0 : moreActionsProps.exploreAppsModalProps,
    biAdditionalInfo: moreActionsProps == null ? void 0 : moreActionsProps.biAdditionalInfo,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 77,
      columnNumber: 7
    }
  });
});
const CollectionPageActionsBar = exports.CollectionPageActionsBar = (0, _mobxReactLite.observer)(({
  child
}) => {
  const isMobile = (0, _useIsMobile.useIsMobile)();
  const {
    isNarrow
  } = (0, _providers.useCollectionPageContext)();
  const {
    internalExperiments
  } = (0, _react2.useWixPatternsContainer)();
  const isNarrowMode = isNarrow && (internalExperiments == null ? void 0 : internalExperiments.enabled('specs.cairo.CollectionPageMinWidth'));
  if (isMobile) {
    return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      gap: "SP2",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 98,
        columnNumber: 14
      }
    }, child.props.primaryAction);
  }
  if (isNarrowMode) {
    return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      gap: "SP2",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 103,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement(NarrowModeMoreActions, {
      child: child,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 104,
        columnNumber: 11
      }
    }), child.props.primaryAction);
  }
  return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    gap: "SP2",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 111,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(WideModeMoreActions, {
    child: child,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 112,
      columnNumber: 9
    }
  }), child.props.secondaryActions, child.props.primaryAction);
});
//# sourceMappingURL=CollectionPageActionsBar.js.map