import { offset as H, autoPlacement as I, computePosition as J } from "../../../../../@floating-ui_dom@1.6.13/node_modules/@floating-ui/dom/dist/floating-ui.dom.js";
import { autoUpdate as ne, platform as re } from "../../../../../@floating-ui_dom@1.6.13/node_modules/@floating-ui/dom/dist/floating-ui.dom.js";
import * as r from "react";
import { useLayoutEffect as K, useEffect as N } from "react";
import * as Q from "react-dom";
var w = typeof document < "u" ? K : N;
function h(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 (!h(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) && !h(e[p], t[p]))
        return !1;
    }
    return !0;
  }
  return e !== e && t !== t;
}
function A(e) {
  return typeof window > "u" ? 1 : (e.ownerDocument.defaultView || window).devicePixelRatio || 1;
}
function v(e, t) {
  const n = A(e);
  return Math.round(t * n) / n;
}
function k(e) {
  const t = r.useRef(e);
  return w(() => {
    t.current = e;
  }), t;
}
function Y(e) {
  e === void 0 && (e = {});
  const {
    placement: t = "bottom",
    strategy: n = "absolute",
    middleware: f = [],
    platform: c,
    elements: {
      reference: p,
      floating: q
    } = {},
    transform: D = !0,
    whileElementsMounted: _,
    open: P
  } = e, [s, C] = r.useState({
    x: 0,
    y: 0,
    strategy: n,
    placement: t,
    middlewareData: {},
    isPositioned: !1
  }), [x, B] = r.useState(f);
  h(x, f) || B(f);
  const [U, V] = r.useState(null), [W, z] = r.useState(null), F = r.useCallback((o) => {
    o !== a.current && (a.current = o, V(o));
  }, []), O = r.useCallback((o) => {
    o !== m.current && (m.current = o, z(o));
  }, []), u = p || U, i = q || W, a = r.useRef(null), m = r.useRef(null), y = r.useRef(s), G = _ != null, M = k(_), S = k(c), $ = k(P), g = r.useCallback(() => {
    if (!a.current || !m.current)
      return;
    const o = {
      placement: t,
      strategy: n,
      middleware: x
    };
    S.current && (o.platform = S.current), J(a.current, m.current, o).then((R) => {
      const d = {
        ...R,
        // 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
      };
      E.current && !h(y.current, d) && (y.current = d, Q.flushSync(() => {
        C(d);
      }));
    });
  }, [x, t, n, S, $]);
  w(() => {
    P === !1 && y.current.isPositioned && (y.current.isPositioned = !1, C((o) => ({
      ...o,
      isPositioned: !1
    })));
  }, [P]);
  const E = r.useRef(!1);
  w(() => (E.current = !0, () => {
    E.current = !1;
  }), []), w(() => {
    if (u && (a.current = u), i && (m.current = i), u && i) {
      if (M.current)
        return M.current(u, i, g);
      g();
    }
  }, [u, i, g, M, G]);
  const j = r.useMemo(() => ({
    reference: a,
    floating: m,
    setReference: F,
    setFloating: O
  }), [F, O]), l = r.useMemo(() => ({
    reference: u,
    floating: i
  }), [u, i]), L = r.useMemo(() => {
    const o = {
      position: n,
      left: 0,
      top: 0
    };
    if (!l.floating)
      return o;
    const R = v(l.floating, s.x), d = v(l.floating, s.y);
    return D ? {
      ...o,
      transform: "translate(" + R + "px, " + d + "px)",
      ...A(l.floating) >= 1.5 && {
        willChange: "transform"
      }
    } : {
      position: n,
      left: R,
      top: d
    };
  }, [n, D, l.floating, s.x, s.y]);
  return r.useMemo(() => ({
    ...s,
    update: g,
    refs: j,
    elements: l,
    floatingStyles: L
  }), [s, g, j, l, L]);
}
const Z = (e, t) => ({
  ...H(e),
  options: [e, t]
}), b = (e, t) => ({
  ...I(e),
  options: [e, t]
});
export {
  b as autoPlacement,
  ne as autoUpdate,
  J as computePosition,
  Z as offset,
  re as platform,
  Y as useFloating
};
//# sourceMappingURL=floating-ui.react-dom.js.map
