'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../utils/index.js');
var copyText = require('./copy-text.js');
var createNamespace = require('../../../utils/create-namespace.js');

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

exports.default = _sfc_main;
//# sourceMappingURL=copy-text.vue2.js.map
