import { useTranslation } from "react-i18next";

import { AreaModel } from "@/contracts/client.schemas";

export const useGetAreaName = (areas: AreaModel[]) => {
	const { t } = useTranslation("translation");
	return {
		getName: (index?: number) => {
			const name = areas.find((x) => x.index === index)?.name;

			if (
				!name ||
				(name?.startsWith("Area") &&
					name?.endsWith((index || 0)?.toFixed(0)))
			) {
				return `${t("area")} ${index}`;
			}

			return name;
		},
	};
};
