import { o as q } from "./rolldown-runtime.js";
import { i as re, r as ie, t as ae } from "./vendor/react.js";
import { u as le } from "./safeReact.js";
import { s as j, t as X, u as ue } from "./useRenderElement.js";
import { n as W, t as D } from "./useIsoLayoutEffect.js";
import { a as ce, n as pe } from "./useTransitionStatus.js";
import { n as fe, t as de } from "./useTimeout.js";
import { t as ge } from "./useBaseUiId.js";
import { n as me, r as he } from "./shadowDom.js";
import { A as Ce, E as ve, M as ye, a as Pe, f as I, j as Se, l as xe, n as Te, o as Re, p as be, r as G, s as Ie } from "./popupStateMapping.js";
import { n as Oe } from "./event.js";
import { t as Me } from "./addEventListener.js";
import { i as we, n as Ee, r as ke, t as Ae } from "./safePolygon.js";
import { S as De, a as He, g as Ve, l as _e, t as N } from "./createBaseUIEventDetails.js";
import { i as je, n as Fe, r as Be, t as Le } from "./usePositioner.js";
import { a as Ue, i as Ne, n as Xe, o as We, r as Ye, t as qe } from "./useSyncedFloatingRootContext.js";
import { t as Ge } from "./useFocus.js";
import { t as Ke } from "./FloatingPortalLite.js";
var w = ae(), i = /* @__PURE__ */ q(re()), K = /* @__PURE__ */ i.createContext(void 0);
function V(t) {
  const e = i.useContext(K);
  if (e === void 0 && !t) throw new Error(j(72));
  return e;
}
var $ = /* @__PURE__ */ i.createContext({
  hasProvider: !1,
  timeoutMs: 0,
  delayRef: { current: 0 },
  initialDelayRef: { current: 0 },
  timeout: new de(),
  currentIdRef: { current: null },
  currentContextRef: { current: null }
});
function $e(t) {
  const { children: e, delay: n, timeoutMs: s = 0 } = t, l = i.useRef(n), a = i.useRef(n), u = i.useRef(null), r = i.useRef(null), p = fe();
  return /* @__PURE__ */ (0, w.jsx)($.Provider, {
    value: i.useMemo(() => ({
      hasProvider: !0,
      delayRef: l,
      initialDelayRef: a,
      currentIdRef: u,
      timeoutMs: s,
      currentContextRef: r,
      timeout: p
    }), [s, p]),
    children: e
  });
}
function ze(t, e = { open: !1 }) {
  const n = "rootStore" in t ? t.rootStore : t, s = n.useState("floatingId"), { open: l } = e, { currentIdRef: a, delayRef: u, timeoutMs: r, initialDelayRef: p, currentContextRef: c, hasProvider: f, timeout: g } = i.useContext($), [m, v] = i.useState(!1);
  return D(() => {
    function o() {
      v(!1), c.current?.setIsInstantPhase(!1), a.current = null, c.current = null, u.current = p.current;
    }
    if (a.current && !l && a.current === s) {
      if (v(!1), r) {
        const d = s;
        return g.start(r, () => {
          n.select("open") || a.current && a.current !== d || o();
        }), () => {
          g.clear();
        };
      }
      o();
    }
  }, [
    l,
    s,
    a,
    u,
    r,
    p,
    c,
    g,
    n
  ]), D(() => {
    if (!l) return;
    const o = c.current, d = a.current;
    g.clear(), c.current = {
      onOpenChange: n.setOpen,
      setIsInstantPhase: v
    }, a.current = s, u.current = {
      open: 0,
      close: we(p.current, "close")
    }, d !== null && d !== s ? (v(!0), o?.setIsInstantPhase(!0), o?.onOpenChange(!1, N(Ve))) : (v(!1), o?.setIsInstantPhase(!1));
  }, [
    l,
    s,
    n,
    a,
    u,
    r,
    p,
    c,
    g
  ]), D(() => () => {
    c.current = null;
  }, [c]), i.useMemo(() => ({
    hasProvider: f,
    delayRef: u,
    isInstantPhase: m
  }), [
    f,
    u,
    m
  ]);
}
function Je(t, e) {
  let n = null, s = null, l = !1;
  return {
    contextElement: t || void 0,
    getBoundingClientRect() {
      const a = t?.getBoundingClientRect() || {
        width: 0,
        height: 0,
        x: 0,
        y: 0
      }, u = e.axis === "x" || e.axis === "both", r = e.axis === "y" || e.axis === "both", p = ["mouseenter", "mousemove"].includes(e.dataRef.current.openEvent?.type || "") && e.pointerType !== "touch";
      let c = a.width, f = a.height, g = a.x, m = a.y;
      return n == null && e.x && u && (n = a.x - e.x), s == null && e.y && r && (s = a.y - e.y), g -= n || 0, m -= s || 0, c = 0, f = 0, !l || p ? (c = e.axis === "y" ? a.width : 0, f = e.axis === "x" ? a.height : 0, g = u && e.x != null ? e.x : g, m = r && e.y != null ? e.y : m) : l && !p && (f = e.axis === "x" ? a.height : f, c = e.axis === "y" ? a.width : c), l = !0, {
        width: c,
        height: f,
        x: g,
        y: m,
        top: m,
        right: g + c,
        bottom: m + f,
        left: g
      };
    }
  };
}
function Y(t) {
  return t != null && t.clientX != null;
}
function Qe(t, e = {}) {
  const n = "rootStore" in t ? t.rootStore : t, s = n.useState("open"), l = n.useState("floatingElement"), a = n.useState("domReferenceElement"), u = n.context.dataRef, { enabled: r = !0, axis: p = "both" } = e, c = i.useRef(!1), f = i.useRef(null), [g, m] = i.useState(), [v, o] = i.useState([]), d = W((C, S, P) => {
    c.current || u.current.openEvent && !Y(u.current.openEvent) || n.set("positionReference", Je(P ?? a, {
      x: C,
      y: S,
      axis: p,
      dataRef: u,
      pointerType: g
    }));
  }), y = W((C) => {
    s ? f.current || o([]) : d(C.clientX, C.clientY, C.currentTarget);
  }), O = Oe(g) ? l : s, R = i.useCallback(() => {
    if (!O || !r) return;
    const C = le(l);
    function S(P) {
      me(l, he(P)) ? (f.current?.(), f.current = null) : d(P.clientX, P.clientY);
    }
    if (!u.current.openEvent || Y(u.current.openEvent)) {
      const P = () => {
        f.current?.(), f.current = null;
      };
      return f.current = Me(C, "mousemove", S), P;
    }
    n.set("positionReference", a);
  }, [
    O,
    r,
    l,
    u,
    a,
    n,
    d
  ]);
  i.useEffect(() => R(), [R, v]), i.useEffect(() => {
    r && !l && (c.current = !1);
  }, [r, l]), i.useEffect(() => {
    !r && s && (c.current = !0);
  }, [r, s]);
  const h = i.useMemo(() => {
    function C(S) {
      m(S.pointerType);
    }
    return {
      onPointerDown: C,
      onPointerEnter: C,
      onMouseMove: y,
      onMouseEnter: y
    };
  }, [y]);
  return i.useMemo(() => r ? {
    reference: h,
    trigger: h
  } : {}, [r, h]);
}
var Ze = /* @__PURE__ */ q(ie()), et = {
  ...Ye,
  disabled: I((t) => t.disabled),
  instantType: I((t) => t.instantType),
  isInstantPhase: I((t) => t.isInstantPhase),
  trackCursorAxis: I((t) => t.trackCursorAxis),
  disableHoverablePopup: I((t) => t.disableHoverablePopup),
  lastOpenChangeReason: I((t) => t.openChangeReason),
  closeOnClick: I((t) => t.closeOnClick),
  closeDelay: I((t) => t.closeDelay),
  hasViewport: I((t) => t.hasViewport)
}, tt = class z extends xe {
  constructor(e) {
    super({
      ...nt(),
      ...e
    }, {
      popupRef: /* @__PURE__ */ i.createRef(),
      onOpenChange: void 0,
      onOpenChangeComplete: void 0,
      triggerElements: new Ie()
    }, et);
  }
  setOpen = (e, n) => {
    const s = n.reason, l = s === De, a = e && s === "trigger-focus", u = !e && (s === "trigger-press" || s === "escape-key");
    if (n.preventUnmountOnClose = () => {
      this.set("preventUnmountingOnClose", !0);
    }, this.context.onOpenChange?.(e, n), n.isCanceled) return;
    this.state.floatingRootContext.dispatchOpenChange(e, n);
    const r = () => {
      const p = {
        open: e,
        openChangeReason: s
      };
      a ? p.instantType = "focus" : u ? p.instantType = "dismiss" : s === "trigger-hover" && (p.instantType = void 0);
      const c = n.trigger?.id ?? null;
      (c || e) && (p.activeTriggerId = c, p.activeTriggerElement = n.trigger ?? null), this.update(p);
    };
    l ? Ze.flushSync(r) : r();
  };
  static useStore(e, n) {
    const s = ue(() => new z(n)).current, l = e ?? s, a = qe({
      popupStore: l,
      onOpenChange: l.setOpen
    });
    return l.state.floatingRootContext = a, l;
  }
};
function nt() {
  return {
    ...Xe(),
    disabled: !1,
    instantType: void 0,
    isInstantPhase: !1,
    trackCursorAxis: "none",
    disableHoverablePopup: !1,
    openChangeReason: null,
    closeOnClick: !0,
    closeDelay: 0,
    hasViewport: !1
  };
}
var Mt = Se(function(e) {
  const { disabled: n = !1, defaultOpen: s = !1, open: l, disableHoverablePopup: a = !1, trackCursorAxis: u = "none", actionsRef: r, onOpenChange: p, onOpenChangeComplete: c, handle: f, triggerId: g, defaultTriggerId: m = null, children: v } = e, o = tt.useStore(f?.store, {
    open: s,
    openProp: l,
    activeTriggerId: m,
    triggerIdProp: g
  });
  Ce(() => {
    l === void 0 && o.state.open === !1 && s === !0 && o.update({
      open: !0,
      activeTriggerId: m
    });
  }), o.useControlledProp("openProp", l), o.useControlledProp("triggerIdProp", g), o.useContextCallback("onOpenChange", p), o.useContextCallback("onOpenChangeComplete", c);
  const d = o.useState("open"), y = !n && d, O = o.useState("activeTriggerId"), R = o.useState("payload");
  o.useSyncedValues({
    trackCursorAxis: u,
    disableHoverablePopup: a
  }), D(() => {
    d && n && o.setOpen(!1, N(He));
  }, [
    d,
    n,
    o
  ]), o.useSyncedValue("disabled", n), Ne(o);
  const { forceUnmount: h, transitionStatus: C } = Ue(y, o), S = o.select("floatingRootContext"), P = o.useState("isInstantPhase"), b = o.useState("instantType"), E = o.useState("lastOpenChangeReason"), M = i.useRef(null);
  D(() => {
    C === "ending" && E === "none" || C !== "ending" && P ? (b !== "delay" && (M.current = b), o.set("instantType", "delay")) : M.current !== null && (o.set("instantType", M.current), M.current = null);
  }, [
    C,
    P,
    E,
    b,
    o
  ]), D(() => {
    y && O == null && o.set("payload", void 0);
  }, [
    o,
    O,
    y
  ]);
  const T = i.useCallback(() => {
    o.setOpen(!1, N(_e));
  }, [o]);
  i.useImperativeHandle(r, () => ({
    unmount: h,
    close: T
  }), [h, T]);
  const { getReferenceProps: k, getFloatingProps: x, getTriggerProps: A } = Re([be(S, {
    enabled: !n,
    referencePress: () => o.select("closeOnClick")
  }), Qe(S, {
    enabled: !n && u !== "none",
    axis: u === "none" ? void 0 : u
  })]), H = i.useMemo(() => k(), [k]), F = i.useMemo(() => A(), [A]), B = i.useMemo(() => x(), [x]);
  return o.useSyncedValues({
    activeTriggerProps: H,
    inactiveTriggerProps: F,
    popupProps: B
  }), /* @__PURE__ */ (0, w.jsx)(K.Provider, {
    value: o,
    children: typeof v == "function" ? v({ payload: R }) : v
  });
}), J = /* @__PURE__ */ i.createContext(void 0);
function ot() {
  return i.useContext(J);
}
var st = (function(t) {
  return t[t.popupOpen = Te.popupOpen] = "popupOpen", t.triggerDisabled = "data-trigger-disabled", t;
})({}), wt = ye(function(e, n) {
  const { className: s, render: l, handle: a, payload: u, disabled: r, delay: p, closeOnClick: c = !0, closeDelay: f, id: g, style: m, ...v } = e, o = V(!0), d = a?.store ?? o;
  if (!d) throw new Error(j(82));
  const y = ge(g), O = d.useState("isTriggerActive", y), R = d.useState("isOpenedByTrigger", y), h = d.useState("floatingRootContext"), C = i.useRef(null), S = p ?? 600, P = f ?? 0, { registerTrigger: b, isMountedByThisTrigger: E } = We(y, C, d, {
    payload: u,
    closeOnClick: c,
    closeDelay: P
  }), M = ot(), { delayRef: T, isInstantPhase: k, hasProvider: x } = ze(h, { open: R });
  d.useSyncedValue("isInstantPhase", k);
  const A = d.useState("disabled"), H = r ?? A, F = d.useState("trackCursorAxis"), B = d.useState("disableHoverablePopup"), te = Ee(h, {
    enabled: !H,
    mouseOnly: !0,
    move: !1,
    handleClose: !B && F !== "both" ? Ae() : null,
    restMs() {
      const L = M?.delay, _ = typeof T.current == "object" ? T.current.open : void 0;
      let U = S;
      return x && (_ !== 0 ? U = p ?? L ?? S : U = 0), U;
    },
    delay() {
      const L = typeof T.current == "object" ? T.current.close : void 0;
      let _ = P;
      return f == null && x && (_ = L), { close: _ };
    },
    triggerElementRef: C,
    isActiveTrigger: O,
    isClosing: () => d.select("transitionStatus") === "ending"
  }), ne = Ge(h, { enabled: !H }).reference, oe = { open: R }, se = d.useState("triggerProps", E);
  return X("button", e, {
    state: oe,
    ref: [
      n,
      b,
      C
    ],
    props: [
      te,
      ne,
      se,
      {
        onPointerDown() {
          d.set("closeOnClick", c);
        },
        id: y,
        [st.triggerDisabled]: H ? "" : void 0
      },
      v
    ],
    stateAttributesMapping: Pe
  });
}), Q = /* @__PURE__ */ i.createContext(void 0);
function rt() {
  const t = i.useContext(Q);
  if (t === void 0) throw new Error(j(70));
  return t;
}
var Et = /* @__PURE__ */ i.forwardRef(function(e, n) {
  const { keepMounted: s = !1, ...l } = e;
  return V().useState("mounted") || s ? /* @__PURE__ */ (0, w.jsx)(Q.Provider, {
    value: s,
    children: /* @__PURE__ */ (0, w.jsx)(Ke, {
      ref: n,
      ...l
    })
  }) : null;
}), Z = /* @__PURE__ */ i.createContext(void 0);
function ee() {
  const t = i.useContext(Z);
  if (t === void 0) throw new Error(j(71));
  return t;
}
var kt = /* @__PURE__ */ i.forwardRef(function(e, n) {
  const { render: s, className: l, anchor: a, positionMethod: u = "absolute", side: r = "top", align: p = "center", sideOffset: c = 0, alignOffset: f = 0, collisionBoundary: g = "clipping-ancestors", collisionPadding: m = 5, arrowPadding: v = 5, sticky: o = !1, disableAnchorTracking: d = !1, collisionAvoidance: y = ve, style: O, ...R } = e, h = V(), C = rt(), S = h.useState("open"), P = h.useState("mounted"), b = h.useState("trackCursorAxis"), E = h.useState("disableHoverablePopup"), M = h.useState("floatingRootContext"), T = h.useState("instantType"), k = h.useState("transitionStatus"), x = Be({
    anchor: a,
    positionMethod: u,
    floatingRootContext: M,
    mounted: P,
    side: r,
    sideOffset: c,
    align: p,
    alignOffset: f,
    collisionBoundary: g,
    collisionPadding: m,
    sticky: o,
    arrowPadding: v,
    disableAnchorTracking: d,
    keepMounted: C,
    collisionAvoidance: y,
    adaptiveOrigin: h.useState("hasViewport") ? je : void 0
  }), A = Le(e, i.useMemo(() => ({
    open: S,
    side: x.side,
    align: x.align,
    anchorHidden: x.anchorHidden,
    instant: b !== "none" ? "tracking-cursor" : T
  }), [
    S,
    x.side,
    x.align,
    x.anchorHidden,
    b,
    T
  ]), {
    styles: x.positionerStyles,
    transitionStatus: k,
    props: R,
    refs: [n, h.useStateSetter("positionerElement")],
    hidden: !P,
    inert: !S || b === "both" || E
  });
  return /* @__PURE__ */ (0, w.jsx)(Z.Provider, {
    value: x,
    children: A
  });
}), it = {
  ...G,
  ...ce
}, At = /* @__PURE__ */ i.forwardRef(function(e, n) {
  const { className: s, render: l, style: a, ...u } = e, r = V(), { side: p, align: c } = ee(), f = r.useState("open"), g = r.useState("instantType"), m = r.useState("transitionStatus"), v = r.useState("popupProps"), o = r.useState("floatingRootContext");
  pe({
    open: f,
    ref: r.context.popupRef,
    onComplete() {
      f && r.context.onOpenChangeComplete?.(!0);
    }
  });
  const d = r.useState("disabled"), y = r.useState("closeDelay");
  return ke(o, {
    enabled: !d,
    closeDelay: y
  }), X("div", e, {
    state: {
      open: f,
      side: p,
      align: c,
      instant: g,
      transitionStatus: m
    },
    ref: [
      n,
      r.context.popupRef,
      r.useStateSetter("popupElement")
    ],
    props: [
      v,
      Fe(m),
      u
    ],
    stateAttributesMapping: it
  });
}), Dt = /* @__PURE__ */ i.forwardRef(function(e, n) {
  const { className: s, render: l, style: a, ...u } = e, r = V(), p = r.useState("open"), c = r.useState("instantType"), { arrowRef: f, side: g, align: m, arrowUncentered: v, arrowStyles: o } = ee();
  return X("div", e, {
    state: {
      open: p,
      side: g,
      align: m,
      uncentered: v,
      instant: c
    },
    ref: [n, f],
    props: [{
      style: o,
      "aria-hidden": !0
    }, u],
    stateAttributesMapping: G
  });
}), Ht = function(e) {
  const { delay: n, closeDelay: s, timeout: l = 400 } = e, a = i.useMemo(() => ({
    delay: n,
    closeDelay: s
  }), [n, s]), u = i.useMemo(() => ({
    open: n,
    close: s
  }), [n, s]);
  return /* @__PURE__ */ (0, w.jsx)(J.Provider, {
    value: a,
    children: /* @__PURE__ */ (0, w.jsx)($e, {
      delay: u,
      timeoutMs: l,
      children: e.children
    })
  });
};
export {
  Et as a,
  kt as i,
  Dt as n,
  wt as o,
  At as r,
  Mt as s,
  Ht as t
};

//# sourceMappingURL=TooltipProvider.js.map