import { getThemeId, getThemeType } from '@opensumi/ide-theme';
export const flatModules = (modules) => {
    return Object.keys(modules).reduce((arr, key) => arr.concat(modules[key]), []);
};
export const mergeConfig = (target, source) => {
    if (!source) {
        return target;
    }
    Object.keys(source).forEach((key) => {
        const sourceValue = source[key];
        switch (key) {
            case 'modules':
            case 'extensionMetadata':
                if (Array.isArray(sourceValue)) {
                    if (!target[key]) {
                        target[key] = [];
                    }
                    const targetValue = target[key];
                    sourceValue.forEach((value) => {
                        if (targetValue.indexOf(value) < 0) {
                            targetValue.push(value);
                        }
                    });
                }
                break;
            case 'defaultPreferences':
            case 'defaultPanels':
                if (!target[key]) {
                    target[key] = {};
                }
                Object.assign(target[key], sourceValue);
                break;
            default:
                target[key] = sourceValue;
        }
    });
    return target;
};
export const getThemeTypeByPreferenceThemeId = (themeId, extensionMetadata) => {
    var _a, _b;
    let uiTheme;
    if (themeId && extensionMetadata) {
        for (const ext of extensionMetadata) {
            const theme = (_b = (_a = ext.packageJSON.contributes) === null || _a === void 0 ? void 0 : _a.themes) === null || _b === void 0 ? void 0 : _b.find((contrib) => contrib && getThemeId(contrib) === themeId);
            if (theme === null || theme === void 0 ? void 0 : theme.uiTheme) {
                uiTheme = theme.uiTheme;
                break;
            }
        }
    }
    return getThemeType(uiTheme || 'vs-dark');
};
//# sourceMappingURL=utils.js.map