"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.PlaceholderStatesBase = void 0;
var _react = _interopRequireDefault(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _ErrorState = require("../ErrorState");
var _CollectionEmptyState = require("../EmptyState/CollectionEmptyState");
var _CollectionNoResultsState = require("../EmptyState/CollectionNoResultsState");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/PlaceholderStates/PlaceholderStatesBase.tsx";
function _PlaceholderStatesBase(props) {
  const {
    state,
    emptyState,
    noResultsState: noResultsStateProp,
    errorState,
    children,
    loadingState
  } = props;
  const {
    initTask,
    showLoadingState,
    showEmptyState,
    hasAvailableItems,
    resultOriginQuerySearch,
    hasNonPersistentActiveFilters,
    showErrorState,
    errorStatus
  } = state;
  const noResultsState = typeof noResultsStateProp === 'function' ? noResultsStateProp() : noResultsStateProp;
  let child;
  if (initTask.status.isError) {
    child = /*#__PURE__*/_react.default.createElement(_ErrorState.ErrorState, {
      dataHook: "placeholder-states-error-state",
      errorStatus: initTask.status,
      state: state,
      errorState: errorState,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 63,
        columnNumber: 7
      }
    });
  } else if (showLoadingState) {
    child = loadingState || children;
  } else if (showErrorState && errorStatus) {
    child = /*#__PURE__*/_react.default.createElement(_ErrorState.ErrorState, {
      dataHook: "placeholder-states-error-state",
      errorStatus: errorStatus,
      state: state,
      errorState: errorState,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 74,
        columnNumber: 7
      }
    });
  } else if (showEmptyState) {
    if (hasAvailableItems && (resultOriginQuerySearch != null || hasNonPersistentActiveFilters)) {
      if (noResultsState) {
        child = noResultsState;
      } else {
        child = /*#__PURE__*/_react.default.createElement(_CollectionNoResultsState.CollectionNoResultsState, {
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 89,
            columnNumber: 17
          }
        });
      }
    } else {
      if (emptyState) {
        child = emptyState;
      } else {
        child = /*#__PURE__*/_react.default.createElement(_CollectionEmptyState.CollectionEmptyState, {
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 95,
            columnNumber: 17
          }
        });
      }
    }
  } else {
    child = children;
  }
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, child);
}
const PlaceholderStatesBase = exports.PlaceholderStatesBase = (0, _mobxReactLite.observer)(_PlaceholderStatesBase);
//# sourceMappingURL=PlaceholderStatesBase.js.map