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

export function useNames() {
	const watcher = useWatcherStore();

	const getArea = (areaIndex?: number) => {
		if (areaIndex === undefined) {
			return undefined;
		}

		return watcher.assetAreas.find((x) => x.index === areaIndex);
	};

	const getAreaName = (areaIndex?: number) => {
		const area = getArea(areaIndex);
		return area?.name ?? "-";
	};

	const getZoneName = (areaIndex?: number, zoneIndex?: number) => {
		if (areaIndex === undefined || zoneIndex === undefined) {
			return "-";
		}

		const area = getArea(areaIndex);
		if (!area) {
			return "-";
		}

		return (
			watcher.assetZones.find(
				(x) => x.areaId === area.id && x.index === zoneIndex
			)?.name ?? "-"
		);
	};

	return { getAreaName, getZoneName };
}
