import { ref as n, watch as p, nextTick as f } from "vue";
import { calculatePanelPosition as z, calculateFixedPanelPosition as M } from "./usePositioning.js";
function j(y, i) {
  const t = n(!1), l = n(!1), e = n(null), s = n(null), h = n({}), v = n({});
  let r = !1, P = !1, c = !1;
  p(t, async (u) => {
    if (u) {
      const a = y.value.length * 40 + 40, k = await z(s.value, i.value, a);
      h.value = k;
    }
  }), p(l, async (u) => {
    if (u) {
      await f();
      let a = 0;
      const k = 20;
      for (; !e.value && a < k; )
        await new Promise((o) => setTimeout(o, 10)), a++;
      await f();
      const w = 350;
      let m = await M(e.value, i.value, w);
      if (v.value = m, e.value) {
        let o = 0;
        const S = 10;
        for (; e.value.offsetWidth === 0 && o < S; )
          await new Promise((q) => setTimeout(q, 10)), o++;
        await f(), m = await M(e.value, i.value, e.value.offsetWidth || w), v.value = m;
      }
    }
  });
  function O() {
    t.value = !0, l.value = !1;
  }
  function Q() {
    t.value = !1;
  }
  async function x() {
    t.value = !1, await f(), l.value = !0;
  }
  function T() {
    l.value = !1;
  }
  function F() {
    P = !0;
  }
  function W() {
    P = !1, setTimeout(() => {
      !c && !P && (t.value = !1);
    }, 150);
  }
  function d() {
    r = !0;
  }
  function g() {
    r = !1, setTimeout(() => {
      !c && !r && (l.value = !1);
    }, 150);
  }
  function A() {
    c = !0;
  }
  function E() {
    c = !1;
  }
  function L(u) {
    const a = u.target;
    t.value && s.value && i.value && !s.value.contains(a) && !i.value.contains(a) && (t.value = !1), l.value && e.value && i.value && !e.value.contains(a) && !i.value.contains(a) && (l.value = !1);
  }
  return {
    isQuickReactionsOpen: t,
    isFullPickerOpen: l,
    pickerRef: e,
    quickReactionsRef: s,
    quickPanelStyle: h,
    pickerStyle: v,
    openQuickPanel: O,
    closeQuickPanel: Q,
    openFullPicker: x,
    closeFullPicker: T,
    handleQuickPanelMouseEnter: F,
    handleQuickPanelMouseLeave: W,
    handlePickerMouseEnter: d,
    handlePickerMouseLeave: g,
    handleButtonMouseEnter: A,
    handleButtonMouseLeave: E,
    handleClickOutside: L
  };
}
export {
  j as useReactionsPanel
};
