import { jsxs, jsx } from 'react/jsx-runtime';
import { Box } from '@chakra-ui/react';
import CopyButton from '../CopyButton/CopyButton.js';
import { PrismLight } from 'react-syntax-highlighter';
import nightOwlTheme from './theme/nightOwl.js';
import prism from 'react-syntax-highlighter/dist/cjs/styles/prism/prism';
import jsx2 from 'react-syntax-highlighter/dist/cjs/languages/prism/jsx';
import tsx from 'react-syntax-highlighter/dist/cjs/languages/prism/tsx';
import bash from 'react-syntax-highlighter/dist/cjs/languages/prism/bash';
import python from 'react-syntax-highlighter/dist/cjs/languages/prism/python';
import go from 'react-syntax-highlighter/dist/cjs/languages/prism/go';
import java from 'react-syntax-highlighter/dist/cjs/languages/prism/java';
import protobuf from 'react-syntax-highlighter/dist/cjs/languages/prism/protobuf';

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
PrismLight.registerLanguage("jsx", jsx2);
PrismLight.registerLanguage("tsx", tsx);
PrismLight.registerLanguage("bash", bash);
PrismLight.registerLanguage("python", python);
PrismLight.registerLanguage("go", go);
PrismLight.registerLanguage("java", java);
PrismLight.registerLanguage("protobuf", protobuf);
PrismLight.registerLanguage("json", java);
function CodeBlock(_a) {
  var _b = _a, {
    codeString,
    language,
    removeLineBreaksFromCopy = false,
    showLineNumbers = false,
    showCopyButton = true,
    highlightLines,
    theme = "dark"
  } = _b, otherProps = __objRest(_b, [
    "codeString",
    "language",
    "removeLineBreaksFromCopy",
    "showLineNumbers",
    "showCopyButton",
    "highlightLines",
    "theme"
  ]);
  const shouldHighlightLine = (index) => {
    if (!highlightLines) {
      return false;
    }
    const lineNumber = index + 1;
    const inRange = lineNumber >= highlightLines[0] && lineNumber <= highlightLines[1];
    return inRange;
  };
  const backgroundColor = theme === "dark" ? "#011627" : "#F5F2F0";
  return /* @__PURE__ */ jsxs(Box, { position: "relative", zIndex: "0", children: [
    /* @__PURE__ */ jsx(
      Box,
      {
        px: 0,
        rounded: "md",
        bg: backgroundColor,
        color: "white",
        overflow: "hidden",
        __css: {
          "&::-webkit-scrollbar": {
            overflow: "visible",
            width: "4px",
            borderRadius: "full"
          },
          "&::-webkit-scrollbar-thumb": {
            background: backgroundColor,
            borderRadius: "full"
          },
          "&::-webkit-scrollbar-track": {
            background: backgroundColor,
            borderRadius: "full"
          },
          "&::-webkit-scrollbar-corner": {
            background: backgroundColor
          }
        },
        children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
          PrismLight,
          __spreadProps(__spreadValues({}, otherProps), {
            PreTag: "div",
            language,
            style: theme === "dark" ? nightOwlTheme : prism,
            showLineNumbers,
            wrapLines: true,
            customStyle: {
              margin: 0,
              padding: "10px",
              lineHeight: "1.3rem"
            },
            codeTagProps: {
              className: "break-all"
            },
            lineNumberStyle: {
              opacity: "0.4",
              userSelect: "none",
              paddingRight: "20px"
            },
            lineProps: (lineNumber) => {
              const highlight = shouldHighlightLine(lineNumber - 1);
              return {
                style: {
                  backgroundColor: highlight ? "whiteAlpha.200" : "initial",
                  opacity: highlightLines ? highlight ? 1 : 0.5 : 1
                }
              };
            },
            children: removeLineBreaksFromCopy ? codeString.replace(/[\n\r]/g, "") : codeString
          })
        ) })
      }
    ),
    showCopyButton && /* @__PURE__ */ jsx(Box, { position: "absolute", top: 1, right: 1, children: /* @__PURE__ */ jsx(
      CopyButton,
      {
        content: removeLineBreaksFromCopy ? codeString.replace(/[\n\r]/g, "") : codeString,
        background: backgroundColor,
        color: theme === "dark" ? "whiteAlpha.900" : "black.900",
        _hover: {
          background: backgroundColor,
          color: "brand.400"
        },
        borderRadius: "base",
        padding: "0.4rem"
      }
    ) })
  ] });
}

export { CodeBlock as default };
//# sourceMappingURL=CodeBlock.js.map
