import { useTranslation } from "react-i18next";

import { useWatcherStore } from "../../watcher/store/watcher.store";
import { ReportWithoutData } from "../models/ReportWithoutData";

export const useBuildObjectListTitle = () => {
	const { t } = useTranslation();
	const { assets } = useWatcherStore();

	return {
		buildObjectListTitle: (report: ReportWithoutData) => {
			if (!report.assetIdList) return "";

			const firstObjectName = assets.find(
				(x) => x.id === report.assetIdList[0]
			)?.name;
			const elseCount = report.assetIdList.length - 1;

			return report.assetIdList.length === 1
				? firstObjectName
				: elseCount === 1
				? t("objectNameAndElseOneObject", {
						assetName: firstObjectName,
				  })
				: t("objectNameAndElseCountObjects", {
						assetName: firstObjectName,
						elseCount,
				  });
		},
	};
};
