import { selectEmptyOptions } from "../config/constants"; import type { TOptionType } from "../config/types"; /** * Gets the label of an option by its value. * Supports nested option groups. * @returns {string} */ export const getLabel = (options: TOptionType[] = selectEmptyOptions, val: string = ""): string => { let result = ""; for (const option of options) { const { label, value, options: subOptions } = option; if (Array.isArray(subOptions)) { for (const subOption of subOptions) { if (subOption.value === val) { result = subOption.label || ""; break; } } } else if (value === val) { result = label || ""; break; } if (result) { break; } } return result; };