var E = Object.defineProperty;
var a = (e, n, t) => n in e ? E(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
var f = (e, n, t) => a(e, typeof n != "symbol" ? n + "" : n, t);
import { createEventEmitter as l } from "../utils/createEventEmitter.js";
import { ReactStore as d } from "../../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/store/ReactStore.js";
import { createSelector as r } from "../../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/store/createSelector.js";
import { isClickLikeEvent as g } from "../utils/event.js";
const p = {
  open: r((e) => e.open),
  domReferenceElement: r((e) => e.domReferenceElement),
  referenceElement: r((e) => e.positionReference ?? e.referenceElement),
  floatingElement: r((e) => e.floatingElement),
  floatingId: r((e) => e.floatingId)
};
class S extends d {
  constructor(t) {
    const {
      nested: o,
      noEmit: i,
      onOpenChange: c,
      triggerElements: m,
      ...s
    } = t;
    super({
      ...s,
      positionReference: s.referenceElement,
      domReferenceElement: s.referenceElement
    }, {
      onOpenChange: c,
      dataRef: {
        current: {}
      },
      events: l(),
      nested: o,
      noEmit: i,
      triggerElements: m
    }, p);
    /**
     * Emits the `openchange` event through the internal event emitter and calls the `onOpenChange` handler with the provided arguments.
     *
     * @param newOpen The new open state.
     * @param eventDetails Details about the event that triggered the open state change.
     */
    f(this, "setOpen", (t, o) => {
      var i, c;
      if ((!t || !this.state.open || // Prevent a pending hover-open from overwriting a click-open event, while allowing
      // click events to upgrade a hover-open.
      g(o.event)) && (this.context.dataRef.current.openEvent = t ? o.event : void 0), !this.context.noEmit) {
        const m = {
          open: t,
          reason: o.reason,
          nativeEvent: o.event,
          nested: this.context.nested,
          triggerElement: o.trigger
        };
        this.context.events.emit("openchange", m);
      }
      (c = (i = this.context).onOpenChange) == null || c.call(i, t, o);
    });
  }
}
export {
  S as FloatingRootStore
};
