'use strict';

var jsxRuntime = require('react/jsx-runtime');
var react = require('@chakra-ui/react');
var CopyButton = require('../CopyButton/CopyButton.cjs');
var reactSyntaxHighlighter = require('react-syntax-highlighter');
var nightOwl = require('./theme/nightOwl.cjs');
var prism = require('react-syntax-highlighter/dist/cjs/styles/prism/prism');
var jsx2 = require('react-syntax-highlighter/dist/cjs/languages/prism/jsx');
var tsx = require('react-syntax-highlighter/dist/cjs/languages/prism/tsx');
var bash = require('react-syntax-highlighter/dist/cjs/languages/prism/bash');
var python = require('react-syntax-highlighter/dist/cjs/languages/prism/python');
var go = require('react-syntax-highlighter/dist/cjs/languages/prism/go');
var java = require('react-syntax-highlighter/dist/cjs/languages/prism/java');

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;
};
reactSyntaxHighlighter.PrismLight.registerLanguage("jsx", jsx2);
reactSyntaxHighlighter.PrismLight.registerLanguage("tsx", tsx);
reactSyntaxHighlighter.PrismLight.registerLanguage("bash", bash);
reactSyntaxHighlighter.PrismLight.registerLanguage("python", python);
reactSyntaxHighlighter.PrismLight.registerLanguage("go", go);
reactSyntaxHighlighter.PrismLight.registerLanguage("java", 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__ */ jsxRuntime.jsxs(react.Box, { position: "relative", zIndex: "0", children: [
    /* @__PURE__ */ jsxRuntime.jsx(
      react.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__ */ jsxRuntime.jsx(react.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
          reactSyntaxHighlighter.PrismLight,
          __spreadProps(__spreadValues({}, otherProps), {
            PreTag: "div",
            language,
            style: theme === "dark" ? nightOwl : 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__ */ jsxRuntime.jsx(react.Box, { position: "absolute", top: 1, right: 1, children: /* @__PURE__ */ jsxRuntime.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"
      }
    ) })
  ] });
}

module.exports = CodeBlock;
//# sourceMappingURL=CodeBlock.cjs.map
