import {
  generateButtonCoreCss,
  generateCardCoreCss,
  generateInputCoreCss,
  getDefaultButtonVariants,
  getDefaultCardVariants,
  getDefaultInputSettings
} from "./chunk-NKXS4TBK.mjs";
import "./chunk-USQF2XTU.mjs";
import "./chunk-BJTO5JO5.mjs";

// src/theme-bridge/ThemeBridgeProvider.tsx
import * as React from "react";

// src/theme-bridge/generateCssVars.ts
var SCOPE_ID = "sdk";
var SYSTEM_FONT_STACK = 'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"';
var SPACING_CONFIG = {
  comfortable: { mult: 1.15, rhythm: "1.2rem" },
  standard: { mult: 1, rhythm: "1rem" },
  dense: { mult: 0.88, rhythm: "0.75rem" }
};
var CORNERS_CONFIG = {
  square: { control: "0px", card: "0px" },
  soft: { control: "4px", card: "8px" },
  rounded: { control: "8px", card: "12px" },
  pill: { control: "9999px", card: "16px" }
};
var SHADOWS_CONFIG = {
  none: {
    sm: "none",
    md: "none",
    lg: "none",
    elev: "none"
  },
  low: {
    sm: "0 1px 2px rgba(0,0,0,0.04)",
    md: "0 2px 4px rgba(0,0,0,0.06)",
    lg: "0 4px 8px rgba(0,0,0,0.08)",
    elev: "0 1px 3px rgba(0,0,0,0.06)"
  },
  medium: {
    sm: "0 1px 2px rgba(0,0,0,0.06)",
    md: "0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1)",
    lg: "0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1)",
    elev: "0 2px 6px rgba(0,0,0,0.08)"
  },
  high: {
    sm: "0 1px 3px rgba(0,0,0,0.08)",
    md: "0 6px 12px -2px rgba(0,0,0,0.15), 0 3px 6px -3px rgba(0,0,0,0.1)",
    lg: "0 20px 25px -5px rgba(0,0,0,0.15), 0 8px 10px -6px rgba(0,0,0,0.1)",
    elev: "0 4px 12px rgba(0,0,0,0.12)"
  }
};
function hexToRgb(hex) {
  const h = hex.replace(/^#/, "");
  const m = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
  if (m.length !== 6) {
    console.warn(`[ThemeBridge] Invalid hex color: ${hex}`);
    return "0 0 0";
  }
  const int = parseInt(m, 16);
  const r = int >> 16 & 255;
  const g = int >> 8 & 255;
  const b = int & 255;
  return `${r} ${g} ${b}`;
}
function normalizeTokenValue(value) {
  if (value.startsWith("var(")) {
    return value;
  }
  if (value.startsWith("#")) {
    return hexToRgb(value);
  }
  return value;
}
function generateThemeBridgeCss(config) {
  if (!config || typeof config !== "object") {
    throw new Error(
      '[ThemeBridge] Invalid config: expected an object with a "tokens" property.'
    );
  }
  if (!config.tokens || typeof config.tokens !== "object" || Array.isArray(config.tokens)) {
    throw new Error(
      '[ThemeBridge] Missing "tokens" property in config. ThemeBridgeConfig requires a "tokens" object with color definitions. Example: { tokens: { primary: "#6d28d9", background: "#ffffff" } }'
    );
  }
  const cssVars = {};
  const cssChunks = [];
  for (const [name, value] of Object.entries(config.tokens)) {
    cssVars[`--tb-${name}`] = normalizeTokenValue(value);
  }
  const typography = config.typography ?? {};
  cssVars["--tb-font-heading"] = typography.headingFamily ?? SYSTEM_FONT_STACK;
  cssVars["--tb-font-body"] = typography.bodyFamily ?? SYSTEM_FONT_STACK;
  cssVars["--tb-font-weight-heading"] = String(typography.headingWeight ?? 600);
  cssVars["--tb-font-weight-body"] = String(typography.bodyWeight ?? 400);
  cssVars["--tb-fs-h1"] = "2.5rem";
  cssVars["--tb-fs-h2"] = "2rem";
  cssVars["--tb-fs-h3"] = "1.5rem";
  cssVars["--tb-fs-body"] = "1rem";
  cssVars["--tb-ls-heading"] = "-0.02em";
  cssVars["--tb-ls-body"] = "0";
  cssVars["--tb-lh-heading"] = "1.2";
  cssVars["--tb-lh-body"] = "1.6";
  cssVars["--tb-tt-heading"] = "none";
  cssVars["--tb-fv-heading"] = "normal";
  const spacingPreset = SPACING_CONFIG[config.spacing ?? "standard"];
  cssVars["--tb-space-mult"] = String(spacingPreset.mult);
  cssVars["--tb-rt-space-y"] = spacingPreset.rhythm;
  const corners = config.corners ?? "rounded";
  const cornersPreset = CORNERS_CONFIG[corners];
  cssVars["--tb-radius-control"] = cornersPreset.control;
  cssVars["--tb-radius-card"] = cornersPreset.card;
  const shadows = config.shadows ?? "medium";
  const shadowsPreset = SHADOWS_CONFIG[shadows];
  cssVars["--tb-shadow-sm"] = shadowsPreset.sm;
  cssVars["--tb-shadow-md"] = shadowsPreset.md;
  cssVars["--tb-shadow-lg"] = shadowsPreset.lg;
  cssVars["--tb-shadow-elev"] = shadowsPreset.elev;
  cssVars["--tb-motion-duration"] = "180ms";
  cssVars["--tb-motion-ease"] = "cubic-bezier(0.2, 0.8, 0.2, 1)";
  const cssLines = Object.entries(cssVars).map(([key, value]) => `  ${key}: ${value};`).join("\n");
  cssChunks.push(`:where([data-theme-scope="${SCOPE_ID}"]) {
${cssLines}
}`);
  if (config.components?.buttons) {
    const buttonCss = generateButtonsCss(config, corners, shadows);
    cssChunks.push(buttonCss);
  }
  if (config.components?.cards) {
    const cardCss = generateCardsCss(config, corners, shadows);
    cssChunks.push(cardCss);
  }
  if (config.components?.inputs) {
    const inputCss = generateInputsCss(config, corners, shadows);
    cssChunks.push(inputCss);
  }
  if (config.overrides) {
    const overrideCss = generateOverrideCss(config.overrides);
    cssChunks.push(overrideCss);
  }
  return {
    cssVars,
    css: cssChunks.join("\n\n")
  };
}
function generateButtonsCss(config, corners, shadows) {
  const buttonConfig = config.components?.buttons;
  let variants = getDefaultButtonVariants();
  if (typeof buttonConfig === "object" && buttonConfig.variants) {
    const requestedIds = new Set(buttonConfig.variants);
    variants = variants.filter((v) => requestedIds.has(v.id));
  }
  const settings = {
    corners,
    shadow: shadows,
    borderWidth: "thin",
    fontWeight: 500,
    textTransform: "none"
  };
  return generateButtonCoreCss(SCOPE_ID, variants, settings);
}
function generateCardsCss(config, corners, shadows) {
  const cardConfig = config.components?.cards;
  let variants = getDefaultCardVariants();
  if (typeof cardConfig === "object" && cardConfig.variants) {
    const requestedIds = new Set(cardConfig.variants);
    variants = variants.filter((v) => requestedIds.has(v.id));
  }
  const settings = {
    corners,
    shadow: shadows,
    borderWidth: "thin"
  };
  return generateCardCoreCss(SCOPE_ID, variants, settings);
}
function generateInputsCss(config, corners, shadows) {
  const settings = getDefaultInputSettings();
  settings.corners = corners;
  settings.shadow = shadows === "none" ? "none" : "low";
  return generateInputCoreCss(SCOPE_ID, settings);
}
function generateOverrideCss(overrides) {
  const chunks = [];
  for (const [selector, rules] of Object.entries(overrides)) {
    chunks.push(`:where([data-theme-scope="${SCOPE_ID}"]) ${selector} {
  ${rules}
}`);
  }
  return chunks.join("\n\n");
}

// src/theme-bridge/ThemeBridgeProvider.tsx
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
function ThemeBridgeProvider({
  config,
  children,
  className = "",
  as: Tag = "div"
}) {
  const { css, cssVars } = React.useMemo(
    () => generateThemeBridgeCss(config),
    [config]
  );
  const inlineStyle = React.useMemo(() => {
    const style = {};
    for (const [key, value] of Object.entries(cssVars)) {
      style[key] = value;
    }
    return style;
  }, [cssVars]);
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: css } }),
    React.createElement(
      Tag,
      {
        "data-theme-scope": "sdk",
        className: `theme-scope ${className}`.trim(),
        style: inlineStyle
      },
      children
    )
  ] });
}
function useThemeBridgeCss(config) {
  return React.useMemo(() => generateThemeBridgeCss(config), [config]);
}
export {
  ThemeBridgeProvider,
  generateThemeBridgeCss,
  useThemeBridgeCss
};
//# sourceMappingURL=theme-bridge.mjs.map