"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CollectionCard = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireDefault(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _CollectionContext = require("../CollectionContext");
var _ActionModal = require("../ActionModal");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _NavigationModal = require("../NavigationModal");
var _WixPatternsModalsContainer = require("../WixPatternsModalsContainer");
var _providers = require("../../providers");
var _MultiCollectionSupportProvider = require("../MultiCollectionSupportProvider");
var _commonStCss = require("../common.st.css.js");
var _ErrorState = require("../ErrorState");
var _WixPatternsPanelModalsContainer = require("../WixPatternsPanelModalsContainer");
var _react2 = require("@wix/bex-core/react");
var _DeleteFieldModal = require("../ArchivedItemsPanel/DeleteFieldModal");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CollectionCard/CollectionCard.tsx";
function _CollectionCard({
  state,
  errorState,
  children,
  tags,
  ...rest
}) {
  const page = (0, _providers.usePageContext)();
  const {
    isPanelLayout,
    useRelativeSidePanel
  } = (0, _react2.useWixPatternsContainer)();
  const {
    modalsContainerRef,
    stackingRootRef
  } = page;
  const {
    collection,
    initTask,
    bulk,
    AddApplyFiltersButton,
    collectionDataExtension,
    tagsCollectionState
  } = state;
  const {
    modals
  } = bulk;
  const {
    actionModal
  } = modals;
  const {
    status: initTaskStatus
  } = initTask;
  let child;
  if (initTaskStatus.isError && errorState !== false) {
    child = /*#__PURE__*/_react.default.createElement(_ErrorState.ErrorState, {
      errorStatus: initTaskStatus,
      errorState: errorState,
      dataHook: "collection-card-error-state",
      state: state,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 69,
        columnNumber: 7
      }
    });
  } else {
    child = children;
    child = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, child, actionModal.value && /*#__PURE__*/_react.default.createElement(_ActionModal.MessageActionModal, (0, _extends2.default)({
      state: actionModal
    }, actionModal.value, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 83,
        columnNumber: 11
      }
    })));
  }
  return /*#__PURE__*/_react.default.createElement(_ToolbarCollectionContext.ToolbarCollectionProvider, {
    value: state,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 90,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_MultiCollectionSupportProvider.MultiCollectionSupportProvider, {
    value: state.multi,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 91,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.Card, (0, _extends2.default)({
    className: (0, _commonStCss.st)(_commonStCss.classes.column, _commonStCss.classes.fullHeight)
  }, rest, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 92,
      columnNumber: 9
    }
  }), /*#__PURE__*/_react.default.createElement(_CollectionContext.CollectionProvider, {
    value: collection,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 93,
      columnNumber: 11
    }
  }, child)), /*#__PURE__*/_react.default.createElement(_NavigationModal.NavigationModal, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 96,
      columnNumber: 9
    }
  }), (collectionDataExtension == null ? void 0 : collectionDataExtension.dataExtension) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(collectionDataExtension.DataExtension.CustomFieldModal, {
    state: collectionDataExtension.customFieldsPanel.customFieldModal,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 99,
      columnNumber: 13
    }
  }), /*#__PURE__*/_react.default.createElement(collectionDataExtension.DataExtension.ArchiveFieldModal, {
    state: collectionDataExtension.customFieldsPanel.archiveFieldModal,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 102,
      columnNumber: 13
    }
  }), collectionDataExtension.dataExtension.deleteFieldModal && /*#__PURE__*/_react.default.createElement(_DeleteFieldModal.DeleteFieldModal, {
    state: collectionDataExtension.dataExtension.deleteFieldModal,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 108,
      columnNumber: 15
    }
  })), /*#__PURE__*/_react.default.createElement(_CollectionContext.CollectionProvider, {
    value: collection,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 115,
      columnNumber: 9
    }
  }, tags), tagsCollectionState && /*#__PURE__*/_react.default.createElement(tagsCollectionState.components.ManageModal, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 116,
      columnNumber: 33
    }
  }), (AddApplyFiltersButton == null ? void 0 : AddApplyFiltersButton.DiscardChangesModal) && /*#__PURE__*/_react.default.createElement(AddApplyFiltersButton.DiscardChangesModal, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 118,
      columnNumber: 11
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.LiveRegion, {
    dataHook: "collection-live-region",
    ref: ref => {
      state.liveRegionRef.current = ref;
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 121,
      columnNumber: 9
    }
  }), isPanelLayout ? /*#__PURE__*/_react.default.createElement(_WixPatternsPanelModalsContainer.WixPatternsPanelModalsContainer, {
    state: state.panels,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 129,
      columnNumber: 11
    }
  }) : /*#__PURE__*/_react.default.createElement(_WixPatternsModalsContainer.WixPatternsModalsContainer, {
    rootRef: stackingRootRef,
    anchorRef: useRelativeSidePanel ? stackingRootRef : modalsContainerRef,
    state: state.panels,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 131,
      columnNumber: 11
    }
  })));
}
const CollectionCard = exports.CollectionCard = (0, _mobxReactLite.observer)(_CollectionCard);
//# sourceMappingURL=CollectionCard.js.map