"use client";
import { jsxs as c, jsx as e } from "react/jsx-runtime";
import { CheckIcon as R, CopyIcon as A } from "@phosphor-icons/react";
import { forwardRef as S, useState as P, useRef as _, useCallback as I } from "react";
import { B as O } from "./button-6by9ntsa3nj553mq.js";
import { i as M } from "./input-lpa5fc75tgrraafv.js";
import { c as s } from "./cn-ct4n7r74mh8y0f48.js";
import { V, W as j, X as B, Y as D, Z as E, _ as L, $ as U, a0 as X, a1 as K, a2 as W, a3 as F, a4 as Y, a5 as Z } from "./vendor-base-ui-ie71jahf0czyf58j.js";
const T = V(), y = {
  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"
    }
  }
}, v = {
  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 $({
  size: o = v.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.size[o].classes
  );
}
function q() {
  const { toasts: o } = K();
  return /* @__PURE__ */ e(W, { className: "pointer-events-none fixed inset-0 isolate", children: o.map((a) => /* @__PURE__ */ e(F, { toast: a, className: "absolute", children: /* @__PURE__ */ e(
    Y,
    {
      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(Z, {})
    }
  ) }, a.id)) });
}
function G({ children: o }) {
  return /* @__PURE__ */ e(U, { children: /* @__PURE__ */ c(X, { toastManager: T, children: [
    /* @__PURE__ */ e(q, {}),
    o
  ] }) });
}
const H = S(
  ({
    text: o,
    textToCopy: a,
    className: C,
    size: m = v.size,
    onCopy: f,
    tooltip: n,
    labels: { copyAction: k = "Copy to clipboard" } = {}
  }, w) => {
    const [r, d] = P(!1), b = _(null), g = y.size[m], {
      text: z = "Copy",
      copiedText: p = "Copied",
      side: u = "top"
    } = n ?? {}, N = I(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(), h = i?.rangeCount ? i.getRangeAt(0) : null;
          t.select();
          try {
            document.execCommand("copy");
          } finally {
            document.body.removeChild(t), h && (i?.removeAllRanges(), i?.addRange(h));
          }
        }
        d(!0), n ? T.add({
          description: p,
          positionerProps: {
            anchor: b.current,
            side: u,
            sideOffset: 8
          },
          timeout: 1500,
          onClose() {
            d(!1);
          }
        }) : setTimeout(() => d(!1), 1500), f?.();
      } catch (t) {
        console.warn("Clipboard copy failed", t);
      }
    }, [o, f, n, p, u]), x = /* @__PURE__ */ c(
      O,
      {
        ref: b,
        size: g.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: N,
        "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(R, {})
            }
          ),
          /* @__PURE__ */ e(
            "span",
            {
              className: s(
                "flex items-center justify-center transition-all duration-200",
                r ? l.slide.end : l.slide.animate
              ),
              children: /* @__PURE__ */ e(A, {})
            }
          )
        ]
      }
    );
    return /* @__PURE__ */ c(
      "div",
      {
        ref: w,
        className: s(
          M({ size: g.buttonSize }),
          $({ size: m }),
          C
        ),
        children: [
          /* @__PURE__ */ e("span", { className: "grow truncate ps-4 pe-2", children: o }),
          n ? /* @__PURE__ */ e(G, { children: /* @__PURE__ */ c(
            j,
            {
              disabled: r,
              onOpenChange: (t, i) => {
                i.reason === "trigger-press" && i.cancel();
              },
              children: [
                /* @__PURE__ */ e(B, { render: x }),
                /* @__PURE__ */ e(D, { children: /* @__PURE__ */ e(E, { side: u, sideOffset: 8, children: /* @__PURE__ */ e(
                  L,
                  {
                    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: z
                  }
                ) }) })
              ]
            }
          ) }) : x,
          /* @__PURE__ */ e("span", { className: "sr-only", "aria-live": "polite", children: r ? p : "" })
        ]
      }
    );
  }
);
H.displayName = "ClipboardText";
export {
  H as C
};
//# sourceMappingURL=clipboard-text-f9q753udny1uyxr5.js.map
