import { nextTick as x } from "vue";
function R(i) {
  if (!i) return null;
  let t = i.parentElement;
  for (; t; ) {
    if (t.classList.contains("message-feed"))
      return t;
    t = t.parentElement;
  }
  return null;
}
function w(i) {
  if (!i) return !1;
  let t = i.parentElement;
  for (; t; ) {
    for (const f of t.classList)
      if (f.includes("__right"))
        return !0;
    if (t.classList.contains("message-feed"))
      break;
    t = t.parentElement;
  }
  return !1;
}
async function P(i, t, f = 300) {
  if (!t) return {};
  const a = R(t);
  if (!a) return {};
  const d = w(t);
  await x();
  const n = t.closest(".message-reactions");
  if (!n) return {};
  const e = t.getBoundingClientRect(), s = a.getBoundingClientRect(), g = n.getBoundingClientRect(), c = (i == null ? void 0 : i.offsetWidth) || f, o = 8;
  if (d) {
    const p = s.right - e.right, h = e.left - g.left, C = e.width;
    return c <= p - o ? {
      left: `${h + C + 6}px`,
      // справа от кнопки с gap 6px
      right: "auto",
      transform: "none"
    } : {
      left: `${h - c - 6}px`,
      right: "auto",
      transform: "none"
    };
  }
  const u = e.left - g.left, l = e.width, r = e.left - s.left;
  return c <= r - o ? {
    left: `${u - c - 6}px`,
    // слева от кнопки с gap 6px
    right: "auto",
    transform: "none"
  } : {
    left: `${u + l + 6}px`,
    // справа от кнопки с gap 6px
    right: "auto",
    transform: "none"
  };
}
async function B(i, t, f = 300) {
  if (!t) return {};
  const a = R(t);
  if (!a) return {};
  const d = w(t);
  await x();
  const n = t.getBoundingClientRect(), e = a.getBoundingClientRect(), s = (i == null ? void 0 : i.offsetWidth) || f, g = (i == null ? void 0 : i.offsetHeight) || 450, c = 8, o = 6, u = window.innerHeight - n.bottom - o, l = n.top - o;
  let r;
  if (u >= g || u >= l ? r = { top: `${n.bottom + o}px` } : r = { bottom: `${window.innerHeight - n.top + o}px` }, d) {
    const h = e.right - n.right;
    return s <= h - c ? {
      position: "fixed",
      ...r,
      left: `${n.right + o}px`,
      right: "auto",
      transform: "none"
    } : {
      position: "fixed",
      ...r,
      left: `${n.left - s - o}px`,
      right: "auto",
      transform: "none"
    };
  }
  const p = n.left - e.left;
  return s <= p - c ? {
    position: "fixed",
    ...r,
    left: `${n.left - s - o}px`,
    right: "auto",
    transform: "none"
  } : {
    position: "fixed",
    ...r,
    left: `${n.right + o}px`,
    right: "auto",
    transform: "none"
  };
}
export {
  B as calculateFixedPanelPosition,
  P as calculatePanelPosition,
  R as findFeedContainer,
  w as isRightMessage
};
