import * as a from "react";
import { createElement as x } from "react";
import { i as te } from "./floating-ui.utils.dom-uiDUZc_y.mjs";
import * as R from "react-dom";
const v = {};
function g(e, t) {
  const n = a.useRef(v);
  return n.current === v && (n.current = e(t)), n;
}
const N = a[`useInsertionEffect${Math.random().toFixed(1)}`.slice(0, -3)], ne = (
  // React 17 doesn't have useInsertionEffect.
  N && // Preact replaces useInsertionEffect with useLayoutEffect and fires too late.
  N !== a.useLayoutEffect ? N : (e) => e()
);
function k(e) {
  const t = g(re).current;
  return t.next = e, ne(t.effect), t.trampoline;
}
function re() {
  const e = {
    next: void 0,
    callback: se,
    trampoline: (...t) => e.callback?.(...t),
    effect: () => {
      e.callback = e.next;
    }
  };
  return e;
}
function se() {
  if (process.env.NODE_ENV !== "production")
    throw new Error("Base UI: Cannot call an event handler while rendering.");
}
const oe = () => {
}, V = typeof document < "u" ? a.useLayoutEffect : oe;
function K(e, ...t) {
  const n = new URL(`https://base-ui.com/production-error/${e}`);
  return t.forEach((s) => n.searchParams.append("args[]", s)), `Base UI error #${e}; visit ${n} for the full message.`;
}
function B(e, t, n, s) {
  const r = g(L).current;
  return ie(r, e, t, n, s) && q(r, [e, t, n, s]), r.callback;
}
function ce(e) {
  const t = g(L).current;
  return ae(t, e) && q(t, e), t.callback;
}
function L() {
  return {
    callback: null,
    cleanup: null,
    refs: []
  };
}
function ie(e, t, n, s, r) {
  return e.refs[0] !== t || e.refs[1] !== n || e.refs[2] !== s || e.refs[3] !== r;
}
function ae(e, t) {
  return e.refs.length !== t.length || e.refs.some((n, s) => n !== t[s]);
}
function q(e, t) {
  if (e.refs = t, t.every((n) => n == null)) {
    e.callback = null;
    return;
  }
  e.callback = (n) => {
    if (e.cleanup && (e.cleanup(), e.cleanup = null), n != null) {
      const s = Array(t.length).fill(null);
      for (let r = 0; r < t.length; r += 1) {
        const o = t[r];
        if (o != null)
          switch (typeof o) {
            case "function": {
              const c = o(n);
              typeof c == "function" && (s[r] = c);
              break;
            }
            case "object": {
              o.current = n;
              break;
            }
          }
      }
      e.cleanup = () => {
        for (let r = 0; r < t.length; r += 1) {
          const o = t[r];
          if (o != null)
            switch (typeof o) {
              case "function": {
                const c = s[r];
                typeof c == "function" ? c() : o(null);
                break;
              }
              case "object": {
                o.current = null;
                break;
              }
            }
        }
      };
    }
  };
}
const ue = parseInt(a.version, 10);
function le(e) {
  return ue >= e;
}
function U(e) {
  if (!/* @__PURE__ */ a.isValidElement(e))
    return null;
  const t = e, n = t.props;
  return (le(19) ? n?.ref : t.ref) ?? null;
}
function A(e, t) {
  if (e && !t)
    return e;
  if (!e && t)
    return t;
  if (e || t)
    return {
      ...e,
      ...t
    };
}
function fe(e, t) {
  const n = {};
  for (const s in e) {
    const r = e[s];
    if (t?.hasOwnProperty(s)) {
      const o = t[s](r);
      o != null && Object.assign(n, o);
      continue;
    }
    r === !0 ? n[`data-${s.toLowerCase()}`] = "" : r && (n[`data-${s.toLowerCase()}`] = r.toString());
  }
  return n;
}
function de(e, t) {
  return typeof e == "function" ? e(t) : e;
}
function pe(e, t) {
  return typeof e == "function" ? e(t) : e;
}
const b = {};
function $(e, t, n, s, r) {
  let o = {
    ...w(e, b)
  };
  return t && (o = C(o, t)), n && (o = C(o, n)), s && (o = C(o, s)), o;
}
function he(e) {
  if (e.length === 0)
    return b;
  if (e.length === 1)
    return w(e[0], b);
  let t = {
    ...w(e[0], b)
  };
  for (let n = 1; n < e.length; n += 1)
    t = C(t, e[n]);
  return t;
}
function C(e, t) {
  return j(t) ? t(e) : me(e, t);
}
function me(e, t) {
  if (!t)
    return e;
  for (const n in t) {
    const s = t[n];
    switch (n) {
      case "style": {
        e[n] = A(e.style, s);
        break;
      }
      case "className": {
        e[n] = W(e.className, s);
        break;
      }
      default:
        be(n, s) ? e[n] = ge(e[n], s) : e[n] = s;
    }
  }
  return e;
}
function be(e, t) {
  const n = e.charCodeAt(0), s = e.charCodeAt(1), r = e.charCodeAt(2);
  return n === 111 && s === 110 && r >= 65 && r <= 90 && (typeof t == "function" || typeof t > "u");
}
function j(e) {
  return typeof e == "function";
}
function w(e, t) {
  return j(e) ? e(t) : e ?? b;
}
function ge(e, t) {
  return t ? e ? (n) => {
    if (Ee(n)) {
      const r = n;
      D(r);
      const o = t(r);
      return r.baseUIHandlerPrevented || e?.(r), o;
    }
    const s = t(n);
    return e?.(n), s;
  } : t : e;
}
function D(e) {
  return e.preventBaseUIHandler = () => {
    e.baseUIHandlerPrevented = !0;
  }, e;
}
function W(e, t) {
  return t ? e ? t + " " + e : t : e;
}
function Ee(e) {
  return e != null && typeof e == "object" && "nativeEvent" in e;
}
function Ke() {
}
const m = Object.freeze({});
function Le(e, t, n = {}) {
  const s = t.render, r = ye(t, n);
  if (n.enabled === !1)
    return null;
  const o = n.state ?? m;
  return Ie(e, s, r, o);
}
function ye(e, t = {}) {
  const {
    className: n,
    style: s,
    render: r
  } = e, {
    state: o = m,
    ref: c,
    props: u,
    stateAttributesMapping: p,
    enabled: l = !0
  } = t, h = l ? de(n, o) : void 0, E = l ? pe(s, o) : void 0, f = l ? fe(o, p) : m, d = l ? A(f, Array.isArray(u) ? he(u) : u) ?? m : m;
  return typeof document < "u" && (l ? Array.isArray(c) ? d.ref = ce([d.ref, U(r), ...c]) : d.ref = B(d.ref, U(r), c) : B(null, null)), l ? (h !== void 0 && (d.className = W(d.className, h)), E !== void 0 && (d.style = A(d.style, E)), d) : m;
}
function Ie(e, t, n, s) {
  if (t) {
    if (typeof t == "function")
      return t(n, s);
    const r = $(n, t.props);
    return r.ref = n.ref, /* @__PURE__ */ a.cloneElement(t, r);
  }
  if (e && typeof e == "string")
    return Ce(e, n);
  throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: Render element or function are not defined." : K(8));
}
function Ce(e, t) {
  return e === "button" ? /* @__PURE__ */ x("button", {
    type: "button",
    ...t,
    key: t.key
  }) : e === "img" ? /* @__PURE__ */ x("img", {
    alt: "",
    ...t,
    key: t.key
  }) : /* @__PURE__ */ a.createElement(e, t);
}
const qe = "none", $e = "trigger-press", je = "trigger-hover", We = "outside-press", Ge = "close-press", He = "focus-out", Ye = "escape-key", ze = "imperative-action";
function Je(e, t, n, s) {
  let r = !1, o = !1;
  const c = m;
  return {
    reason: e,
    event: t ?? new Event("base-ui"),
    cancel() {
      r = !0;
    },
    allowPropagation() {
      o = !0;
    },
    get isCanceled() {
      return r;
    },
    get isPropagationAllowed() {
      return o;
    },
    trigger: n,
    ...c
  };
}
const ke = {
  ...a
};
let M = 0;
function Ne(e, t = "mui") {
  const [n, s] = a.useState(e), r = e || n;
  return a.useEffect(() => {
    n == null && (M += 1, s(`${t}-${M}`));
  }, [n, t]), r;
}
const T = ke.useId;
function Ze(e, t) {
  if (T !== void 0) {
    const n = T();
    return e ?? (t ? `${t}-${n}` : n);
  }
  return Ne(e, t);
}
const Ae = [];
function we(e) {
  a.useEffect(e, Ae);
}
const y = null;
let _ = globalThis.requestAnimationFrame;
class De {
  /* This implementation uses an array as a backing data-structure for frame callbacks.
   * It allows `O(1)` callback cancelling by inserting a `null` in the array, though it
   * never calls the native `cancelAnimationFrame` if there are no frames left. This can
   * be much more efficient if there is a call pattern that alterns as
   * "request-cancel-request-cancel-…".
   * But in the case of "request-request-…-cancel-cancel-…", it leaves the final animation
   * frame to run anyway. We turn that frame into a `O(1)` no-op via `callbacksCount`. */
  callbacks = [];
  callbacksCount = 0;
  nextId = 1;
  startId = 1;
  isScheduled = !1;
  tick = (t) => {
    this.isScheduled = !1;
    const n = this.callbacks, s = this.callbacksCount;
    if (this.callbacks = [], this.callbacksCount = 0, this.startId = this.nextId, s > 0)
      for (let r = 0; r < n.length; r += 1)
        n[r]?.(t);
  };
  request(t) {
    const n = this.nextId;
    this.nextId += 1, this.callbacks.push(t), this.callbacksCount += 1;
    const s = process.env.NODE_ENV === "test" && _ !== requestAnimationFrame && (_ = requestAnimationFrame, !0);
    return (!this.isScheduled || s) && (requestAnimationFrame(this.tick), this.isScheduled = !0), n;
  }
  cancel(t) {
    const n = t - this.startId;
    n < 0 || n >= this.callbacks.length || (this.callbacks[n] = null, this.callbacksCount -= 1);
  }
}
const I = new De();
class O {
  static create() {
    return new O();
  }
  static request(t) {
    return I.request(t);
  }
  static cancel(t) {
    return I.cancel(t);
  }
  currentId = y;
  /**
   * Executes `fn` after `delay`, clearing any previously scheduled call.
   */
  request(t) {
    this.cancel(), this.currentId = I.request(() => {
      this.currentId = y, t();
    });
  }
  cancel = () => {
    this.currentId !== y && (I.cancel(this.currentId), this.currentId = y);
  };
  disposeEffect = () => this.cancel;
}
function Pe() {
  const e = g(O.create).current;
  return we(e.disposeEffect), e;
}
function Oe(e) {
  return e == null ? e : "current" in e ? e.current : e;
}
function Se(e, t = !1, n = !0) {
  const s = Pe();
  return k((r, o = null) => {
    s.cancel();
    const c = Oe(e);
    c != null && (typeof c.getAnimations != "function" || globalThis.BASE_UI_ANIMATIONS_DISABLED ? r() : s.request(() => {
      function u() {
        c && Promise.all(c.getAnimations().map((p) => p.finished)).then(() => {
          o != null && o.aborted || R.flushSync(r);
        }).catch(() => {
          if (n) {
            if (o != null && o.aborted)
              return;
            R.flushSync(r);
          } else c.getAnimations().length > 0 && c.getAnimations().some((p) => p.pending || p.playState !== "finished") && u();
        });
      }
      t ? s.request(u) : u();
    }));
  });
}
let G = /* @__PURE__ */ (function(e) {
  return e.startingStyle = "data-starting-style", e.endingStyle = "data-ending-style", e;
})({});
const xe = {
  [G.startingStyle]: ""
}, Re = {
  [G.endingStyle]: ""
}, Qe = {
  transitionStatus(e) {
    return e === "starting" ? xe : e === "ending" ? Re : null;
  }
};
let P;
process.env.NODE_ENV !== "production" && (P = /* @__PURE__ */ new Set());
function F(...e) {
  if (process.env.NODE_ENV !== "production") {
    const t = e.join(" ");
    P.has(t) || (P.add(t), console.error(`Base UI: ${t}`));
  }
}
const H = /* @__PURE__ */ a.createContext(void 0);
process.env.NODE_ENV !== "production" && (H.displayName = "CompositeRootContext");
function ve(e = !1) {
  const t = a.useContext(H);
  if (t === void 0 && !e)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: CompositeRootContext is missing. Composite parts must be placed within <Composite.Root>." : K(16));
  return t;
}
function Be(e) {
  const {
    focusableWhenDisabled: t,
    disabled: n,
    composite: s = !1,
    tabIndex: r = 0,
    isNativeButton: o
  } = e, c = s && t !== !1, u = s && t === !1;
  return {
    props: a.useMemo(() => {
      const l = {
        // allow Tabbing away from focusableWhenDisabled elements
        onKeyDown(h) {
          n && t && h.key !== "Tab" && h.preventDefault();
        }
      };
      return s || (l.tabIndex = r, !o && n && (l.tabIndex = t ? r : -1)), (o && (t || c) || !o && n) && (l["aria-disabled"] = n), o && (!t || u) && (l.disabled = n), l;
    }, [s, n, t, c, u, o, r])
  };
}
function Xe(e = {}) {
  const {
    disabled: t = !1,
    focusableWhenDisabled: n,
    tabIndex: s = 0,
    native: r = !0
  } = e, o = a.useRef(null), c = ve(!0) !== void 0, u = k(() => {
    const f = o.current;
    return !!(f?.tagName === "A" && f?.href);
  }), {
    props: p
  } = Be({
    focusableWhenDisabled: n,
    disabled: t,
    composite: c,
    tabIndex: s,
    isNativeButton: r
  });
  process.env.NODE_ENV !== "production" && a.useEffect(() => {
    if (!o.current)
      return;
    const f = o.current.tagName === "BUTTON";
    r ? f || F("A component that acts as a button was not rendered as a native <button>, which does not match the default. Ensure that the element passed to the `render` prop of the component is a real <button>, or set the `nativeButton` prop on the component to `false`.") : f && F("A component that acts as a button was rendered as a native <button>, which does not match the default. Ensure that the element passed to the `render` prop of the component is not a real <button>, or set the `nativeButton` prop on the component to `true`.");
  }, [r]);
  const l = a.useCallback(() => {
    const f = o.current;
    Ue(f) && c && t && p.disabled === void 0 && f.disabled && (f.disabled = !1);
  }, [t, p.disabled, c]);
  V(l, [l]);
  const h = a.useCallback((f = {}) => {
    const {
      onClick: d,
      onMouseDown: Y,
      onKeyUp: z,
      onKeyDown: J,
      onPointerDown: Z,
      ...Q
    } = f;
    return $({
      type: r ? "button" : void 0,
      onClick(i) {
        if (t) {
          i.preventDefault();
          return;
        }
        d?.(i);
      },
      onMouseDown(i) {
        t || Y?.(i);
      },
      onKeyDown(i) {
        if (t || (D(i), J?.(i)), i.baseUIHandlerPrevented)
          return;
        const X = i.target === i.currentTarget && !r && !u() && !t, S = i.key === "Enter", ee = i.key === " ";
        X && ((ee || S) && i.preventDefault(), S && d?.(i));
      },
      onKeyUp(i) {
        t || (D(i), z?.(i)), !i.baseUIHandlerPrevented && i.target === i.currentTarget && !r && !t && i.key === " " && d?.(i);
      },
      onPointerDown(i) {
        if (t) {
          i.preventDefault();
          return;
        }
        Z?.(i);
      }
    }, r ? void 0 : {
      role: "button"
    }, p, Q);
  }, [t, p, r, u]), E = k((f) => {
    o.current = f, l();
  });
  return {
    getButtonProps: h,
    buttonRef: E
  };
}
function Ue(e) {
  return te(e) && e.tagName === "BUTTON";
}
function Me(e) {
  const t = g(Te, e).current;
  return t.next = e, V(t.effect), t;
}
function Te(e) {
  const t = {
    current: e,
    next: e,
    effect: () => {
      t.current = t.next;
    }
  };
  return t;
}
function et(e) {
  const {
    enabled: t = !0,
    open: n,
    ref: s,
    onComplete: r
  } = e, o = Me(n), c = k(r), u = Se(s, n);
  a.useEffect(() => {
    t && u(() => {
      n === o.current && c();
    });
  }, [t, n, c, u, o]);
}
export {
  O as A,
  m as E,
  Ke as N,
  G as T,
  V as a,
  Se as b,
  k as c,
  Je as d,
  Pe as e,
  K as f,
  B as g,
  we as h,
  Qe as i,
  Le as j,
  Xe as k,
  et as l,
  g as m,
  qe as n,
  He as o,
  le as p,
  Me as q,
  Oe as r,
  je as s,
  $e as t,
  Ze as u,
  We as v,
  Ye as w,
  ze as x,
  Ge as y
};
//# sourceMappingURL=useOpenChangeComplete-RUbg6RBw.mjs.map
