const y = (e) => {
  e._copyEventType && e._onCopy && e.removeEventListener(e._copyEventType, e._onCopy), e._copyEventType = void 0;
}, a = (e) => {
  const t = e.tagName;
  if (t === "INPUT" || t === "TEXTAREA") {
    e.focus(), e.select();
    return;
  }
  const n = window.getSelection();
  if (n)
    try {
      const o = document.createRange();
      o.selectNodeContents(e), n.removeAllRanges(), n.addRange(o);
    } catch {
    }
}, s = (e, t) => {
  e._copyBinding = t, e._onCopy || (e._onCopy = () => {
    const o = e._copyBinding;
    o != null && o.value && (o.modifiers.dblclick && a(e), window.$copy(o.value, o.arg));
  });
  const n = t.modifiers.dblclick ? "dblclick" : "click";
  e._copyEventType !== n && (y(e), e.addEventListener(n, e._onCopy), e._copyEventType = n);
}, m = (e) => {
  e.directive("copy", {
    mounted(t, n) {
      s(t, n);
    },
    updated(t, n) {
      s(t, n);
    },
    unmounted(t) {
      y(t), t._onCopy = void 0, t._copyBinding = void 0;
    }
  }), e.directive("focus", {
    mounted(t, n, o) {
      let { value: c = 0, arg: p = "time" } = n;
      if (c === null)
        return;
      let r = 100, i = 0;
      p !== "time" ? i = c : r = Number(c);
      const u = setTimeout(() => {
        let d = t.querySelectorAll("input, textarea");
        d[i].focus(), d[i].select(), clearTimeout(u);
      }, r);
    }
  });
};
export {
  m as d
};
