import { jsxs as i, jsx as t, Fragment as u } from "react/jsx-runtime";
import { useState as C } from "react";
import _ from "copy-to-clipboard";
import e from "highlight.js/lib/core";
import s from "highlight.js/lib/languages/javascript";
import g from "highlight.js/lib/languages/typescript";
import z from "highlight.js/lib/languages/json";
import F from "highlight.js/lib/languages/elixir";
import M from "highlight.js/lib/languages/java";
import B from "highlight.js/lib/languages/swift";
import d from "highlight.js/lib/languages/objectivec";
import f from "highlight.js/lib/languages/kotlin";
import h from "highlight.js/lib/languages/protobuf";
import x from "highlight.js/lib/languages/python";
import y from "highlight.js/lib/languages/yaml";
import L from "highlight.js/lib/languages/shell";
import b from "highlight.js/lib/languages/diff";
import w from "highlight.js/lib/languages/plaintext";
import P from "highlight.js/lib/languages/markdown";
import "highlight.js/styles/atom-one-dark.css";
import { FileCopy as S, Check as T } from "@mui/icons-material";
import o from "../Colors/themes/default.js";
import { styled as A } from "../Theme/index.js";
import E from "./LightBox.js";
e.registerLanguage("javascript", s);
e.registerLanguage("js", s);
e.registerLanguage("jsx", s);
e.registerLanguage("typescript", g);
e.registerLanguage("ts", g);
e.registerLanguage("tsx", g);
e.registerLanguage("json", z);
e.registerLanguage("elixir", F);
e.registerLanguage("java", M);
e.registerLanguage("kotlin", f);
e.registerLanguage("kt", f);
e.registerLanguage("protobuf", h);
e.registerLanguage("protobuffer", h);
e.registerLanguage("python", x);
e.registerLanguage("py", x);
e.registerLanguage("yaml", y);
e.registerLanguage("yml", y);
e.registerLanguage("shell", L);
e.registerLanguage("sh", L);
e.registerLanguage("plaintext", w);
e.registerLanguage("text", w);
e.registerLanguage("patch", b);
e.registerLanguage("diff", b);
e.registerLanguage("swift", B);
e.registerLanguage("objectivec", d);
e.registerLanguage("oc", d);
e.registerLanguage("markdown", P);
function le({
  code: r = "",
  language: a = "text",
  children: k = null,
  dark: j = !0,
  showDefaultText: v = !0,
  ...$
}) {
  const [l, p] = C(!1), c = r || k, N = () => {
    l || (_(c), p(!0), setTimeout(() => {
      p(!1);
    }, 1500));
  }, m = /* @__PURE__ */ i(H, { ...$, children: [
    /* @__PURE__ */ t("span", { className: "codeblock__inner", children: /* @__PURE__ */ t(
      "code",
      {
        className: `hljs ${a}`,
        dangerouslySetInnerHTML: { __html: e.highlightAuto(c, [a]).value }
      }
    ) }),
    /* @__PURE__ */ i("div", { className: "copy-button", onClick: N, children: [
      v && /* @__PURE__ */ t("span", { className: "default-text", children: a }),
      /* @__PURE__ */ t("span", { className: "hover-text", children: l ? /* @__PURE__ */ i(u, { children: [
        /* @__PURE__ */ t(T, { className: "copy-icon" }),
        /* @__PURE__ */ t("span", { className: "button-lang-text", children: "copied" })
      ] }) : /* @__PURE__ */ i(u, { children: [
        /* @__PURE__ */ t(S, { className: "copy-icon" }),
        /* @__PURE__ */ t("span", { className: "button-lang-text", children: "copy" })
      ] }) })
    ] })
  ] });
  return j ? m : /* @__PURE__ */ t(E, { children: m });
}
const n = "source-code-pro, Menlo, Monaco, Consolas, Courier New, monospace !important", H = A("pre", {
  shouldForwardProp: (r) => r !== "sx"
})`
  font-family: ${n};
  display: block;
  font-size: 14px;
  line-height: 1.42857143;
  margin: 0 0 32px;
  word-break: break-word;
  word-wrap: break-word;
  text-align: left;
  border-radius: 5px;
  border: 1px solid;
  border-color: ${({ theme: r }) => r.palette.divider};
  background: ${({ theme: r }) => r.palette.background.default};
  color: ${({ theme: r }) => r.palette.common.white};
  position: relative;

  .codeblock__inner {
    display: block;
    width: 100%;
    max-height: 46.25rem;
    overflow: auto;
  }

  .copy-button {
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 8px;
    right: 24px;
    padding: 4px;
    min-width: 72px;
    height: 24px;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    transition: all ease 0.2s;

    .copy-icon {
      font-size: 16px;
      color: ${o.common.white};
    }

    .hover-text {
      display: none;
    }
    .default-text {
      font-size: 12px;
      color: ${o.common.white};
    }
  }

  &:hover {
    .copy-button {
      display: flex;
      background: ${o.primary.main};

      .hover-text {
        display: flex;
        justify-content: center;
        align-items: center;
        color: ${o.common.white};
      }
      .default-text {
        display: none;
        font-size: 12px;
      }
    }
  }

  .button-lang-text {
    margin-left: 4px;
    font-size: 12px;
    color: ${o.common.white};
  }

  code {
    counter-reset: line;
    counter-increment: line;
    padding: 16px;
    font-family: ${n};
    color: ${o.common.white};
    * {
      font-family: ${n};
    }
  }

  .hljs * {
    white-space: normal; // autowrap
  }
`;
export {
  le as default
};
