import * as fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { defaultDarkTheme, defaultLightTheme } from "../components/ThemeProvider/defaultTheme.js";
import { camelToKebab } from "../components/ThemeProvider/utils.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const sectionHeaders = {
    background: "// Surface / Background Colors",
    textNeutralPrimary: "// Text Colors",
    chatUserResponseBg: "// Chat Colors",
    interactiveAccentDefault: "// Interactive Colors",
    borderDefault: "// Border Colors",
    space000: "// Spacing",
    radiusNone: "// Border Radius",
    fontBody: "// Typography Tokens",
    shadow0: "// Shadows",
};
const lines = [];
lines.push("// Auto-generated by src/scripts/generate-css-utils.ts — do not edit manually.");
lines.push('@use "sass:map";');
lines.push("");
const entries = Object.entries(defaultLightTheme).filter(([, value]) => typeof value === "string");
for (const [key] of entries) {
    if (sectionHeaders[key]) {
        if (lines.length > 3)
            lines.push("");
        lines.push(sectionHeaders[key]);
        lines.push("");
    }
    const kebab = camelToKebab(key);
    lines.push(`$${kebab}: var(--openui-${kebab});`);
}
// $chat-container-bg is an SCSS-level alias, not a CSS variable
lines.push("");
lines.push("$chat-container-bg: $background;");
// ─── Static typography system ────────────────────────────────────────────────
lines.push("");
lines.push(`\
@function typography($font-name) {
  @return (font: var(--#{$font-name}), letter-spacing: var(--#{$font-name}-letter-spacing));
}

$typography: (
  body: (
    default: typography(openui-text-body-default),
    heavy: typography(openui-text-body-default-heavy),
    small: typography(openui-text-body-sm),
    small-heavy: typography(openui-text-body-sm-heavy),
    large: typography(openui-text-body-lg),
    large-heavy: typography(openui-text-body-lg-heavy),
    link: typography(openui-text-body-default),
    medium: typography(openui-text-body-default),
  ),
  label: (
    default: typography(openui-text-label-default),
    heavy: typography(openui-text-label-default-heavy),
    large: typography(openui-text-label-lg),
    large-heavy: typography(openui-text-label-lg-heavy),
    medium: typography(openui-text-label-default),
    medium-heavy: typography(openui-text-label-default-heavy),
    small: typography(openui-text-label-sm),
    small-heavy: typography(openui-text-label-sm-heavy),
    extra-small: typography(openui-text-label-xs),
    extra-small-heavy: typography(openui-text-label-xs-heavy),
    2-extra-small: typography(openui-text-label-xs),
    2-extra-small-heavy: typography(openui-text-label-xs-heavy),
  ),
  heading: (
    xl: typography(openui-text-heading-xl),
    large: typography(openui-text-heading-lg),
    medium: typography(openui-text-heading-md),
    small: typography(openui-text-heading-sm),
    extra-small: typography(openui-text-heading-xs),
  ),
  number: (
    large: typography(openui-text-numbers-lg),
    large-heavy: typography(openui-text-numbers-lg-heavy),
    heavy: typography(openui-text-numbers-default-heavy),
    default: typography(openui-text-numbers-default),
    small: typography(openui-text-numbers-sm),
    small-heavy: typography(openui-text-numbers-sm-heavy),
    extra-small: typography(openui-text-numbers-xs),
    extra-small-heavy: typography(openui-text-numbers-xs-heavy),
    heading: typography(openui-text-numbers-heading-lg),
    heading-small: typography(openui-text-numbers-heading-sm),
    heading-medium: typography(openui-text-numbers-heading-md),
    heading-large: typography(openui-text-numbers-heading-lg),
    heading-xl: typography(openui-text-numbers-heading-xl),
  ),
  code: (
    default: typography(openui-text-code-default),
    heavy: typography(openui-text-code-default-heavy),
    small: typography(openui-text-code-sm),
    small-heavy: typography(openui-text-code-sm-heavy),
  ),
);

@mixin typography($font-name, $font-variant) {
  font: map.get($typography, $font-name, $font-variant, font);
  letter-spacing: map.get($typography, $font-name, $font-variant, letter-spacing);
}

@mixin button-reset {
  padding: 0;
  border: 0;
  background: transparent;
}`);
lines.push("");
const outputPath = path.resolve(__dirname, "../cssUtils.css");
fs.writeFileSync(outputPath, lines.join("\n"));
console.info(`Generated cssUtils.scss at ${outputPath}`);
// ─── Generate openui-defaults.scss with :root custom property defaults ───────
const defaultsLines = [];
defaultsLines.push("// Auto-generated by src/scripts/generate-css-utils.ts — do not edit manually.");
defaultsLines.push("");
defaultsLines.push(":root {");
for (const [key, value] of entries) {
    if (sectionHeaders[key]) {
        if (defaultsLines.length > 3)
            defaultsLines.push("");
        defaultsLines.push(`  ${sectionHeaders[key]}`);
        defaultsLines.push("");
    }
    const kebab = camelToKebab(key);
    defaultsLines.push(`  --openui-${kebab}: ${value};`);
}
defaultsLines.push("}");
defaultsLines.push("");
// ─── Dark mode defaults via prefers-color-scheme ─────────────────────────────
const darkEntries = Object.entries(defaultDarkTheme).filter(([, value]) => typeof value === "string");
defaultsLines.push("@media (prefers-color-scheme: dark) {");
defaultsLines.push("  :root {");
for (const [key, value] of darkEntries) {
    if (sectionHeaders[key]) {
        defaultsLines.push("");
        defaultsLines.push(`    ${sectionHeaders[key]}`);
        defaultsLines.push("");
    }
    const kebab = camelToKebab(key);
    defaultsLines.push(`    --openui-${kebab}: ${value};`);
}
defaultsLines.push("  }");
defaultsLines.push("}");
defaultsLines.push("");
const defaultsOutputPath = path.resolve(__dirname, "../openui-defaults.css");
fs.writeFileSync(defaultsOutputPath, defaultsLines.join("\n"));
console.info(`Generated openui-defaults.scss at ${defaultsOutputPath}`);
//# sourceMappingURL=generate-css-utils.js.map