"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CollectionNoResultsState = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _MultiCollectionSupportProvider = require("../MultiCollectionSupportProvider");
var _designSystem = require("@wix/design-system");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _react2 = require("@wix/bex-core/react");
var _EmptyStateBase = require("./EmptyStateBase");
var _MagnifyingGlassArt = require("../MagnifyingGlassArt");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/EmptyState/CollectionNoResultsState.tsx"; // import { EmptyStateBasePrivateProps } from '../components/EmptyState/EmptyStateBase';
function _CollectionNoResultsState(props) {
  const state = (0, _MultiCollectionSupportProvider.useMultiCollectionSupportContext)();
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const {
    title,
    subtitle,
    cta
  } = getNoResultsStateTexts(state, t);
  return /*#__PURE__*/_react.default.createElement(_EmptyStateBase.EmptyStateBase, (0, _extends2.default)({
    dataHook: "collection-empty-state",
    title: title,
    subtitle: subtitle
  }, props, {
    cta: cta,
    image: /*#__PURE__*/_react.default.createElement(_MagnifyingGlassArt.MagnifyingGlassArt, {
      "data-hook": "empty-state-glass-illustration",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 34,
        columnNumber: 14
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 28,
      columnNumber: 5
    }
  }));
}
function ResetFiltersButton(props) {
  const state = (0, _react2.useCollectionContext)();
  return /*#__PURE__*/_react.default.createElement(_designSystem.TextButton, (0, _extends2.default)({}, props, {
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Revert, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 45,
        columnNumber: 19
      }
    }),
    dataHook: "empty-state-clear-filters-button",
    onClick: () => {
      var _state$searchInputRef;
      state.emitter.emit('beforeClearFilters', {
        origin: 'empty-state'
      });
      state.resetFiltersAndRefresh();
      (_state$searchInputRef = state.searchInputRef) == null || _state$searchInputRef.focus();
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 43,
      columnNumber: 5
    }
  }));
}
const getNoResultsStateTexts = (state, t) => {
  const {
    hasAvailableItems,
    hasNonPersistentCustomFilters,
    resultOriginQuerySearch: search,
    resultOriginQueryRawSearch: rawSearch
  } = state;
  // has search no filter
  if (hasAvailableItems && search && !hasNonPersistentCustomFilters) {
    return {
      title: t('cairo.search.nothingMatches.title', {
        term: rawSearch
      }),
      subtitle: t('cairo.search.nothingMatches.text'),
      cta: /*#__PURE__*/_react.default.createElement(ResetFiltersButton, {
        __self: void 0,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 74,
          columnNumber: 9
        }
      }, t('cairo.emptyState.reset.button'))
    };
  }
  // has filter no search
  if (hasAvailableItems && !search && hasNonPersistentCustomFilters) {
    return {
      title: t('cairo.search.noresults.title'),
      subtitle: t('cairo.emptyState.subtitle.noFilterResults'),
      cta: /*#__PURE__*/_react.default.createElement(ResetFiltersButton, {
        __self: void 0,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 86,
          columnNumber: 9
        }
      }, t('cairo.emptyState.filters.nothingFound.clearFilters.CTA'))
    };
  }
  // has filter and search
  return {
    title: t('cairo.search.nothingMatches.title', {
      term: rawSearch
    }),
    subtitle: t('cairo.search.filter.nothingMatches.text'),
    cta: /*#__PURE__*/_react.default.createElement(ResetFiltersButton, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 99,
        columnNumber: 7
      }
    }, t('cairo.emptyState.reset.button'))
  };
};
const CollectionNoResultsState = exports.CollectionNoResultsState = (0, _mobxReactLite.observer)(_CollectionNoResultsState);
//# sourceMappingURL=CollectionNoResultsState.js.map