import { u as useI18n } from './server.mjs';

const useApiError = () => {
  const { t } = useI18n();
  const translateError = (message) => {
    if (!message) return t("notify.error");
    const lowerMessage = message.toLowerCase();
    if (lowerMessage.includes("wip limit")) {
      const match = message.match(/(\d+)\s+issue/);
      const count = match ? match[1] : "1";
      return t("apiError.wipLimit", { count });
    }
    if (lowerMessage.includes("cannot skip") || lowerMessage.includes("cannot move from")) {
      return t("apiError.cannotSkip");
    }
    if (lowerMessage.includes("acceptance criteria required")) {
      return t("apiError.acceptanceCriteriaRequired");
    }
    if (lowerMessage.includes("not found") && lowerMessage.includes("issue")) {
      return t("apiError.issueNotFound");
    }
    if (lowerMessage.includes("required") && lowerMessage.includes("column")) {
      return t("apiError.columnRequired");
    }
    if (lowerMessage.includes("move") && lowerMessage.includes("failed")) {
      return t("apiError.moveFailed");
    }
    if (lowerMessage.includes("save") && lowerMessage.includes("failed")) {
      return t("apiError.saveFailed");
    }
    if (lowerMessage.includes("delete") && lowerMessage.includes("failed")) {
      return t("apiError.deleteFailed");
    }
    return message;
  };
  const getErrorMessage = (err, fallback) => {
    const apiMessage = err?.data?.message;
    if (apiMessage) {
      return translateError(apiMessage);
    }
    const directMessage = err?.message;
    if (directMessage) {
      return translateError(directMessage);
    }
    return fallback || t("notify.error");
  };
  return {
    translateError,
    getErrorMessage
  };
};

export { useApiError as u };
//# sourceMappingURL=useApiError-BSStUojq.mjs.map
