export const getOpenKeysFromMenuData = (menuData) => {
    return (menuData || []).reduce((pre, item) => {
        if(item.key) {
            pre.push(item.key);
        }

        if(item.children) {
            const newArray = pre.concat(getOpenKeysFromMenuData(item.children) || []);
            return newArray;
        }
        return pre;
    }, []);
};

const themeConfig = {
    daybreak: 'daybreak',
    '#1890ff': 'daybreak',
    '#F5222D': 'dust',
    '#FA541C': 'volcano',
    '#FAAD14': 'sunset',
    '#13C2C2': 'cyan',
    '#52C41A': 'green',
    '#2F54EB': 'geekblue',
    '#722ED1': 'purple',
};

const invertKeyValues = (obj) => {
    Object.keys(obj).reduce((acc, key) => {
        acc[obj[key]] = key;
        return acc;
    }, {})
}

export function genThemeToString(val) {
    return val && themeConfig[val] ? themeConfig[val] : undefined;
};

export function genStringToTheme(val) {
    const stringConfig = invertKeyValues(themeConfig);
    return val && stringConfig[val] ? stringConfig[val] : val;
};
