var S = Object.defineProperty;
var R = (e, o, t) => o in e ? S(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t;
var d = (e, o, t) => R(e, typeof o != "symbol" ? o + "" : o, t);
import * as y from "react";
import * as T from "react-dom";
import { useRefWithInit 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/useRefWithInit.js";
import { useSyncedFloatingRootContext as P } from "../../floating-ui-react/hooks/useSyncedFloatingRootContext.js";
import { ReactStore as I } 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 O } from "../../utils/popups/popupTriggerMap.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 { popupStoreSelectors as w, createInitialPopupStoreState as x } from "../../utils/popups/store.js";
import { triggerHover as m, triggerFocus as H, triggerPress as v, escapeKey as k } from "../../utils/reason-parts.js";
const A = {
  ...w,
  disabled: r((e) => e.disabled),
  instantType: r((e) => e.instantType),
  isInstantPhase: r((e) => e.isInstantPhase),
  trackCursorAxis: r((e) => e.trackCursorAxis),
  disableHoverablePopup: r((e) => e.disableHoverablePopup),
  lastOpenChangeReason: r((e) => e.openChangeReason),
  closeDelay: r((e) => e.closeDelay),
  hasViewport: r((e) => e.hasViewport)
};
class h extends I {
  constructor(t) {
    super({
      ...F(),
      ...t
    }, {
      popupRef: /* @__PURE__ */ y.createRef(),
      onOpenChange: void 0,
      onOpenChangeComplete: void 0,
      triggerElements: new O()
    }, A);
    d(this, "setOpen", (t, n) => {
      var l, u;
      const s = n.reason, a = s === m, p = t && s === H, C = !t && (s === v || s === k);
      if (n.preventUnmountOnClose = () => {
        this.set("preventUnmountingOnClose", !0);
      }, (u = (l = this.context).onOpenChange) == null || u.call(l, t, n), n.isCanceled)
        return;
      const c = () => {
        var f;
        const i = {
          open: t,
          openChangeReason: s
        };
        p ? i.instantType = "focus" : C ? i.instantType = "dismiss" : s === m && (i.instantType = void 0);
        const g = ((f = n.trigger) == null ? void 0 : f.id) ?? null;
        (g || t) && (i.activeTriggerId = g, i.activeTriggerElement = n.trigger ?? null), this.update(i);
      };
      a ? T.flushSync(c) : c();
    });
  }
  static useStore(t, n) {
    const s = b(() => new h(n)).current, a = t ?? s, p = P({
      popupStore: a,
      onOpenChange: a.setOpen
    });
    return a.state.floatingRootContext = p, a;
  }
}
function F() {
  return {
    ...x(),
    disabled: !1,
    instantType: void 0,
    isInstantPhase: !1,
    trackCursorAxis: "none",
    disableHoverablePopup: !1,
    openChangeReason: null,
    closeDelay: 0,
    hasViewport: !1
  };
}
export {
  h as TooltipStore
};
