import NumberUtil from "../../Utils/Number";
export default class DropdownUtil {
    static getDropdownOptionsFromEnum(obj, useKeyAsLabel = false) {
        const dropdownOptions = Object.keys(obj)
            .map((key) => {
            // for enums with numbers, Object.keys will return the numbers as strings which is not what we want
            if (NumberUtil.canBeConvertedToNumber(key)) {
                return null;
            }
            return {
                label: useKeyAsLabel ? key : obj[key].toString(),
                value: NumberUtil.canBeConvertedToNumber(obj[key])
                    ? NumberUtil.convertToNumber(obj[key])
                    : obj[key],
            };
        })
            .filter((option) => {
            return option !== null;
        });
        return dropdownOptions;
    }
    static getDropdownOptionFromEnumForValue(enumObject, value) {
        const options = DropdownUtil.getDropdownOptionsFromEnum(enumObject);
        const option = options.find((option) => {
            return option.value === value;
        });
        return option;
    }
    static getDropdownOptionsFromEntityArray(data) {
        return data.array.map((item) => {
            const option = {
                label: item.getColumnValue(data.labelField),
                value: item.getColumnValue(data.valueField),
            };
            const colorColumnName = typeof item.getFirstColorColumn === "function"
                ? item.getFirstColorColumn()
                : null;
            if (colorColumnName) {
                const color = item.getColumnValue(colorColumnName);
                if (color) {
                    option.color = color;
                }
            }
            return option;
        });
    }
    static getDropdownOptionsFromArray(arr) {
        const uniqueArr = [...new Set(arr)];
        return uniqueArr.map((item) => {
            return {
                label: item,
                value: item,
            };
        });
    }
}
//# sourceMappingURL=Dropdown.js.map