import { defineComponent, ref, resolveComponent, createElementBlock, openBlock, normalizeClass, unref, createVNode, withCtx, createElementVNode, renderSlot, createTextVNode, toDisplayString, createBlock, createCommentVNode } from 'vue';
import '../../../utils/index.mjs';
import { copyTextProps } from './copy-text.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';

"use strict";
const _hoisted_1 = { key: 1 };
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlCopyText" },
  __name: "copy-text",
  props: copyTextProps,
  setup(__props) {
    const bem = createNamespace("copy-text");
    const props = __props;
    const loading = ref(false);
    const handleCopyText = (title) => {
      const textarea = document.createElement("textarea");
      textarea.value = title;
      document.body.appendChild(textarea);
      textarea.select();
      document.execCommand("Copy");
      document.body.removeChild(textarea);
    };
    const handleCopy = (value) => {
      try {
        loading.value = true;
        handleCopyText(value);
        setTimeout(() => {
          loading.value = false;
        }, 3e3);
      } catch (error) {
        loading.value = false;
      }
    };
    return (_ctx, _cache) => {
      const _component_ll_icon = resolveComponent("ll-icon");
      const _component_ll_tooltip = resolveComponent("ll-tooltip");
      return openBlock(), createElementBlock(
        "div",
        {
          class: normalizeClass(unref(bem).b())
        },
        [
          createVNode(_component_ll_tooltip, { placement: "top" }, {
            title: withCtx(() => [
              loading.value ? (openBlock(), createElementBlock(
                "div",
                {
                  key: 0,
                  class: normalizeClass([unref(bem).b("tooltip-title-succeed")])
                },
                [
                  _ctx.iconName ? (openBlock(), createBlock(_component_ll_icon, {
                    key: 0,
                    "icon-name": _ctx.iconName || "icon-succeed",
                    size: 14,
                    color: _ctx.iconColor || "#fff"
                  }, null, 8, ["icon-name", "color"])) : createCommentVNode("v-if", true),
                  createElementVNode(
                    "span",
                    null,
                    toDisplayString(props.copySucceed),
                    1
                    /* TEXT */
                  )
                ],
                2
                /* CLASS */
              )) : (openBlock(), createElementBlock(
                "div",
                _hoisted_1,
                toDisplayString(props.clickText),
                1
                /* TEXT */
              ))
            ]),
            default: withCtx(() => [
              createElementVNode(
                "div",
                {
                  class: normalizeClass([unref(bem).e("content")]),
                  onClick: _cache[0] || (_cache[0] = ($event) => handleCopy(String(_ctx.value)))
                },
                [
                  renderSlot(_ctx.$slots, "value", {}, () => [
                    createTextVNode(
                      toDisplayString(_ctx.value),
                      1
                      /* TEXT */
                    )
                  ])
                ],
                2
                /* CLASS */
              )
            ]),
            _: 3
            /* FORWARDED */
          })
        ],
        2
        /* CLASS */
      );
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=copy-text.vue2.mjs.map
