import { cache } from 'react';
import { codeToHtml } from 'shiki';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { CodeBlockCopy } from './code-block-copy.js';
import { jsxs, jsx } from 'react/jsx-runtime';

// src/ai/code-block/code-block.tsx
function cn(...inputs) {
  return twMerge(clsx(inputs));
}
var LABEL_TO_LANG = {
  pnpm: "bash",
  npm: "bash",
  yarn: "bash",
  bun: "bash",
  bash: "bash",
  sh: "bash",
  shell: "bash",
  zsh: "bash",
  ts: "ts",
  typescript: "ts",
  tsx: "tsx",
  js: "js",
  javascript: "js",
  jsx: "jsx",
  json: "json",
  css: "css",
  html: "html",
  md: "md",
  markdown: "md",
  py: "py",
  python: "py",
  text: "text",
  prompt: "text",
  plain: "text"
};
var DEFAULT_THEMES = { light: "github-light-high-contrast", dark: "github-dark" };
var cachedCodeToHtml = cache(
  async (code, lang, themesKey, themes) => {
    return codeToHtml(code, { lang, themes, defaultColor: false });
  }
);
function resolveLang(label, language) {
  if (language) return language;
  if (label) {
    const fromLabel = LABEL_TO_LANG[label.toLowerCase()];
    if (fromLabel) return fromLabel;
  }
  return "text";
}
async function CodeBlock({
  code,
  label,
  language,
  themes = DEFAULT_THEMES,
  className
}) {
  const lang = resolveLang(label, language);
  const themesKey = `${themes.light}|${themes.dark}`;
  const html = await cachedCodeToHtml(code, lang, themesKey, themes);
  const displayLabel = label ?? lang;
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: cn(
        "group relative overflow-hidden rounded-lg border bg-card text-card-foreground",
        className
      ),
      children: [
        /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b bg-muted/40 px-3 py-1.5", children: [
          /* @__PURE__ */ jsx("span", { className: "font-mono text-xs font-medium text-muted-foreground", children: displayLabel }),
          /* @__PURE__ */ jsx(CodeBlockCopy, { code })
        ] }),
        /* @__PURE__ */ jsx(
          "div",
          {
            "data-shiki": "",
            className: "overflow-x-auto p-4 font-mono text-sm [&_pre]:!bg-transparent",
            dangerouslySetInnerHTML: { __html: html }
          }
        )
      ]
    }
  );
}

export { CodeBlock };
//# sourceMappingURL=code-block.js.map
//# sourceMappingURL=code-block.js.map