"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.useCollectionPageHeader = useCollectionPageHeader;
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 _PageSubTitle = require("../../components/PageSubTitle");
var _MoreActionsText = require("../../components/MoreActions/MoreActionsText");
var _useIsMobile = require("../../hooks/useIsMobile");
var _CollectionPageHeaderStCss = require("./CollectionPageHeader.st.css.js");
var _pushFactoryIfNotExistsOrAddToTopOfGroup = require("./pushFactoryIfNotExistsOrAddToTopOfGroup");
var _MoreActions = require("../../components/MoreActions");
var _react2 = require("@wix/bex-core/react");
var _PanelHeader = require("./PanelHeader");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/state/CollectionPage/useCollectionPageHeader.tsx";
const MoreActionsBySecondaryAction = (0, _mobxReactLite.observer)(({
  child
}) => {
  const pageState = (0, _providers.useCollectionPageContext)();
  const {
    primaryToolbar
  } = pageState;
  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: 23,
      columnNumber: 7
    }
  }) : undefined;
  const moreActions = child.props.moreActions ?? forceMoreActions;
  if (!moreActions) {
    return null;
  }
  const {
    type: MoreActionsElementType,
    props: moreActionsProps
  } = moreActions;
  let items = moreActionsProps.items;
  if (featuredActions) {
    for (const factory of featuredActions) {
      items = (0, _pushFactoryIfNotExistsOrAddToTopOfGroup.pushFactoryIfNotExistsOrAddToTopOfGroup)(items, factory);
    }
  }
  if (child.props.secondaryActions) {
    return /*#__PURE__*/_react.default.createElement(MoreActionsElementType, (0, _extends2.default)({}, moreActionsProps, {
      items: items,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 44,
        columnNumber: 14
      }
    }));
  }
  return /*#__PURE__*/_react.default.createElement(_MoreActionsText.MoreActionsText, (0, _extends2.default)({}, moreActionsProps, {
    items: items,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 47,
      columnNumber: 12
    }
  }));
});
function useCollectionPageHeader(child) {
  const isMobile = (0, _useIsMobile.useIsMobile)();
  const {
    isPanelLayout
  } = (0, _react2.useWixPatternsContainer)();
  if (isPanelLayout) {
    var _child$props$subtitle;
    return /*#__PURE__*/_react.default.createElement(_PanelHeader.PanelHeader, {
      title: child.props.title.text,
      subtitle: (_child$props$subtitle = child.props.subtitle) == null ? void 0 : _child$props$subtitle.text,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 57,
        columnNumber: 7
      }
    });
  }
  return /*#__PURE__*/_react.default.createElement(_designSystem.Page.Header, {
    key: child.key,
    className: (0, _CollectionPageHeaderStCss.st)(_CollectionPageHeaderStCss.classes.root, {
      mobile: isMobile
    }),
    dataHook: "collection-page-header",
    title: minimized => /*#__PURE__*/_react.default.createElement(CollectionPageHeaderTitle, {
      minimized: minimized,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 68,
        columnNumber: 29
      }
    }),
    subtitle: child.props.subtitle ? /*#__PURE__*/_react.default.createElement(_PageSubTitle.PageSubTitle, (0, _extends2.default)({}, child.props.subtitle, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 71,
        columnNumber: 11
      }
    })) : undefined,
    actionsBar: /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      gap: "SP2",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 75,
        columnNumber: 9
      }
    }, !isMobile && /*#__PURE__*/_react.default.createElement(MoreActionsBySecondaryAction, {
      child: child,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 76,
        columnNumber: 25
      }
    }), !isMobile && child.props.secondaryActions, child.props.primaryAction),
    breadcrumbs: isMobile ? () => {
      return /*#__PURE__*/_react.default.createElement("div", {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 84,
          columnNumber: 22
        }
      });
    } : child.props.breadcrumbs,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 64,
      columnNumber: 5
    }
  });
}
const CollectionPageHeaderTitle = (0, _mobxReactLite.observer)(({
  minimized
}) => {
  const state = (0, _providers.useCollectionPageContext)();
  const isMobile = (0, _useIsMobile.useIsMobile)();
  const titleContent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    inline: true,
    paddingRight: "9px",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 98,
      columnNumber: 9
    }
  }, state.pageTitle), state.total !== false && !state.hideHeaderTotal && /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    inline: true,
    color: "D40",
    dataHook: "page-header-total-count",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 102,
      columnNumber: 11
    }
  }, state.total));
  if (minimized) {
    return titleContent;
  }
  return /*#__PURE__*/_react.default.createElement(_designSystem.Heading, {
    size: isMobile ? 'large' : 'extraLarge',
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 114,
      columnNumber: 7
    }
  }, titleContent);
});
//# sourceMappingURL=useCollectionPageHeader.js.map