"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DesignModule = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const split_panel_service_1 = require("@opensumi/ide-core-browser/lib/components/layout/split-panel.service");
const design_1 = require("@opensumi/ide-core-browser/lib/design");
const browser_1 = require("@opensumi/ide-core-browser/lib/menu/next/renderer/ctxmenu/browser");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const browser_2 = require("@opensumi/ide-editor/lib/browser");
const ide_theme_1 = require("@opensumi/ide-theme");
const theme_store_1 = require("@opensumi/ide-theme/lib/browser/theme-store");
const workbench_theme_service_1 = require("@opensumi/ide-theme/lib/browser/workbench.theme.service");
const design_contribution_1 = require("./design.contribution");
const menu_bar_contribution_1 = require("./menu-bar/menu-bar.contribution");
const editor_tab_service_1 = require("./override/editor-tab.service");
const menu_service_1 = require("./override/menu.service");
const split_panel_service_2 = require("./override/split-panel.service");
const design_module_less_1 = tslib_1.__importDefault(require("./style/design.module.less"));
const default_theme_1 = tslib_1.__importDefault(require("./theme/default-theme"));
const light_theme_1 = tslib_1.__importDefault(require("./theme/light-theme"));
const override_token_1 = require("./theme/override.token");
let DesignModule = class DesignModule extends ide_core_browser_1.BrowserModule {
    constructor() {
        super(...arguments);
        this.providers = [menu_bar_contribution_1.DesignMenuBarContribution, design_contribution_1.DesignCoreContribution];
        this.preferences = (injector) => {
            import('./style/global.less');
            const designStyleService = injector.get(design_1.IDesignStyleService);
            designStyleService.setStyles(design_module_less_1.default);
            (0, override_token_1.overrideColorToken)();
            (0, override_token_1.overrideMonacoColorToken)();
            const appLifeCycleService = injector.get(ide_core_common_1.AppLifeCycleServiceToken);
            ide_core_common_1.Event.once(ide_core_common_1.Event.filter(appLifeCycleService.onDidLifeCyclePhaseChange, (phase) => phase === 3 /* LifeCyclePhase.Starting */))(() => {
                const themeService = injector.get(ide_theme_1.IThemeService);
                [default_theme_1.default, light_theme_1.default].forEach((theme) => {
                    themeService.registerThemes([
                        {
                            id: theme.id,
                            label: theme.name,
                            path: '',
                            extensionId: theme.id,
                            uiTheme: theme.base,
                        },
                    ], ide_core_browser_1.URI.parse(`${theme.id}.json`).withQuery(theme.id).withScheme(ide_core_common_1.Schemes.design));
                });
            });
            injector.overrideProviders({
                token: ide_theme_1.IThemeStore,
                useClass: class extends theme_store_1.ThemeStore {
                    async getThemeData(contribution, basePath) {
                        const newTheme = await super.getThemeData(contribution, basePath);
                        document.body.classList.remove(light_theme_1.default.designThemeType);
                        document.body.classList.remove(default_theme_1.default.designThemeType);
                        if (default_theme_1.default.id === (contribution === null || contribution === void 0 ? void 0 : contribution.id)) {
                            document.body.classList.add(default_theme_1.default.designThemeType);
                        }
                        else if (light_theme_1.default.id === (contribution === null || contribution === void 0 ? void 0 : contribution.id)) {
                            document.body.classList.add(light_theme_1.default.designThemeType);
                        }
                        return newTheme;
                    }
                },
                override: true,
                isDefault: true,
            }, {
                token: ide_theme_1.IThemeService,
                useClass: class extends workbench_theme_service_1.WorkbenchThemeService {
                    async ensureValidTheme() {
                        return super.ensureValidTheme(default_theme_1.default.id);
                    }
                },
                override: true,
                isDefault: true,
            }, {
                token: browser_2.IEditorTabService,
                useClass: editor_tab_service_1.DesignEditorTabService,
                override: true,
                isDefault: true,
            }, {
                token: split_panel_service_1.ISplitPanelService,
                useClass: split_panel_service_2.DesignSplitPanelService,
                override: true,
                isDefault: true,
            }, {
                token: browser_1.IBrowserCtxMenu,
                useClass: menu_service_1.DesignBrowserCtxMenuService,
            });
        };
    }
};
DesignModule = tslib_1.__decorate([
    (0, di_1.Injectable)()
], DesignModule);
exports.DesignModule = DesignModule;
//# sourceMappingURL=index.js.map