"use client";
import { jsxs as g, jsx as i } from "react/jsx-runtime";
import { CheckIcon as C, ClipboardIcon as y } from "@phosphor-icons/react";
import { forwardRef as T, useState as z, useCallback as v, useEffect as h } from "react";
import { B as A } from "./button-E2-hZMZE.js";
import { i as S } from "./input-Dqvc2AB_.js";
import { c as d } from "./cn-Bhsu1vx2.js";
const p = {
  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"
    }
  }
}, m = {
  size: "lg"
};
function R({
  size: t = m.size
} = {}) {
  return d(
    // Base styles
    "flex items-center overflow-hidden bg-kumo-base px-0 font-mono",
    // Apply size styles from KUMO_CLIPBOARD_TEXT_VARIANTS
    p.size[t].classes
  );
}
const I = T(
  ({
    text: t,
    className: u,
    size: n = m.size,
    onCopy: r
  }, f) => {
    const [o, s] = z(!1), c = p.size[n], b = v(async () => {
      try {
        if (typeof navigator < "u" && navigator.clipboard && typeof navigator.clipboard.writeText == "function") {
          await navigator.clipboard.writeText(t), s(!0), r?.();
          return;
        }
      } catch {
      }
      if (typeof document < "u") {
        const e = document.createElement("textarea");
        e.value = t, e.setAttribute("readonly", ""), e.style.position = "absolute", e.style.left = "-9999px", document.body.appendChild(e);
        const a = document.getSelection(), l = a?.rangeCount ? a.getRangeAt(0) : null;
        e.select();
        try {
          document.execCommand("copy"), s(!0), r?.();
        } catch (x) {
          console.warn("Clipboard copy failed", x);
        } finally {
          document.body.removeChild(e), l && (a?.removeAllRanges(), a?.addRange(l));
        }
      }
    }, [t, r]);
    return h(() => {
      if (o) {
        const e = setTimeout(() => {
          s(!1);
        }, 2e3);
        return () => clearTimeout(e);
      }
    }, [o]), /* @__PURE__ */ g(
      "div",
      {
        ref: f,
        className: d(
          S({ size: c.buttonSize }),
          R({ size: n }),
          u
        ),
        children: [
          /* @__PURE__ */ i("span", { className: "grow px-4", children: t }),
          /* @__PURE__ */ i(
            A,
            {
              size: c.buttonSize,
              variant: "ghost",
              className: "rounded-none border-l! border-kumo-line! px-3",
              onClick: b,
              "aria-label": o ? "Copied" : "Copy to clipboard",
              "aria-pressed": o,
              children: o ? /* @__PURE__ */ i(C, {}) : /* @__PURE__ */ i(y, {})
            }
          ),
          /* @__PURE__ */ i("span", { className: "sr-only", "aria-live": "polite", children: o ? "Copied to clipboard" : "" })
        ]
      }
    );
  }
);
I.displayName = "ClipboardText";
export {
  I as C
};
//# sourceMappingURL=clipboard-text-BFHWMjmr.js.map
