import { jsx as e } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import B from "classnames";
import { useState as C, useCallback as u, useMemo as b } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { Tooltip as _ } from "../Tooltip/Tooltip.js";
import { ButtonVariant as I } from "../Button/types.js";
/* empty css              */
import S from "../../../core/Context/preact/useCoreContext.js";
import T from "../Button/Button.js";
import { Icon as A } from "../Icon/Icon.js";
const o = "adyen-pe-copy-text", a = {
  base: o,
  container: o + "__container",
  icon: o + "__icon",
  information: o + "__information",
  label: o + "__label",
  text: o + "__text",
  stronger: o + "--stronger"
}, V = ({
  copyButtonAriaLabelKey: c,
  isUnderlineVisible: h,
  textToCopy: t,
  visibleText: r,
  onCopyText: s,
  showCopyTextTooltip: v = !0,
  type: n = "Trimmed",
  stronger: l,
  ...g
}) => {
  const { i18n: i } = S(), [m, d] = C(!1), p = u(() => d(!1), []), N = b(() => i.get(c ?? "common.actions.copy.labels.default"), [i, c]), x = u(async () => {
    if (t)
      try {
        await navigator.clipboard.writeText(t), d(!0), s && s();
      } catch (y) {
        console.error(y);
      }
  }, [t, s]), f = b(
    () => /* @__PURE__ */ e(
      "span",
      {
        className: B({
          [a.label]: n !== "Default",
          [a.information]: n === "Trimmed",
          [a.text]: n === "Text",
          [a.stronger]: l
        }),
        children: r || t
      }
    ),
    [n, l, r, t]
  );
  return /* @__PURE__ */ e("span", { className: a.container, ...g, children: [
    v ? /* @__PURE__ */ e(_, { content: t, isUnderlineVisible: h, children: f }) : f,
    /* @__PURE__ */ e(_, { content: i.get(m ? "common.actions.copy.labels.done" : "common.actions.copy.labels.default"), children: /* @__PURE__ */ e(
      T,
      {
        variant: I.TERTIARY,
        className: a.base,
        onClick: x,
        onBlur: p,
        onMouseLeaveCapture: p,
        "aria-label": N,
        "data-testid": "copyText",
        children: /* @__PURE__ */ e("div", { className: a.icon, children: /* @__PURE__ */ e(A, { name: "copy", "data-testid": "copy-icon" }) })
      }
    ) }),
    /* @__PURE__ */ e("div", { className: "adyen-pe-visually-hidden", "aria-atomic": "true", "aria-live": "polite", children: m && i.get("common.actions.copy.labels.done") })
  ] });
};
export {
  V as default
};
