"use client";
import { jsxs as c, jsx as e } from "react/jsx-runtime";
import { CheckIcon as A, CopyIcon as S } from "@phosphor-icons/react";
import { forwardRef as P, useState as _, useRef as I, useCallback as O } from "react";
import { B as V } from "./button-ebfdg9mkhojue36n.js";
import { i as M } from "./input-ckl5misj0jd9cu5r.js";
import { r as y } from "./resolve-variant-gw6eh7fa4st8ej7m.js";
import { c as s } from "./vendor-styling-ofvnbcuht98q88oo.js";
import { V as j, W as B, X as D, Y as E, Z as L, _ as U, $ as X, a0 as K, a1 as W, a2 as F, a3 as Y, a4 as Z, a5 as $ } from "./vendor-base-ui-elpbzr8xeffrz4h2.js";
const v = j(), C = {
  size: {
    sm: {
      classes: "text-xs",
      buttonSize: "sm",
      description: "Small clipboard text for compact UIs"
    },
    base: {
      classes: "text-sm",
      buttonSize: "base",
      description: "Default clipboard text size"
    },
    lg: {
      classes: "text-sm",
      buttonSize: "lg",
      description: "Large clipboard text for prominent display"
    }
  }
}, d = {
  size: "lg"
}, l = {
  slide: {
    initial: "pointer-events-none absolute inset-0 flex items-center justify-center opacity-0 translate-y-full",
    animate: "translate-y-0 opacity-100",
    end: "pointer-events-none absolute inset-0 flex items-center justify-center opacity-0 -translate-y-full"
  }
};
function q({
  size: o = d.size
} = {}) {
  return s(
    // Base styles
    "flex items-center overflow-hidden bg-kumo-base px-0 font-mono",
    // Apply size styles from KUMO_CLIPBOARD_TEXT_VARIANTS
    y(C.size, o, d.size).classes
  );
}
function G() {
  const { toasts: o } = W();
  return /* @__PURE__ */ e(F, { className: "pointer-events-none fixed inset-0 isolate", children: o.map((a) => /* @__PURE__ */ e(Y, { toast: a, className: "absolute", children: /* @__PURE__ */ e(
    Z,
    {
      toast: a,
      className: s(
        "flex origin-[var(--transform-origin)] flex-col rounded-md bg-kumo-base px-3 py-1.5 text-xs text-kumo-default font-sans",
        "shadow-lg shadow-kumo-tip-shadow outline outline-kumo-fill"
      ),
      children: /* @__PURE__ */ e($, {})
    }
  ) }, a.id)) });
}
function H({ children: o }) {
  return /* @__PURE__ */ e(X, { children: /* @__PURE__ */ c(K, { toastManager: v, children: [
    /* @__PURE__ */ e(G, {}),
    o
  ] }) });
}
const J = P(
  ({
    text: o,
    textToCopy: a,
    className: z,
    size: f = d.size,
    onCopy: b,
    tooltip: n,
    labels: { copyAction: k = "Copy to clipboard" } = {}
  }, w) => {
    const [r, p] = _(!1), g = I(null), x = y(C.size, f, d.size), {
      text: N = "Copy",
      copiedText: u = "Copied",
      side: m = "top"
    } = n ?? {}, R = O(async () => {
      try {
        if (typeof navigator < "u" && navigator.clipboard && typeof navigator.clipboard.writeText == "function")
          await navigator.clipboard.writeText(a ?? o);
        else if (typeof document < "u") {
          const t = document.createElement("textarea");
          t.value = a ?? o, t.setAttribute("readonly", ""), t.style.position = "absolute", t.style.left = "-9999px", document.body.appendChild(t);
          const i = document.getSelection(), T = i?.rangeCount ? i.getRangeAt(0) : null;
          t.select();
          try {
            document.execCommand("copy");
          } finally {
            document.body.removeChild(t), T && (i?.removeAllRanges(), i?.addRange(T));
          }
        }
        p(!0), n ? v.add({
          description: u,
          positionerProps: {
            anchor: g.current,
            side: m,
            sideOffset: 8
          },
          timeout: 1500,
          onClose() {
            p(!1);
          }
        }) : setTimeout(() => p(!1), 1500), b?.();
      } catch (t) {
        console.warn("Clipboard copy failed", t);
      }
    }, [o, b, n, u, m]), h = /* @__PURE__ */ c(
      V,
      {
        ref: g,
        size: x.buttonSize,
        variant: "ghost",
        className: s(
          "rounded-l-none rounded-r-[inherit] border-l! border-kumo-line! px-3 relative isolate overflow-hidden transition-all duration-200",
          "focus:ring-inset focus:ring-kumo-focus/50",
          "focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-kumo-brand"
        ),
        onClick: R,
        "aria-label": k,
        children: [
          /* @__PURE__ */ e(
            "span",
            {
              className: s(
                "flex items-center gap-1 transition-all duration-200",
                r ? l.slide.animate : l.slide.initial
              ),
              children: /* @__PURE__ */ e(A, {})
            }
          ),
          /* @__PURE__ */ e(
            "span",
            {
              className: s(
                "flex items-center justify-center transition-all duration-200",
                r ? l.slide.end : l.slide.animate
              ),
              children: /* @__PURE__ */ e(S, {})
            }
          )
        ]
      }
    );
    return /* @__PURE__ */ c(
      "div",
      {
        ref: w,
        className: s(
          M({ size: x.buttonSize }),
          q({ size: f }),
          z
        ),
        children: [
          /* @__PURE__ */ e("span", { className: "grow truncate ps-4 pe-2", children: o }),
          n ? /* @__PURE__ */ e(H, { children: /* @__PURE__ */ c(
            B,
            {
              disabled: r,
              onOpenChange: (t, i) => {
                i.reason === "trigger-press" && i.cancel();
              },
              children: [
                /* @__PURE__ */ e(D, { render: h }),
                /* @__PURE__ */ e(E, { children: /* @__PURE__ */ e(L, { side: m, sideOffset: 8, children: /* @__PURE__ */ e(
                  U,
                  {
                    className: s(
                      "flex origin-[var(--transform-origin)] flex-col rounded-md bg-kumo-base px-3 py-1.5 text-xs text-kumo-default",
                      "shadow-lg shadow-kumo-tip-shadow outline outline-kumo-fill"
                    ),
                    children: N
                  }
                ) }) })
              ]
            }
          ) }) : h,
          /* @__PURE__ */ e("span", { className: "sr-only", "aria-live": "polite", children: r ? u : "" })
        ]
      }
    );
  }
);
J.displayName = "ClipboardText";
export {
  J as C
};
//# sourceMappingURL=clipboard-text-isb05zkg2aox0tp6.js.map
