import { flip as H, offset as I, size as J, hide as K, computePosition as N, shift as Q, limitShift as T } from "../../../../../@floating-ui_dom@1.7.4/node_modules/@floating-ui/dom/dist/floating-ui.dom.js";
import { autoUpdate as ae, detectOverflow as de, platform as me } from "../../../../../@floating-ui_dom@1.7.4/node_modules/@floating-ui/dom/dist/floating-ui.dom.js";
import * as r from "react";
import { useLayoutEffect as X } from "react";
import * as Y from "react-dom";
var Z = typeof document < "u", b = function() {
}, R = Z ? X : b;
function w(e, t) {
  if (e === t)
    return !0;
  if (typeof e != typeof t)
    return !1;
  if (typeof e == "function" && e.toString() === t.toString())
    return !0;
  let n, f, c;
  if (e && t && typeof e == "object") {
    if (Array.isArray(e)) {
      if (n = e.length, n !== t.length) return !1;
      for (f = n; f-- !== 0; )
        if (!w(e[f], t[f]))
          return !1;
      return !0;
    }
    if (c = Object.keys(e), n = c.length, n !== Object.keys(t).length)
      return !1;
    for (f = n; f-- !== 0; )
      if (!{}.hasOwnProperty.call(t, c[f]))
        return !1;
    for (f = n; f-- !== 0; ) {
      const p = c[f];
      if (!(p === "_owner" && e.$$typeof) && !w(e[p], t[p]))
        return !1;
    }
    return !0;
  }
  return e !== e && t !== t;
}
function L(e) {
  return typeof window > "u" ? 1 : (e.ownerDocument.defaultView || window).devicePixelRatio || 1;
}
function z(e, t) {
  const n = L(e);
  return Math.round(t * n) / n;
}
function k(e) {
  const t = r.useRef(e);
  return R(() => {
    t.current = e;
  }), t;
}
function ne(e) {
  e === void 0 && (e = {});
  const {
    placement: t = "bottom",
    strategy: n = "absolute",
    middleware: f = [],
    platform: c,
    elements: {
      reference: p,
      floating: A
    } = {},
    transform: D = !0,
    whileElementsMounted: E,
    open: x
  } = e, [s, v] = r.useState({
    x: 0,
    y: 0,
    strategy: n,
    placement: t,
    middlewareData: {},
    isPositioned: !1
  }), [M, q] = r.useState(f);
  w(M, f) || q(f);
  const [B, U] = r.useState(null), [V, W] = r.useState(null), C = r.useCallback((o) => {
    o !== a.current && (a.current = o, U(o));
  }, []), O = r.useCallback((o) => {
    o !== d.current && (d.current = o, W(o));
  }, []), i = p || B, u = A || V, a = r.useRef(null), d = r.useRef(null), y = r.useRef(s), G = E != null, S = k(E), P = k(c), _ = k(x), g = r.useCallback(() => {
    if (!a.current || !d.current)
      return;
    const o = {
      placement: t,
      strategy: n,
      middleware: M
    };
    P.current && (o.platform = P.current), N(a.current, d.current, o).then((h) => {
      const m = {
        ...h,
        // The floating element's position may be recomputed while it's closed
        // but still mounted (such as when transitioning out). To ensure
        // `isPositioned` will be `false` initially on the next open, avoid
        // setting it to `true` when `open === false` (must be specified).
        isPositioned: _.current !== !1
      };
      $.current && !w(y.current, m) && (y.current = m, Y.flushSync(() => {
        v(m);
      }));
    });
  }, [M, t, n, P, _]);
  R(() => {
    x === !1 && y.current.isPositioned && (y.current.isPositioned = !1, v((o) => ({
      ...o,
      isPositioned: !1
    })));
  }, [x]);
  const $ = r.useRef(!1);
  R(() => ($.current = !0, () => {
    $.current = !1;
  }), []), R(() => {
    if (i && (a.current = i), u && (d.current = u), i && u) {
      if (S.current)
        return S.current(i, u, g);
      g();
    }
  }, [i, u, g, S, G]);
  const F = r.useMemo(() => ({
    reference: a,
    floating: d,
    setReference: C,
    setFloating: O
  }), [C, O]), l = r.useMemo(() => ({
    reference: i,
    floating: u
  }), [i, u]), j = r.useMemo(() => {
    const o = {
      position: n,
      left: 0,
      top: 0
    };
    if (!l.floating)
      return o;
    const h = z(l.floating, s.x), m = z(l.floating, s.y);
    return D ? {
      ...o,
      transform: "translate(" + h + "px, " + m + "px)",
      ...L(l.floating) >= 1.5 && {
        willChange: "transform"
      }
    } : {
      position: n,
      left: h,
      top: m
    };
  }, [n, D, l.floating, s.x, s.y]);
  return r.useMemo(() => ({
    ...s,
    update: g,
    refs: F,
    elements: l,
    floatingStyles: j
  }), [s, g, F, l, j]);
}
const re = (e, t) => ({
  ...I(e),
  options: [e, t]
}), oe = (e, t) => ({
  ...Q(e),
  options: [e, t]
}), fe = (e, t) => ({
  ...T(e),
  options: [e, t]
}), se = (e, t) => ({
  ...H(e),
  options: [e, t]
}), ie = (e, t) => ({
  ...J(e),
  options: [e, t]
}), ue = (e, t) => ({
  ...K(e),
  options: [e, t]
});
export {
  ae as autoUpdate,
  N as computePosition,
  de as detectOverflow,
  se as flip,
  ue as hide,
  fe as limitShift,
  re as offset,
  me as platform,
  oe as shift,
  ie as size,
  ne as useFloating
};
