import { defineComponent as w, computed as r, watch as g, useCssModule as T, ref as B, openBlock as s, createElementBlock as p, normalizeClass as l, unref as d, Fragment as M, renderSlot as E, createVNode as u, withCtx as c, createBlock as a, createTextVNode as y, toDisplayString as m } from "vue";
import I from "@leaflink/snitch";
import { UI_TIMEOUT as z } from "./constants.js";
import { t as f } from "./locale.js";
import _ from "./Button.js";
import x from "./Icon.js";
import N from "./IconLabel.js";
import { _ as U } from "./Tooltip.vue_vue_type_script_setup_true_lang-EZU7uCEV.js";
import { _ as $ } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const L = /* @__PURE__ */ w({
  __name: "Copy",
  props: {
    text: { default: void 0 },
    value: {},
    visible: { type: Boolean, default: !1 },
    mode: { default: "unset" }
  },
  emits: ["copy"],
  setup(h, { emit: v }) {
    const t = h, o = r(() => t.mode !== "unset" ? t.mode : t.text ? "text" : "icon");
    g(
      [o, () => t.text, () => t.visible],
      () => {
        if (!t.text && ["text", "icon-button"].includes(o.value))
          throw new Error("Copy: text prop is required when mode is text or icon-button");
        if (t.text && o.value === "icon")
          throw new Error("Copy: text prop is not allowed when mode is icon");
        o.value === "icon-button" && t.visible === !1 && I.warn("Copy: visible prop is ignored when mode is icon-button");
      },
      { immediate: !0 }
    );
    const b = v, n = T(), e = B(!1), C = r(() => e.value ? f("ll.copy.copied") : t.text ? null : f("ll.copy.copyToClipboard"));
    function i() {
      navigator.clipboard.writeText(t.value), e.value = !0, setTimeout(() => {
        e.value = !1;
      }, z), b("copy");
    }
    return (k, D) => (s(), p("div", {
      class: l(["stash-copy flex items-center", { [d(n).hidden]: !t.visible }]),
      "data-test": "stash-copy"
    }, [
      o.value !== "icon-button" ? (s(), p(M, { key: 0 }, [
        E(k.$slots, "default"),
        u(U, {
          side: "top",
          text: C.value,
          "is-disabled": !!t.text,
          class: l(["stash-copy__copy-zone ml-3 cursor-pointer", d(n).copy]),
          "data-test": "stash-copy|copy-zone"
        }, {
          default: c(() => [
            e.value ? (s(), a(x, {
              key: 0,
              class: "stash-copy__success-icon text-green-500",
              name: "circle-check",
              "data-test": "stash-copy|success-icon"
            })) : o.value === "text" ? (s(), a(_, {
              key: 1,
              class: "stash-copy__copy-text",
              inline: "",
              "data-test": "stash-copy|copy-target",
              onClick: i
            }, {
              default: c(() => [
                y(m(t.text), 1)
              ]),
              _: 1
            })) : (s(), a(x, {
              key: 2,
              class: "stash-copy__copy-icon",
              name: "copy",
              title: "Copy to clipboard",
              "data-test": "stash-copy|copy-target",
              onClick: i
            }))
          ]),
          _: 1
        }, 8, ["text", "is-disabled", "class"])
      ], 64)) : (s(), a(_, {
        key: 1,
        "icon-label": "",
        "data-test": e.value ? "stash-copy|success-icon-button" : "stash-copy|copy-target",
        title: t.text,
        class: l(e.value ? "text-green-500" : ""),
        onClick: i
      }, {
        default: c(() => [
          u(N, {
            icon: e.value ? "circle-check" : "copy",
            title: t.text,
            stacked: ""
          }, {
            default: c(() => [
              y(m(t.text), 1)
            ]),
            _: 1
          }, 8, ["icon", "title"])
        ]),
        _: 1
      }, 8, ["data-test", "title", "class"]))
    ], 2));
  }
}), S = "_hidden_LXtNd", V = "_copy_ayU6X", X = {
  hidden: S,
  copy: V
}, q = {
  $style: X
}, Q = /* @__PURE__ */ $(L, [["__cssModules", q]]);
export {
  Q as default
};
//# sourceMappingURL=Copy.js.map
