import { TransactionRequestType as e } from "../types/transaction.types.mjs";
import "../types/index.mjs";
import { DIRECTLY_SHOW_MESSAGE_ERROR_CODES as t, UserFriendlyErrorCodes as n, insufficientResourcesErrorCodes as r, transactionErrorCodes as i } from "./error-codes.constants.mjs";
import { ErrorWithAmount as a } from "./customErrors/ErrorWithAmount.mjs";
import { FeeOverTransactionValueError as o } from "./customErrors/FeeOverTransactionValueError.mjs";
import { ErrorCategory as s } from "./types.mjs";
import { getGenericFeeOverTransactionValueErrorMessage as c } from "./customErrors/customErrors.helpers.mjs";
import "./customErrors/index.mjs";
import { isInsufficientFundsError as l } from "./isInsufficientFundsError.mjs";
//#region libs/shared/common/src/error-handling/get-error.message.ts
var u = (e) => {
	if (typeof e == "object" && e) {
		if ("response" in e && typeof e.response == "object" && e.response !== null && "data" in e.response && typeof e.response.data == "object" && e.response.data !== null && "message" in e.response.data && typeof e.response.data.message == "string") return e.response.data.message;
		if ("data" in e && typeof e.data == "object" && e.data !== null && "message" in e.data && typeof e.data.message == "string") return e.data.message;
		if ("message" in e && typeof e.message == "string") return e.message;
	}
	if (e instanceof Error) return e.message;
	if (typeof e == "string") return e;
}, d = (e) => {
	switch (e) {
		case s.DEPOSIT: return "Deposit failed";
		case s.SWAP: return "Swap failed";
		case s.BRIDGE: return "Bridge failed";
		case s.WITHDRAW: return "Send failed";
		case s.Fund: return "Unshield failed";
		case s.Receive: return "Shield failed";
		case s.DappTransaction: return "DApp transaction failed";
		case s.Approve: return "Approval failed";
		default: return i.UNKNOWN;
	}
}, f = (e, s) => {
	if (e instanceof o) return c(e, s);
	if (e instanceof a) {
		let { amount: t, message: n } = e;
		return `${n} ${t}`;
	}
	let f = u(e);
	if (f && l(f)) return r.INSUFFICIENT_FUNDS;
	if (f) {
		let e = f.toLowerCase(), r = Object.keys(i).find((t) => e === i[t].toLowerCase());
		if (r && r in n) return n[r];
		let a = Object.entries(i).find(([t, n]) => e.includes(n.toLowerCase()));
		if (a) return n[a[0]] ?? a[1];
		if (Object.values(t).find((t) => e.includes(t.toLowerCase()))) return f;
	}
	return s ? d(s) : i.UNKNOWN;
}, p = (t, n) => {
	let r;
	switch (n) {
		case e.Send:
		case e.ProxySend:
			r = s.WITHDRAW;
			break;
		case e.SwapTokens:
		case e.ProxySwapTokens:
			r = s.SWAP;
			break;
		case e.ReceiveFromShieldedAccount:
			r = s.Receive;
			break;
		case e.Fund:
			r = s.Fund;
			break;
		case e.PrivateTransactionFromProxy:
			r = s.DappTransaction;
			break;
		default:
			r = void 0;
			break;
	}
	return f(t, r);
};
//#endregion
export { u as extractMessage, f as getErrorMessage, p as getErrorMessageFromTransactionRequest };
