import { defineComponent as h, Text as f, isVNode as y, computed as m, createVNode as r, Fragment as k } from "vue";
import { message as p } from "@aplus-frontend/antdv";
import { IconApAdLineCopy as T } from "@aplus-frontend/icon";
import { isNull as P, isUndefined as j, isString as A, isBoolean as N } from "lodash-unified";
import "../../config-provider/index.mjs";
import { ApCopyProps as I } from "./constans.mjs";
import V from "./style/index.mjs";
import { useNamespace as w } from "../../config-provider/hooks/use-namespace.mjs";
import { useLocale as z } from "../../config-provider/hooks/use-locale.mjs";
const G = /* @__PURE__ */ h({
  name: "CopyBtn",
  props: I(),
  setup(e, {
    slots: d
  }) {
    const {
      b: x,
      e: l,
      m: a
    } = w("ap-copy"), g = V("ap-copy"), {
      t: s
    } = z(), v = (t, n, b) => {
      t.stopPropagation(), t.preventDefault(), t.stopImmediatePropagation(), navigator.clipboard.writeText(e.text || c() || "").then(() => {
        p.success(n || s("ap.apCopy.copySuccess"));
      }).catch(() => {
        p.error(b || s("ap.apCopy.copyError"));
      });
    }, S = (t) => {
      if (t.length === 1) {
        const n = t[0];
        if (n.type === f || n.type.toString() === "Symbol(Text)" || y(n) && typeof n.children == "string")
          return !0;
      }
      return !1;
    }, C = (t) => {
      if (!t.length) return "";
      const n = t[0];
      return n.type === f || n.type.toString() === "Symbol(Text)" ? String(n.children) : y(n) && typeof n.children == "string" ? n.children : "";
    }, c = () => {
      const t = d.default?.();
      return t && S(t) ? C(t) : null;
    }, u = (t) => !(P(t) || j(t) || typeof t == "string" && t === ""), o = m(() => {
      if (typeof e.textStyle == "string")
        switch (e.textStyle) {
          case "link":
            return "text-link";
          case "minor":
            return "text-minor";
          case "major":
            return "text-major";
          default:
            return "text-major";
        }
      else if (typeof e.textStyle == "object")
        return {
          ...e.textStyle
        };
      return {};
    }), i = m(() => c() || e.text || "");
    return () => r(k, null, [r("div", {
      class: [x(), g.value]
    }, [r("div", {
      class: [l("text"), typeof o.value == "string" && a(o.value)],
      style: typeof o.value != "string" && o.value,
      title: typeof o.value == "string" ? i.value : "",
      onClick: e.onClick ? () => e.onClick() : void 0
    }, [u(i.value) ? e.link && A(e.link) ? r("a", {
      href: e.link,
      target: "_blank"
    }, [i.value]) : N(e.link) ? r("span", {
      class: a("text-link")
    }, [i.value]) : i.value : "--"]), u(i.value) && !e.disableCopy ? r("div", {
      class: [l("copy-btn"), "copy-btn"],
      onClick: e.disableCopy ? void 0 : (t) => v(t, e.tipMessageSuccess, e.tipMessageError)
    }, [r(T, {
      size: e.size
    }, null)]) : r("div", {
      class: [l("copy-btn"), "copy-btn"]
    }, null)])]);
  }
});
export {
  G as default
};
