"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var assistant_error_descriptor_exports = {};
__export(assistant_error_descriptor_exports, {
  getAssistantErrorDescriptor: () => getAssistantErrorDescriptor
});
module.exports = __toCommonJS(assistant_error_descriptor_exports);
const trimMessage = (message) => message?.trim();
const createDefaultDescriptor = (t, overrides = {}) => ({
  title: t("AssistantTimeline_Error_Title_Default"),
  subtitle: t("AssistantTimeline_Error_Subtitle_Default"),
  isRetriable: true,
  hiddenMessage: "<HIDDEN>Request failed. Please try again later.</HIDDEN>",
  shouldOpenPaywall: false,
  ...overrides
});
const getAssistantErrorDescriptor = ({
  applicationErrorCode,
  message,
  t
}) => {
  const trimmedMessage = trimMessage(message);
  switch (applicationErrorCode) {
    case "ALREADY_EXECUTED":
      return createDefaultDescriptor(t, {
        title: t("AssistantTimeline_Error_Title_AlreadyExecuted"),
        subtitle: t("AssistantTimeline_Error_Subtitle_AlreadyExecuted"),
        hiddenMessage: "<HIDDEN>Request cancelled by user</HIDDEN>"
      });
    case "USER_CANCELLED":
      return createDefaultDescriptor(t, {
        hiddenMessage: "<HIDDEN>Request cancelled by user</HIDDEN>"
      });
    case "AI_BUDGET_EXCEEDED":
      return createDefaultDescriptor(t, {
        title: t("AssistantTimeline_Error_Title_BudgetExceeded"),
        subtitle: t("AssistantTimeline_Error_Subtitle_BudgetExceeded"),
        hiddenMessage: "<HIDDEN>User is out of credit, he can upgrade his plan to continue using AI editing.</HIDDEN>",
        shouldOpenPaywall: true
      });
    case "UNSUPPORTED_MIME_TYPE":
      return createDefaultDescriptor(t, {
        title: t("AssistantTimeline_Error_Title_UnsupportedFileType"),
        subtitle: t("AssistantTimeline_Error_Subtitle_UnsupportedFileType"),
        isRetriable: false,
        hiddenMessage: trimmedMessage ? `<HIDDEN>File type is not supported. ${trimmedMessage}</HIDDEN>` : "<HIDDEN>File type is not supported.</HIDDEN>"
      });
    case "AI_GENERATED_ERROR":
      return createDefaultDescriptor(t, {
        subtitle: trimmedMessage || t("AssistantTimeline_Error_Subtitle_Default"),
        hiddenMessage: trimmedMessage ? `<HIDDEN>Request failed with error: ${trimmedMessage}</HIDDEN>` : "<HIDDEN>Request failed. Please try again later.</HIDDEN>"
      });
    default:
      return createDefaultDescriptor(t);
  }
};
//# sourceMappingURL=assistant-error-descriptor.js.map
