"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ErrorState = void 0;
var _react = _interopRequireDefault(require("react"));
var _react2 = require("@wix/bex-core/react");
var _OfflineErrorState = require("./OfflineErrorState");
var _CollectionErrorState = require("../CollectionErrorState");
var _mobxReactLite = require("mobx-react-lite");
var _bexCore = require("@wix/bex-core");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/ErrorState/ErrorState.tsx";
function _ErrorState({
  state,
  errorStatus: errorStatusProp,
  errorState,
  dataHook,
  image
}) {
  const {
    onlineState: {
      isOnline
    },
    errorHandler,
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const errorStatus = errorStatusProp ?? state.errorStatus;
  if (!isOnline) {
    return /*#__PURE__*/_react.default.createElement(_OfflineErrorState.OfflineErrorState, {
      image: image,
      onRetry: state.retryErrorState,
      dataHook: dataHook,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 52,
        columnNumber: 7
      }
    });
  }
  if (errorState && errorStatus) {
    return errorState(errorStatus.error, {
      isOnline,
      retry: state.retryErrorState
    });
  }
  const resolvedError = errorHandler.getResolvedError == null ? void 0 : errorHandler.getResolvedError(errorStatus == null ? void 0 : errorStatus.error);
  const action = (resolvedError == null ? void 0 : resolvedError.action) ?? ((0, _bexCore.isServerErrorCode)(errorStatus == null ? void 0 : errorStatus.error) ? {
    text: t('cairo.error.tryAgain.cta'),
    onClick: state.retryErrorState
  } : undefined);
  return /*#__PURE__*/_react.default.createElement(_CollectionErrorState.CollectionErrorState, {
    dataHook: dataHook,
    title: t('cairo.technical.error.title', {
      defaultValue: 'We couldn’t load your items'
    }),
    subtitle: resolvedError == null ? void 0 : resolvedError.message,
    action: action && {
      text: action == null ? void 0 : action.text,
      onClick: () => action == null || action.onClick == null ? void 0 : action.onClick()
    },
    requestId: resolvedError == null ? void 0 : resolvedError.requestId,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 75,
      columnNumber: 5
    }
  });
}
const ErrorState = exports.ErrorState = (0, _mobxReactLite.observer)(_ErrorState);
//# sourceMappingURL=ErrorState.js.map