var u = Object.defineProperty;
var p = (e, r, o) => r in e ? u(e, r, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[r] = o;
var s = (e, r, o) => p(e, typeof r != "symbol" ? r + "" : r, o);
import * as a from "react";
import { EMPTY_OBJECT 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/empty.js";
import { useRefWithInit as f } 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/useRefWithInit.js";
import { FloatingTreeStore as c } from "../../floating-ui-react/components/FloatingTreeStore.js";
import { popupStoreSelectors as m, createInitialPopupStoreState as g } from "../../utils/popups/store.js";
import { ReactStore as b } 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 { PopupTriggerMap as y } from "../../utils/popups/popupTriggerMap.js";
import { createSelector as t } 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";
const R = {
  ...m,
  disabled: t((e) => e.parent.type === "menubar" && e.parent.context.disabled || e.disabled),
  modal: t((e) => (e.parent.type === void 0 || e.parent.type === "context-menu") && (e.modal ?? !0)),
  allowMouseEnter: t((e) => e.parent.type === "menu" ? e.parent.store.select("allowMouseEnter") : e.allowMouseEnter),
  stickIfOpen: t((e) => e.stickIfOpen),
  parent: t((e) => e.parent),
  rootId: t((e) => e.parent.type === "menu" ? e.parent.store.select("rootId") : e.parent.type !== void 0 ? e.parent.context.rootId : e.rootId),
  activeIndex: t((e) => e.activeIndex),
  isActive: t((e, r) => e.activeIndex === r),
  hoverEnabled: t((e) => e.hoverEnabled),
  instantType: t((e) => e.instantType),
  lastOpenChangeReason: t((e) => e.openChangeReason),
  floatingTreeRoot: t((e) => e.parent.type === "menu" ? e.parent.store.select("floatingTreeRoot") : e.floatingTreeRoot),
  floatingNodeId: t((e) => e.floatingNodeId),
  floatingParentNodeId: t((e) => e.floatingParentNodeId),
  itemProps: t((e) => e.itemProps),
  closeDelay: t((e) => e.closeDelay),
  keyboardEventRelay: t((e) => {
    if (e.keyboardEventRelay)
      return e.keyboardEventRelay;
    if (e.parent.type === "menu")
      return e.parent.store.select("keyboardEventRelay");
  })
};
class l extends b {
  constructor(o) {
    super({
      ...I(),
      ...o
    }, {
      positionerRef: /* @__PURE__ */ a.createRef(),
      popupRef: /* @__PURE__ */ a.createRef(),
      typingRef: {
        current: !1
      },
      itemDomElements: {
        current: []
      },
      itemLabels: {
        current: []
      },
      allowMouseUpTriggerRef: {
        current: !1
      },
      triggerFocusTargetRef: /* @__PURE__ */ a.createRef(),
      beforeContentFocusGuardRef: /* @__PURE__ */ a.createRef(),
      onOpenChangeComplete: void 0,
      triggerElements: new y()
    }, R);
    s(this, "unsubscribeParentListener", null);
    this.observe(t((n) => n.allowMouseEnter), (n, i) => {
      this.state.parent.type === "menu" && n !== i && this.state.parent.store.set("allowMouseEnter", n);
    }), this.unsubscribeParentListener = this.observe("parent", (n) => {
      var i;
      if ((i = this.unsubscribeParentListener) == null || i.call(this), n.type === "menu") {
        this.unsubscribeParentListener = n.store.subscribe(() => {
          this.notifyAll();
        }), this.context.allowMouseUpTriggerRef = n.store.context.allowMouseUpTriggerRef;
        return;
      }
      n.type !== void 0 && (this.context.allowMouseUpTriggerRef = n.context.allowMouseUpTriggerRef), this.unsubscribeParentListener = null;
    });
  }
  setOpen(o, n) {
    this.state.floatingRootContext.context.events.emit("setOpen", {
      open: o,
      eventDetails: n
    });
  }
  static useStore(o, n) {
    const i = f(() => new l(n)).current;
    return o ?? i;
  }
}
function I() {
  return {
    ...g(),
    disabled: !1,
    modal: !0,
    allowMouseEnter: !0,
    stickIfOpen: !0,
    parent: {
      type: void 0
    },
    rootId: void 0,
    activeIndex: null,
    hoverEnabled: !0,
    instantType: void 0,
    openChangeReason: null,
    floatingTreeRoot: new c(),
    floatingNodeId: void 0,
    floatingParentNodeId: null,
    itemProps: d,
    keyboardEventRelay: void 0,
    closeDelay: 0
  };
}
export {
  l as MenuStore
};
