import b from "clipboard";
import { C as s } from "../../Shared/base-PQGakkrl.js";
const f = () => {
  const n = (c) => {
    if (c) {
      c().focus();
      const e = window.getSelection();
      e && e.removeAllRanges();
    }
  }, o = (c, e) => {
    let r;
    if (s.isString(c) ? r = document.querySelector(c.toString()) : r = c, !(r && r._clipboardObj)) {
      const t = {
        successCallback: e.successCallback,
        errorCallback: e.errorCallback
      };
      switch (s.getTypeof(e.action)) {
        case "function":
          t.action = e.action;
          break;
        case "string":
          t.action = () => e.action;
          break;
      }
      switch (s.getTypeof(e.text)) {
        case "function":
          t.text = e.text;
          break;
        case "string":
          t.text = () => e.text;
          break;
      }
      e.target && (s.isFunction(e.target) ? t.target = e.target : t.target = () => s.isString(e.target) ? document.querySelector(e.target) : e.target instanceof Element ? e.target : null);
      const a = new b(c, t);
      a.on("success", (l) => {
        t.successCallback(a, l), n(t.target);
      }), a.on("error", (l) => {
        t.errorCallback(a, l), n(t.target);
      }), r._clipboardObj = a;
    }
  };
  return {
    copy: (c) => {
      const e = document.createElement("button");
      e.setAttribute("type", "button");
      const r = {
        action: "copy",
        text: c.text,
        target: c.target
      };
      r.successCallback = (t) => {
        c.successCallback && c.successCallback(), t.destroy();
      }, r.errorCallback = (t) => {
        c.errorCallback && c.errorCallback(), t.destroy();
      }, o(e, r), document.body.appendChild(e), e.click(), document.body.removeChild(e);
    }
  };
};
export {
  f as default
};
//# sourceMappingURL=Clipboard.js.map
