import { getEl as r } from "@das-fed/utils/directive/utils";
const f = {
  mounted: async (i, _) => {
    const e = _.value, t = await r(i, e);
    function c(n) {
      let l = !0;
      if (Array.isArray(t))
        for (let o of t)
          o.__click_outside__ = c, o.contains(n.target) && (l = !1);
      else
        t.contains(n.target) && (l = !1), t.__click_outside__ = c;
      l && e != null && e.fn && typeof (e == null ? void 0 : e.fn) == "function" && (e == null || e.fn(n));
    }
    document.addEventListener("click", c);
  },
  beforeUnmount: async (i, _) => {
    const e = _.value, t = await r(i, e);
    if (Array.isArray(t))
      for (let c of t)
        document.removeEventListener("click", c.__click_outside__), delete c.__click_outside__;
    else
      document.removeEventListener("click", t.__click_outside__), delete t.__click_outside__;
  }
};
export {
  f as vClickOutside
};
