import { splitAndTrim } from "@ax/helpers";
import type { IDimensionsGroup } from "@ax/types";

const getTemplateDimensions = (groups: IDimensionsGroup[], template: string): string[] => {
	const templateDimensionsGroups = groups?.filter((group) => group.templates?.includes(template));
	const templateDimensions = templateDimensionsGroups?.flatMap((group: IDimensionsGroup) =>
		splitAndTrim(group.dimensions, ";"),
	);
	const uniqueTemplateDimensions = [...new Set(templateDimensions)];
	return uniqueTemplateDimensions;
};

export { getTemplateDimensions };
