"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const React = require('react');
const index = require('../../../../../../_virtual/index2.cjs');
const LucideIcons = require('lucide-react');
const useCopyToClipboard = require('../../../hooks/use-copy-to-clipboard.cjs');
const button = require('../../button.cjs');
const prism = require('../../../../../../node_modules/.pnpm/react-syntax-highlighter@16.1.0_react@19.2.0/node_modules/react-syntax-highlighter/dist/esm/prism.cjs');

const CodeBlock = React.memo(function CodeBlock2({
  language,
  value
}) {
  const { isCopied, copyToClipboard } = useCopyToClipboard.useCopyToClipboard({ timeout: 2e3 });
  const onCopy = React.useCallback(() => {
    if (isCopied) return;
    copyToClipboard(value);
  }, [isCopied, copyToClipboard, value]);
  const customStyle = React.useMemo(() => ({
    margin: 0,
    width: "100%",
    background: "transparent",
    padding: "1.5rem 1rem"
  }), []);
  const codeTagProps = React.useMemo(() => ({
    style: {
      fontSize: "0.9rem",
      fontFamily: "var(--font-mono)"
    }
  }), []);
  const highlighted = React.useMemo(
    () => /* @__PURE__ */ jsxRuntime.jsx(
      prism,
      {
        language,
        style: index.prismExports.coldarkDark,
        PreTag: "div",
        showLineNumbers: true,
        customStyle,
        codeTagProps,
        children: value
      }
    ),
    [language, value, customStyle, codeTagProps]
  );
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "codeblock relative w-full font-sans border border-border rounded-md", "data-testid": `codeblock-${language}`, children: [
    /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx("span", { className: "text-md uppercase font-semibold", children: language }),
      /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center space-x-1", children: /* @__PURE__ */ jsxRuntime.jsxs(
        button.Button,
        {
          variant: "ghost",
          size: "icon",
          onClick: onCopy,
          children: [
            isCopied ? /* @__PURE__ */ jsxRuntime.jsx(LucideIcons.CheckIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(LucideIcons.CopyIcon, {}),
            /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Copy code" })
          ]
        }
      ) })
    ] }),
    highlighted
  ] });
});

exports.CodeBlock = CodeBlock;
