import type { Input, Output, STATUS_CODE } from "@/types/index";
import { getOrderStatus } from "@utils/getOrderStatus";
import type { InflightInfo } from "./data";

export function getSubtitle(
	_statusId: STATUS_CODE,
	data: InflightInfo,
	input: Input,
	output: Output,
	inputChainName: string,
	outputChainName: string,
) {
	const { isCompleted, inProgress, isExpired, isReverted } =
		getOrderStatus(_statusId);

	if (inProgress)
		return data.subTitle.inProgress(
			{ chainName: inputChainName, tokenSymbol: input.token.symbol },
			{ chainName: outputChainName, tokenSymbol: output.token.symbol },
		);
	if (isCompleted) return data.subTitle.isCompleted(outputChainName);
	if (isExpired) return data.subTitle.isExpired;
	if (isReverted) return data.subTitle.isReverted;
	return data.subTitle.isPending;
}

export function getTitle(
	statusCode: STATUS_CODE,
	data: InflightInfo,
	protocolName?: string,
	gasless?: boolean,
) {
	const { isPending, isCompleted, inProgress, isExpired, isReverted } =
		getOrderStatus(statusCode);

	if (isExpired) return data.title.isExpired;
	if (isPending) return data.title.isPending;
	if (inProgress) return data.title.inProgress(protocolName, gasless);
	if (isCompleted) return data.title.isCompleted(protocolName);
	if (isReverted) return data.title.isReverted;
}
