"use client";
import { jsx, jsxs } from 'react/jsx-runtime';
import { memo, useCallback, useMemo } from 'react';
import { p as prismExports } from '../../../../../../_virtual/index2.mjs';
import { CheckIcon, CopyIcon } from 'lucide-react';
import { useCopyToClipboard } from '../../../hooks/use-copy-to-clipboard.mjs';
import { Button } from '../../button.mjs';
import highlighter from '../../../../../../node_modules/.pnpm/react-syntax-highlighter@16.1.0_react@19.2.0/node_modules/react-syntax-highlighter/dist/esm/prism.mjs';

const CodeBlock = memo(function CodeBlock2({
  language,
  value
}) {
  const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
  const onCopy = useCallback(() => {
    if (isCopied) return;
    copyToClipboard(value);
  }, [isCopied, copyToClipboard, value]);
  const customStyle = useMemo(() => ({
    margin: 0,
    width: "100%",
    background: "transparent",
    padding: "1.5rem 1rem"
  }), []);
  const codeTagProps = useMemo(() => ({
    style: {
      fontSize: "0.9rem",
      fontFamily: "var(--font-mono)"
    }
  }), []);
  const highlighted = useMemo(
    () => /* @__PURE__ */ jsx(
      highlighter,
      {
        language,
        style: prismExports.coldarkDark,
        PreTag: "div",
        showLineNumbers: true,
        customStyle,
        codeTagProps,
        children: value
      }
    ),
    [language, value, customStyle, codeTagProps]
  );
  return /* @__PURE__ */ jsxs("div", { className: "codeblock relative w-full font-sans border border-border rounded-md", "data-testid": `codeblock-${language}`, children: [
    /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between bg-background px-6 py-2 pr-4 text-foreground border-b border-border rounded-t-sm", children: [
      /* @__PURE__ */ jsx("span", { className: "text-md uppercase font-semibold", children: language }),
      /* @__PURE__ */ jsx("div", { className: "flex items-center space-x-1", children: /* @__PURE__ */ jsxs(
        Button,
        {
          variant: "ghost",
          size: "icon",
          onClick: onCopy,
          children: [
            isCopied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}),
            /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Copy code" })
          ]
        }
      ) })
    ] }),
    highlighted
  ] });
});

export { CodeBlock };
