import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__chakra_ui_react__ from "@chakra-ui/react";
import * as __WEBPACK_EXTERNAL_MODULE__CopyButton_CopyButton_mjs__ from "../CopyButton/CopyButton.mjs";
import * as __WEBPACK_EXTERNAL_MODULE_react_syntax_highlighter__ from "react-syntax-highlighter";
import * as __WEBPACK_EXTERNAL_MODULE__theme_nightOwl_mjs__ from "./theme/nightOwl.mjs";
import * as __WEBPACK_EXTERNAL_MODULE_react_syntax_highlighter_dist_cjs_styles_prism_prism__ from "react-syntax-highlighter/dist/cjs/styles/prism/prism";
// Need to reexport due to conflicting dist build
function CodeBlock({ codeString, language, removeLineBreaksFromCopy = false, showLineNumbers = false, showCopyButton = true, highlightLines, theme = 'dark', ...otherProps }) {
    const shouldHighlightLine = (index)=>{
        if (!highlightLines) return false;
        const lineNumber = index + 1;
        const inRange = lineNumber >= highlightLines[0] && lineNumber <= highlightLines[1];
        return inRange;
    };
    const backgroundColor = 'dark' === theme ? '#011627' : '#F5F2F0';
    return /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Box, {
        position: "relative",
        zIndex: "0"
    }, /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_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
            }
        }
    }, /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Box, null, /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE_react_syntax_highlighter__.Prism, {
        ...otherProps,
        PreTag: "div",
        language: language,
        style: 'dark' === theme ? __WEBPACK_EXTERNAL_MODULE__theme_nightOwl_mjs__["default"] : __WEBPACK_EXTERNAL_MODULE_react_syntax_highlighter_dist_cjs_styles_prism_prism__["default"],
        showLineNumbers: 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
                }
            };
        }
    }, removeLineBreaksFromCopy ? codeString.replace(/[\n\r]/g, '') : codeString))), showCopyButton && /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Box, {
        position: "absolute",
        top: 1,
        right: 1
    }, /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__CopyButton_CopyButton_mjs__["default"], {
        content: removeLineBreaksFromCopy ? codeString.replace(/[\n\r]/g, '') : codeString,
        background: backgroundColor,
        color: 'dark' === theme ? 'whiteAlpha.900' : 'black.900',
        _hover: {
            background: backgroundColor,
            color: 'brand.400'
        },
        borderRadius: "base",
        padding: "0.4rem"
    })));
}
/* ESM default export */ const CodeBlock_rslib_entry_ = CodeBlock;
export { CodeBlock_rslib_entry_ as default };
