"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.useFilterCollectionStates = useFilterCollectionStates;
var _designSystem = require("@wix/design-system");
var _react = _interopRequireDefault(require("react"));
var _react2 = require("@wix/bex-core/react");
var _providers = require("../providers");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/hooks/useFilterCollectionStates.tsx";
function useFilterCollectionStates(params) {
  const {
    collection,
    fixedFooter
  } = params;
  const {
    errorHandler
  } = (0, _react2.useWixPatternsContainer)();
  const {
    translate
  } = (0, _providers.useDropdownTranslationContext)();
  const getEmptyStateText = () => {
    if (collection.hasAvailableItems) {
      return translate('noResultsState');
    }
    return translate('emptyState');
  };
  const getFixedFooter = (dataHook, content, paramsFixedFooter) => /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    align: "left",
    direction: "vertical",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 37,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    dataHook: dataHook,
    verticalAlign: "middle",
    align: "center",
    direction: "vertical",
    width: "100%",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 38,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    padding: "SP2",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 45,
      columnNumber: 9
    }
  }, content)), paramsFixedFooter);
  if (collection.showInitialLoader || collection.result.status.isLoading || collection.showRefreshLoader) {
    return {
      showInitialLoader: true,
      fixedFooter: getFixedFooter('initial-loader', /*#__PURE__*/_react.default.createElement(_designSystem.Loader, {
        size: "small",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 58,
          columnNumber: 53
        }
      }))
    };
  }
  if (collection.showEmptyState) {
    return {
      fixedFooter: getFixedFooter('empty-state', /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
        dataHook: "empty-state-text",
        secondary: true,
        size: "small",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 66,
          columnNumber: 9
        }
      }, getEmptyStateText()), params.fixedFooter)
    };
  }
  if (collection.showErrorState) {
    var _collection$result$er;
    const resolvedError = errorHandler.getResolvedError == null ? void 0 : errorHandler.getResolvedError((_collection$result$er = collection.result.errorStatus) == null ? void 0 : _collection$result$er.error);
    if (resolvedError) {
      return {
        fixedFooter: getFixedFooter('filter-error-state', /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
          direction: "vertical",
          gap: "SP1",
          verticalAlign: "middle",
          align: "center",
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 83,
            columnNumber: 11
          }
        }, /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
          dataHook: "filter-error-state-text",
          secondary: true,
          align: "center",
          weight: "thin",
          size: "small",
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 89,
            columnNumber: 13
          }
        }, resolvedError.message, resolvedError.action && /*#__PURE__*/_react.default.createElement(_designSystem.TextButton, {
          onClick: async () => {
            var _resolvedError$action;
            await ((_resolvedError$action = resolvedError.action) == null || _resolvedError$action.onClick == null ? void 0 : _resolvedError$action.onClick());
          },
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 98,
            columnNumber: 17
          }
        }, resolvedError.action.text)), resolvedError.action && /*#__PURE__*/_react.default.createElement(_designSystem.TextButton, {
          size: "small",
          weight: "thin",
          onClick: async () => {
            var _resolvedError$action2;
            await ((_resolvedError$action2 = resolvedError.action) == null || _resolvedError$action2.onClick == null ? void 0 : _resolvedError$action2.onClick());
          },
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 108,
            columnNumber: 15
          }
        }, resolvedError.action.text)))
      };
    }
  }
  return {
    fixedFooter
  };
}
//# sourceMappingURL=useFilterCollectionStates.js.map