import {
  init_define_process_env
} from "./chunk-3M3OZE3J.mjs";
import "./chunk-J7LXIPZS.mjs";

// ../../node_modules/@wix/error-handler/dist/esm/state/commonErrorsMapping.js
init_define_process_env();
function createCommonErrorsMapping(t, state) {
  const {
    webWindow
  } = state;
  const location = webWindow == null ? void 0 : webWindow.location;
  return {
    applicationError: {
      CAPTCHA_REQUIRED: () => ({
        message: t("errorHandler.common-error.captchaRequired")
      })
    },
    statusCodeError: {
      UNAUTHENTICATED: () => ({
        message: t("errorHandler.common-error.unauthenticated"),
        action: webWindow ? {
          text: t("errorHandler.common-error.unauthenticated.cta"),
          onClick: () => {
            const url = new URL("https://users.wix.com/signin");
            url.searchParams.set("redirectTo", window.location.href);
            webWindow.open == null || webWindow.open(url.href, "_blank");
          }
        } : void 0
      }),
      INVALID_ARGUMENT: () => ({
        message: t("errorHandler.common-error.validationBasic")
      }),
      PERMISSION_DENIED: () => ({
        message: t("errorHandler.common-error.permission-denied.site")
      }),
      NOT_FOUND: () => ({
        message: t("errorHandler.common-error.not-found")
      }),
      ALREADY_EXISTS: () => ({
        message: t("errorHandler.common-error.conflict"),
        action: location ? {
          text: t("errorHandler.common-error.refresh.cta"),
          onClick: () => {
            location.reload();
          }
        } : void 0
      }),
      UNAVAILABLE: () => ({
        message: t("errorHandler.common-error.technicalIssue")
      }),
      RESOURCE_EXHAUSTED: () => ({
        message: t("errorHandler.common-error.resource-exhausted")
      }),
      BAD_GATEWAY: () => ({
        message: t("errorHandler.common-error.technicalIssue")
      }),
      GATEWAY_TIMEOUT: () => ({
        message: t("errorHandler.common-error.technicalIssue")
      }),
      INTERNAL: () => ({
        message: t("errorHandler.common-error.technicalIssue")
      })
    }
  };
}
function getConnectionErrorShowErrorProps(t) {
  return {
    message: t("errorHandler.common-error.noConnection")
  };
}
function getDefaultErrorShowErrorProps(t) {
  return {
    message: t("errorHandler.common-error.technicalIssue")
  };
}
function createGetNetworkErrorShowErrorProps(t) {
  return (errorAccessor) => {
    var _errorAccessor$except;
    const lcExceptionMessage = (_errorAccessor$except = errorAccessor.exceptionMessage) == null ? void 0 : _errorAccessor$except.toLowerCase();
    if (lcExceptionMessage === "network error") {
      return {
        message: t("errorHandler.common-error.networkError")
      };
    }
    if (lcExceptionMessage === "request aborted" || lcExceptionMessage === "timeout exceeded") {
      return {
        message: t("errorHandler.common-error.technicalIssue.generic")
      };
    }
    return {
      message: t("errorHandler.common-error.technicalIssue-unmappedError")
    };
  };
}
async function setCommonErrors(state) {
  const {
    translations,
    errorMonitor
  } = state;
  try {
    const t = await translations.getTranslateFn();
    state.commonErrors = {
      commonErrorsMap: createCommonErrorsMapping(t, state),
      connectionErrorShowErrorProps: getConnectionErrorShowErrorProps(t),
      defaultErrorShowErrorProps: getDefaultErrorShowErrorProps(t),
      getNetworkErrorShowErrorProps: createGetNetworkErrorShowErrorProps(t)
    };
  } catch (e) {
    errorMonitor.captureException(e);
  }
}
export {
  createCommonErrorsMapping,
  createGetNetworkErrorShowErrorProps,
  getConnectionErrorShowErrorProps,
  getDefaultErrorShowErrorProps,
  setCommonErrors
};
//# sourceMappingURL=commonErrorsMapping-ZZXTQQQ2.mjs.map