import { j as o } from "../../node_modules/react/jsx-runtime.js";
import { useState as a } from "react";
import { cn as i } from "../../utils/index.js";
import { Icon as d } from "../Icon/index.js";
import { Button as p } from "../Button/base.js";
import "../Button/split-button.js";
import "../Button/login-with-button.js";
import { Tooltip as j, TooltipTrigger as C, TooltipContent as b } from "../Tooltip/index.js";
import { cva as v } from "../../node_modules/class-variance-authority/dist/index.js";
import { Row as g } from "../Layout/Row/index.js";
const n = v([], {
  variants: {
    variant: {
      code: "codeblock-code",
      input: "codeblock-input"
    }
  },
  defaultVariants: {
    variant: "code"
  }
});
function E({
  className: m,
  variant: t,
  children: s,
  hide: r,
  ...x
}) {
  const [e, l] = a(!1), [c, f] = a(r || !1), k = () => {
    l(!0), navigator.clipboard.writeText(s), setTimeout(() => l(!1), 2e3);
  }, u = () => {
    f(!c);
  }, h = c ? s.replace(/./g, "*") : s;
  return /* @__PURE__ */ o.jsxs(j, { open: e || void 0, children: [
    /* @__PURE__ */ o.jsxs(
      "div",
      {
        className: i("codeblock", n({ variant: t }), m),
        ...x,
        children: [
          h,
          /* @__PURE__ */ o.jsxs(g, { className: "!codeblock-row", children: [
            r && /* @__PURE__ */ o.jsx(
              p,
              {
                variant: "ghost",
                className: i(
                  n({ variant: t }),
                  "w-0 codeblock-secret"
                ),
                onClick: u,
                children: /* @__PURE__ */ o.jsx(d, { name: c ? "show" : "hide", size: "xs" })
              }
            ),
            /* @__PURE__ */ o.jsx(C, { children: /* @__PURE__ */ o.jsx(
              p,
              {
                variant: "ghost",
                className: i(n({ variant: t }), "codeblock-copy"),
                onClick: k,
                disabled: e,
                children: /* @__PURE__ */ o.jsx(d, { name: e ? "check" : "copy", size: "xs" })
              }
            ) })
          ] })
        ]
      }
    ),
    /* @__PURE__ */ o.jsx(b, { children: e ? "Copied!" : "Copy" })
  ] });
}
export {
  E as CodeBlock
};
