class ThemesManager {
    private static CurrentThemeAssemblyName: string;

    public static LoadTheme(themeAssemblyName: string): void {
        if (ThemesManager.CurrentThemeAssemblyName !== themeAssemblyName) {
            ThemesManager.CurrentThemeAssemblyName = themeAssemblyName;

            // 清除现有的主题样式
            const existingLinks = document.querySelectorAll('link[rel="stylesheet"][data-theme]');
            existingLinks.forEach(link => link.parentNode?.removeChild(link));

            // 加载基本主题
            const baseThemeLink = document.createElement('link');
            baseThemeLink.rel = 'stylesheet';
            baseThemeLink.href = '/Platform.BaseTheme/CommonResources.css';
            baseThemeLink.dataset.theme = 'base';
            document.head.appendChild(baseThemeLink);

            // 加载指定主题
            const projectThemeLink = document.createElement('link');
            projectThemeLink.rel = 'stylesheet';
            projectThemeLink.href = `/${themeAssemblyName}/CommonResources.css`;
            projectThemeLink.dataset.theme = 'project';
            document.head.appendChild(projectThemeLink);
        }
    }
}

export default ThemesManager;