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