"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const Highlight = require("prism-react-renderer");
const CopyIcon = require("./CopyIcon.cjs");
const prismTheme = require("./prism-theme.cjs");
const Prism_styles = require("./Prism.styles.cjs");
const factory = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/factory/factory.cjs");
const useProps = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/MantineProvider/use-props/use-props.cjs");
const useComputedColorScheme = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/MantineProvider/use-mantine-color-scheme/use-computed-color-scheme.cjs");
const MantineThemeProvider = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/MantineProvider/MantineThemeProvider/MantineThemeProvider.cjs");
const useClipboard = require("../../node_modules/.pnpm/@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-clipboard/use-clipboard.cjs");
const ScrollArea = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/ScrollArea/ScrollArea.cjs");
const useStyles = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/styles-api/use-styles/use-styles.cjs");
const Box = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/Box/Box.cjs");
const Tooltip = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Tooltip/Tooltip.cjs");
const ActionIcon = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/ActionIcon/ActionIcon.cjs");
const getThemeColor = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/MantineProvider/color-functions/get-theme-color/get-theme-color.cjs");
const prismDefaultProps = {
  noCopy: false,
  copyLabel: "Copy code",
  copiedLabel: "Copied",
  withLineNumbers: false,
  trim: true,
  highlightLines: {},
  scrollAreaComponent: ScrollArea.ScrollArea,
  getPrismTheme: prismTheme.getPrismTheme
};
const Prism = factory.factory((_props, ref) => {
  const props = useProps.useProps("CodeHighlight", prismDefaultProps, _props);
  const {
    className,
    children,
    language,
    noCopy,
    classNames,
    styles,
    copyLabel,
    copiedLabel,
    withLineNumbers,
    highlightLines,
    scrollAreaComponent: ScrollAreaComponent,
    colorScheme,
    trim,
    unstyled,
    radius,
    getPrismTheme,
    ...others
  } = useProps.useProps("Prism", prismDefaultProps, props);
  const code = trim && typeof children === "string" ? children.trim() : children;
  const maxLineSize = code.split("\n").length.toString().length;
  const globalColorScheme = useComputedColorScheme.useComputedColorScheme();
  const theme = MantineThemeProvider.useMantineTheme();
  const clipboard = useClipboard.useClipboard();
  const _colorScheme = colorScheme || globalColorScheme;
  const { classes } = Prism_styles.default({
    colorScheme: _colorScheme,
    native: ScrollAreaComponent !== ScrollArea.ScrollArea,
    maxLineSize,
    radius
  });
  const getStyles = useStyles.useStyles({
    name: "Prism",
    props,
    classNames,
    classes,
    styles,
    unstyled
  });
  return /* @__PURE__ */ jsxRuntime.jsxs(Box.Box, { ...getStyles("root"), ...others, ref, translate: "no", children: [
    !noCopy && /* @__PURE__ */ jsxRuntime.jsx(
      Tooltip.Tooltip,
      {
        label: clipboard.copied ? copiedLabel : copyLabel,
        position: "left",
        withArrow: true,
        arrowSize: 6,
        offset: 6,
        color: clipboard.copied ? "teal" : void 0,
        unstyled,
        children: /* @__PURE__ */ jsxRuntime.jsx(
          ActionIcon.ActionIcon,
          {
            ...getStyles("copy"),
            "aria-label": clipboard.copied ? copiedLabel : copyLabel,
            onClick: () => clipboard.copy(code),
            unstyled,
            children: /* @__PURE__ */ jsxRuntime.jsx(CopyIcon.CopyIcon, { copied: clipboard.copied })
          }
        )
      }
    ),
    /* @__PURE__ */ jsxRuntime.jsx(Highlight, { ...Highlight.defaultProps, theme: getPrismTheme(theme, _colorScheme), code, language, children: ({ className: inheritedClassName, style: inheritedStyle, tokens, getLineProps, getTokenProps }) => /* @__PURE__ */ jsxRuntime.jsx(ScrollAreaComponent, { ...getStyles("scrollArea"), dir: "ltr", children: /* @__PURE__ */ jsxRuntime.jsx("pre", { ...getStyles("code", { className: inheritedClassName, style: inheritedStyle }), dir: "ltr", children: tokens.map((line, index) => {
      var _a, _b;
      if (index === tokens.length - 1 && line.length === 1 && line[0].content === "\n") {
        return null;
      }
      const lineNumber = index + 1;
      const { key, ...lineProps } = getLineProps({ line, key: index });
      const shouldHighlight = lineNumber in highlightLines;
      const lineThemeColor = getThemeColor.getThemeColor((_a = highlightLines == null ? void 0 : highlightLines[lineNumber]) == null ? void 0 : _a.color, theme);
      const lineColor = lineThemeColor;
      return /* @__PURE__ */ jsxRuntime.jsxs(
        "div",
        {
          ...lineProps,
          ...getStyles("line", {
            className: lineProps.className,
            style: { ...shouldHighlight ? { backgroundColor: lineColor } : null }
          }),
          children: [
            withLineNumbers && /* @__PURE__ */ jsxRuntime.jsx(
              "div",
              {
                ...getStyles("lineNumber", {
                  style: { color: shouldHighlight ? lineThemeColor : void 0 }
                }),
                children: ((_b = highlightLines == null ? void 0 : highlightLines[lineNumber]) == null ? void 0 : _b.label) || lineNumber
              }
            ),
            /* @__PURE__ */ jsxRuntime.jsx("div", { ...getStyles("lineContent"), children: line.map((token, key2) => {
              var _a2;
              const { key: tokenKey, ...tokenProps } = getTokenProps({ token, key: key2 });
              return /* @__PURE__ */ jsxRuntime.jsx(
                "span",
                {
                  ...tokenProps,
                  style: {
                    ...tokenProps.style,
                    color: shouldHighlight ? (
                      // ? theme.f[n.themeColor(
                      //     highlightLines?.[lineNumber]?.color,
                      //     _colorScheme === 'dark' ? 5 : 8
                      //   )]
                      lineThemeColor
                    ) : (_a2 = tokenProps == null ? void 0 : tokenProps.style) == null ? void 0 : _a2.color
                  }
                },
                tokenKey
              );
            }) })
          ]
        },
        key
      );
    }).filter(Boolean) }) }) })
  ] });
});
Prism.displayName = "@mantine/prism/Prism";
exports.Prism = Prism;
