import { Chalk } from "chalk";
import { builtinThemes } from "../../../core/config/builtin_themes.js";
import { assertNever } from "../../../core/utils/never.js";
import { coercePaletteOverrides, createPalette } from "./palette.js";
const chalk = new Chalk({ level: 3 });
function tagWrapper(label) {
    return (text) => `<${label}>${text}</${label}>`;
}
function plainWrapper() {
    return (text) => text;
}
function createTextStyles(mode) {
    if (mode === "ansi") {
        return {
            bold: (text) => chalk.bold(text),
            italic: (text) => chalk.italic(text),
            underline: (text) => chalk.underline(text),
            strikethrough: (text) => chalk.strikethrough(text),
            cursor: (text) => chalk.inverse(text),
        };
    }
    const wrap = (label) => (mode === "tags" ? tagWrapper(label) : plainWrapper());
    return {
        bold: wrap("bold"),
        italic: wrap("italic"),
        underline: wrap("underline"),
        strikethrough: wrap("strikethrough"),
        cursor: wrap("cursor"),
    };
}
function createMarkdownTheme(palette, text) {
    return {
        bold: (textValue) => text.bold(textValue),
        code: (textValue) => palette.codeInlineText(textValue),
        codeBlock: (textValue) => palette.codeBlockText(textValue),
        codeBlockBorder: (textValue) => palette.textDim(textValue),
        codeBlockIndent: "",
        heading: (textValue) => text.bold(palette.brandAccent(textValue)),
        hr: (textValue) => palette.textDim(textValue),
        italic: (textValue) => text.italic(textValue),
        link: (textValue) => palette.linkText(textValue),
        linkUrl: (textValue) => palette.textDim(textValue),
        listBullet: (textValue) => palette.textMuted(textValue),
        quote: (textValue) => text.italic(palette.textMuted(textValue)),
        quoteBorder: (textValue) => palette.textDim(textValue),
        strikethrough: (textValue) => text.strikethrough(textValue),
        underline: (textValue) => text.underline(textValue),
    };
}
function createSelectListTheme(palette, text) {
    return {
        selectedPrefix: (textValue) => text.bold(palette.brandAccent(textValue)),
        selectedText: (textValue) => text.bold(palette.brandAccent(textValue)),
        description: (textValue) => palette.textMuted(textValue),
        scrollInfo: (textValue) => palette.textDim(textValue),
        noMatch: (textValue) => palette.textMuted(textValue),
    };
}
function createEditorBorderForReasoning(palette) {
    return (effort) => {
        switch (effort) {
            case undefined:
            case "none":
                return palette.editorBorderNone;
            case "minimal":
                return palette.editorBorderMinimal;
            case "low":
                return palette.editorBorderLow;
            case "medium":
                return palette.editorBorderMedium;
            case "high":
                return palette.editorBorderHigh;
            case "xhigh":
                return palette.editorBorderXhigh;
            default:
                assertNever(effort);
        }
    };
}
const defaultPaletteOverrides = coercePaletteOverrides(builtinThemes.find((theme) => theme.id === "gold")?.tokens);
export function createUiTheme(mode = "ansi", overrides) {
    const palette = createPalette(mode, overrides ?? defaultPaletteOverrides);
    const text = createTextStyles(mode);
    const markdownTheme = createMarkdownTheme(palette, text);
    const selectListTheme = createSelectListTheme(palette, text);
    const editorBorderForReasoning = createEditorBorderForReasoning(palette);
    const editorTheme = {
        borderColor: (textValue) => editorBorderForReasoning("none")(textValue),
        selectList: selectListTheme,
    };
    return {
        mode,
        palette,
        markdownTheme,
        editorTheme,
        text,
        editorBorderForReasoning,
    };
}
export const theme = createUiTheme("ansi");
export const palette = theme.palette;
export const markdownTheme = theme.markdownTheme;
export const editorTheme = theme.editorTheme;
export const editorBorderForReasoning = theme.editorBorderForReasoning;
//# sourceMappingURL=theme.js.map