"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CollectionPage = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _useCollectionPageChild = require("../../hooks/useCollectionPageChild");
var _CollectionPageHeaderNew = require("../CollectionPageHeaderNew");
var _PageWrapper = require("../PageWrapper");
var _CollectionPageContent = require("../CollectionPageContent");
var _mobxReactLite = require("mobx-react-lite");
var _providers = require("../../providers");
var _usePageHeaderNew = require("../../hooks/usePageHeaderNew");
var _CollectionPageStCss = require("./CollectionPage.st.css.js");
var _react2 = require("@wix/bex-core/react");
var _useCollectionPageLoadReporting = require("./useCollectionPageLoadReporting");
var _useIsMobile = require("../../hooks/useIsMobile");
var _CollectionPageFooter = require("../CollectionPageFooter");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CollectionPageNew/CollectionPage.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _CollectionPage({
  children,
  scrollableContentRef,
  ...rest
}) {
  const wrappedChildren = (0, _useCollectionPageChild.useCollectionPageChild)(children);
  const childrenArr = _react.default.Children.toArray(children);
  const {
    title: pageTitle,
    hideTotal: hideHeaderTotal,
    header
  } = (0, _usePageHeaderNew.usePageHeader)(childrenArr);
  const container = (0, _react2.useWixPatternsContainer)();
  const [reportBI] = (0, _react.useState)(() => container.createBILogger({
    componentType: 'Collection page',
    pageType: 'Collection',
    route: window.location.pathname
  }));
  const collectionPageState = (0, _react2.useCollectionPageState)({
    reportBI,
    pageTitle,
    hasHeader: header != null,
    hideHeaderTotal
  });
  (0, _react.useEffect)(() => collectionPageState.init(), []);
  (0, _useCollectionPageLoadReporting.useCollectionPageLoadReporting)({
    startTime: collectionPageState.startTime,
    withinRouter: !!collectionPageState.withinRouter
  });
  const isMobile = (0, _useIsMobile.useIsMobile)();
  let child;
  if (container.isPanelLayout) {
    child = /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      direction: "vertical",
      className: (0, _CollectionPageStCss.st)(_CollectionPageStCss.classes.root, {
        panel: true
      }),
      width: "100%",
      height: "100%",
      flex: 1,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 71,
        columnNumber: 7
      }
    }, wrappedChildren);
  } else {
    child = /*#__PURE__*/_react.default.createElement(_PageWrapper.PageWrapperBase, {
      pageState: collectionPageState.pageState,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 85,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Page, (0, _extends2.default)({
      className: (0, _CollectionPageStCss.st)(_CollectionPageStCss.classes.root, {
        mobile: isMobile
      }),
      scrollableContentRef: el => {
        collectionPageState.pageState.scrollableContentRef.current = el;
        scrollableContentRef == null || scrollableContentRef(el);
      }
    }, rest, {
      minWidth: isMobile ? 0 : undefined,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 86,
        columnNumber: 9
      }
    }), wrappedChildren));
  }
  return /*#__PURE__*/_react.default.createElement(_providers.CollectionPageContextProvider, {
    value: collectionPageState,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 102,
      columnNumber: 5
    }
  }, child);
}
_CollectionPage.Header = _CollectionPageHeaderNew.CollectionPageHeader;
_CollectionPage.Content = _CollectionPageContent.CollectionPageContent;
_CollectionPage.Footer = _CollectionPageFooter.CollectionPageFooter;
_CollectionPage.displayName = 'CollectionPage';
const CollectionPage = exports.CollectionPage = (0, _mobxReactLite.observer)(_CollectionPage);
//# sourceMappingURL=CollectionPage.js.map