import { WOO_MERGE_TAGS } from '@/woocommerce/elements/data-field/constants/merge-tags';

export type MergeTagOption = { tag: string; label: string; groupLabel: string };

export function getMergeTagOptions(): MergeTagOption[] {
	return WOO_MERGE_TAGS.flatMap((group) =>
		group.fields.map((field) => ({
			tag: field.tag,
			label: field.label,
			groupLabel: group.groupLabel,
		})),
	);
}

export function findMergeTagLabel(mergeTag?: string): string | undefined {
	if (!mergeTag) return undefined;
	for (const group of WOO_MERGE_TAGS) {
		const found = group.fields.find((field) => field.tag === mergeTag);
		if (found) return found.label;
	}
	return undefined;
}
