import { loadCssVariables } from "./load-css-variables.js";
import * as monaco from "monaco-editor";
//#region src/v2/features/editor/helpers/theme/apply-scalar-theme.ts
var THEME_NAME = "scalar-theme";
/**
* Applies a custom Scalar theme to the Monaco editor.
*
* This function loads CSS variables for either dark or light mode, maps the colors to Monaco's editor theme keys,
* and then applies the new theme. Theme color tokens are resolved from CSS custom properties.
*
* Example usage:
*
*   await applyScalarTheme('scalar', true);  // Apply dark mode
*   await applyScalarTheme('scalar', false); // Apply light mode
*
* @param theme - The theme string key to load variables for (e.g. 'scalar').
* @param isDarkMode - Whether to use dark or light variables.
*/
var applyScalarTheme = async (theme, isDarkMode) => {
	const allVars = await loadCssVariables(theme);
	const vars = isDarkMode ? allVars.dark : allVars.light;
	/**
	* Build a colors object for Monaco from the variable map.
	* Only assign if the variable exists in the loaded vars.
	*/
	const colors = Object.fromEntries(Object.entries({
		"editor.background": "--scalar-background-1",
		"editor.foreground": "--scalar-color-1",
		"editorLineNumber.foreground": "--scalar-color-3",
		"editorLineNumber.activeForeground": "--scalar-color-1",
		"editorLineHighlight.background": "--scalar-background-2",
		"editorCursor.foreground": "--scalar-color-1",
		"editorCursor.background": "--scalar-background-1",
		"editor.selectionBackground": "--scalar-background-3",
		"editor.inactiveSelectionBackground": "--scalar-background-3",
		"editorIndentGuide.background": "--scalar-background-3",
		"editorIndentGuide.activeBackground": "--scalar-background-2",
		"editorWhitespace.foreground": "--scalar-border-color",
		"editorBracketMatch.background": "--scalar-background-3",
		"editorBracketMatch.border": "--scalar-color-accent",
		"editor.selectionHighlightBackground": "--scalar-background-3",
		"editor.hoverHighlightBackground": "--scalar-background-3",
		"editorLink.activeForeground": "--scalar-color-3",
		"editorOverviewRuler.border": "--scalar-border-color"
	}).filter(([_, cssVar]) => !!vars[cssVar]).map(([prop, cssVar]) => [prop, vars[cssVar]]));
	monaco.editor.defineTheme(THEME_NAME, {
		base: isDarkMode ? "vs-dark" : "vs",
		inherit: true,
		rules: [
			{
				token: "",
				foreground: vars["--scalar-color-3"]
			},
			{
				token: "comment",
				foreground: vars["--scalar-color-2"],
				fontStyle: "italic"
			},
			{
				token: "keyword",
				foreground: vars["--scalar-color-accent"],
				fontStyle: "bold"
			},
			{
				token: "number",
				foreground: vars["--scalar-color-purple"]
			},
			{
				token: "string",
				foreground: vars["--scalar-color-2"]
			},
			{
				token: "delimiter",
				foreground: vars["--scalar-color-3"]
			}
		],
		colors
	});
	monaco.editor.setTheme(THEME_NAME);
};
//#endregion
export { applyScalarTheme };

//# sourceMappingURL=apply-scalar-theme.js.map