import { o as $ } from "./rolldown-runtime.js";
import { i as re, r as ae, t as ie } from "./vendor/react.js";
import { p as ce } from "./safeReact.js";
import { s as U, t as D, u as ue } from "./useRenderElement.js";
import { n as pe, t as Y } from "./useIsoLayoutEffect.js";
import { t as le } from "./useButton.js";
import { t as de } from "./useOnMount.js";
import { a as ge, n as fe, r as me } from "./useTransitionStatus.js";
import { t as ve } from "./useTimeout.js";
import { t as z } from "./useBaseUiId.js";
import { A as he, C as Ce, E as Pe, O as X, _ as Se, a as Te, b as Re, f as P, g as xe, h as Ie, i as ye, l as Ee, m as Oe, o as ee, p as Me, r as be, s as Fe } from "./popupStateMapping.js";
import { n as ke, r as we, t as je } from "./safePolygon.js";
import { S as Ae, l as _e, t as He } from "./createBaseUIEventDetails.js";
import { a as Be, i as Ne, r as Ge, t as Ve } from "./useOpenInteractionType.js";
import { i as Le, n as Ke, r as Ue, t as De } from "./usePositioner.js";
import { a as qe, i as We, n as Ye, o as ze, r as Je, t as Qe } from "./useSyncedFloatingRootContext.js";
import { t as Xe } from "./useRole.js";
import { t as Ze } from "./inertValue.js";
import { s as $e } from "./composite2.js";
import { t as et } from "./ToolbarRootContext.js";
import { t as tt } from "./useAnchoredPopupScrollLock.js";
import { t as ot } from "./useTriggerFocusGuards.js";
var n = /* @__PURE__ */ $(re()), te = /* @__PURE__ */ n.createContext(void 0);
function b(e) {
  const o = n.useContext(te);
  if (o === void 0 && !e) throw new Error(U(47));
  return o;
}
var nt = /* @__PURE__ */ $(ae());
function st() {
  return {
    ...Ye(),
    disabled: !1,
    modal: !1,
    focusManagerModal: !1,
    instantType: void 0,
    openMethod: null,
    openChangeReason: null,
    titleElementId: void 0,
    descriptionElementId: void 0,
    stickIfOpen: !0,
    nested: !1,
    openOnHover: !1,
    closeDelay: 0,
    hasViewport: !1
  };
}
var rt = {
  ...Je,
  disabled: P((e) => e.disabled),
  instantType: P((e) => e.instantType),
  openMethod: P((e) => e.openMethod),
  openChangeReason: P((e) => e.openChangeReason),
  modal: P((e) => e.modal),
  focusManagerModal: P((e) => e.focusManagerModal),
  stickIfOpen: P((e) => e.stickIfOpen),
  titleElementId: P((e) => e.titleElementId),
  descriptionElementId: P((e) => e.descriptionElementId),
  openOnHover: P((e) => e.openOnHover),
  closeDelay: P((e) => e.closeDelay),
  hasViewport: P((e) => e.hasViewport)
}, at = class oe extends Ee {
  constructor(o) {
    const t = {
      ...st(),
      ...o
    };
    t.open && o?.mounted === void 0 && (t.mounted = !0), super(t, {
      popupRef: /* @__PURE__ */ n.createRef(),
      backdropRef: /* @__PURE__ */ n.createRef(),
      internalBackdropRef: /* @__PURE__ */ n.createRef(),
      onOpenChange: void 0,
      onOpenChangeComplete: void 0,
      triggerFocusTargetRef: /* @__PURE__ */ n.createRef(),
      beforeContentFocusGuardRef: /* @__PURE__ */ n.createRef(),
      stickIfOpenTimeout: new ve(),
      triggerElements: new Fe()
    }, rt);
  }
  setOpen = (o, t) => {
    const c = t.reason === Ae, v = t.reason === "trigger-press" && t.event.detail === 0, g = !o && (t.reason === "escape-key" || t.reason == null);
    if (t.preventUnmountOnClose = () => {
      this.set("preventUnmountingOnClose", !0);
    }, this.context.onOpenChange?.(o, t), t.isCanceled) return;
    this.state.floatingRootContext.dispatchOpenChange(o, t);
    const p = () => {
      const l = {
        open: o,
        openChangeReason: t.reason
      }, u = t.trigger?.id ?? null;
      (u || o) && (l.activeTriggerId = u, l.activeTriggerElement = t.trigger ?? null), this.update(l);
    };
    c ? (this.set("stickIfOpen", !0), this.context.stickIfOpenTimeout.start(500, () => {
      this.set("stickIfOpen", !1);
    }), nt.flushSync(p)) : p(), v || g ? this.set("instantType", v ? "click" : "dismiss") : t.reason === "focus-out" ? this.set("instantType", "focus") : this.set("instantType", void 0);
  };
  static useStore(o, t) {
    const c = ue(() => new oe(t)).current, v = o ?? c;
    return de(c.disposeEffect), v;
  }
  disposeEffect = () => this.context.stickIfOpenTimeout.disposeEffect();
}, d = ie();
function Z({ props: e }) {
  const { children: o, open: t, defaultOpen: c = !1, onOpenChange: v, onOpenChangeComplete: g, modal: p = !1, handle: l, triggerId: u, defaultTriggerId: s = null } = e, r = at.useStore(l?.store, {
    modal: p,
    open: c,
    openProp: t,
    activeTriggerId: s,
    triggerIdProp: u
  });
  he(() => {
    t === void 0 && r.state.open === !1 && c === !0 && r.update({
      open: !0,
      activeTriggerId: s
    });
  }), r.useControlledProp("openProp", t), r.useControlledProp("triggerIdProp", u);
  const S = r.useState("open"), O = r.useState("payload");
  r.useContextCallback("onOpenChange", v), r.useContextCallback("onOpenChangeComplete", g);
  const { openMethod: F, triggerProps: C } = Ve(S);
  We(r);
  const { forceUnmount: I } = qe(S, r, () => {
    r.update({
      stickIfOpen: !0,
      openChangeReason: null
    });
  });
  n.useEffect(() => {
    S || r.context.stickIfOpenTimeout.clear();
  }, [r, S]);
  const i = n.useCallback(() => {
    r.setOpen(!1, He(_e));
  }, [r]);
  n.useImperativeHandle(e.actionsRef, () => ({
    unmount: I,
    close: i
  }), [I, i]);
  const m = Qe({
    popupStore: r,
    onOpenChange: r.setOpen
  }), { getReferenceProps: R, getFloatingProps: a, getTriggerProps: y } = ee([Me(m, { outsidePressEvent: {
    mouse: p === "trap-focus" ? "sloppy" : "intentional",
    touch: "sloppy"
  } }), Xe(m)]), T = n.useMemo(() => R(C), [R, C]), E = n.useMemo(() => y(C), [y, C]), x = n.useMemo(() => a(), [a]);
  r.useSyncedValues({
    modal: p,
    openMethod: F,
    activeTriggerProps: T,
    inactiveTriggerProps: E,
    popupProps: x,
    floatingRootContext: m,
    nested: Se() != null
  });
  const h = n.useMemo(() => ({ store: r }), [r]);
  return /* @__PURE__ */ (0, d.jsx)(te.Provider, {
    value: h,
    children: typeof o == "function" ? o({ payload: O }) : o
  });
}
function Nt(e) {
  return b(!0) ? /* @__PURE__ */ (0, d.jsx)(Z, { props: e }) : /* @__PURE__ */ (0, d.jsx)(Ie, { children: /* @__PURE__ */ (0, d.jsx)(Z, { props: e }) });
}
var Gt = /* @__PURE__ */ n.forwardRef(function(o, t) {
  const { render: c, className: v, disabled: g = !1, nativeButton: p = !0, handle: l, payload: u, openOnHover: s = !1, delay: r = 300, closeDelay: S = 0, id: O, style: F, ...C } = o, I = b(!0), i = l?.store ?? I?.store;
  if (!i) throw new Error(U(74));
  const m = z(O), R = i.useState("isTriggerActive", m), a = i.useState("floatingRootContext"), y = i.useState("isOpenedByTrigger", m), T = n.useRef(null), { registerTrigger: E, isMountedByThisTrigger: x } = ze(m, T, i, {
    payload: u,
    disabled: g,
    openOnHover: s,
    closeDelay: S
  }), h = i.useState("openChangeReason"), M = i.useState("stickIfOpen"), k = i.useState("openMethod"), w = i.useState("focusManagerModal"), N = ke(a, {
    enabled: a != null && s && (k !== "touch" || h !== "trigger-press"),
    mouseOnly: !0,
    move: !1,
    handleClose: je(),
    restMs: r,
    delay: { close: S },
    triggerElementRef: T,
    isActiveTrigger: R,
    isClosing: () => i.select("transitionStatus") === "ending"
  }), j = ee([Ne(a, {
    enabled: a != null,
    stickIfOpen: M
  })]), G = i.useState("triggerProps", x), V = {
    disabled: g,
    open: y
  }, { getButtonProps: A, buttonRef: _ } = le({
    disabled: g,
    native: p
  }), H = n.useMemo(() => ({ open(L) {
    return L && h === "trigger-press" ? ye.open(L) : Te.open(L);
  } }), [h]), f = D("button", o, {
    state: V,
    ref: [
      _,
      t,
      E,
      T
    ],
    props: [
      j.getReferenceProps(),
      N,
      G,
      {
        [Ce]: "",
        id: m
      },
      C,
      A
    ],
    stateAttributesMapping: H
  }), { preFocusGuardRef: K, handlePreFocusGuardFocus: q, handleFocusTargetFocus: W } = ot(i, T);
  return R && !w ? /* @__PURE__ */ (0, d.jsxs)(n.Fragment, { children: [
    /* @__PURE__ */ (0, d.jsx)(X, {
      ref: K,
      onFocus: q
    }),
    /* @__PURE__ */ (0, d.jsx)(n.Fragment, { children: f }, m),
    /* @__PURE__ */ (0, d.jsx)(X, {
      ref: i.context.triggerFocusTargetRef,
      onFocus: W
    })
  ] }) : /* @__PURE__ */ (0, d.jsx)(n.Fragment, { children: f }, m);
}), ne = /* @__PURE__ */ n.createContext(void 0);
function it() {
  const e = n.useContext(ne);
  if (e === void 0) throw new Error(U(45));
  return e;
}
var Vt = /* @__PURE__ */ n.forwardRef(function(o, t) {
  const { keepMounted: c = !1, ...v } = o, { store: g } = b();
  return g.useState("mounted") || c ? /* @__PURE__ */ (0, d.jsx)(ne.Provider, {
    value: c,
    children: /* @__PURE__ */ (0, d.jsx)(Re, {
      ref: t,
      ...v
    })
  }) : null;
}), se = /* @__PURE__ */ n.createContext(void 0);
function ct() {
  const e = n.useContext(se);
  if (!e) throw new Error(U(46));
  return e;
}
var Lt = /* @__PURE__ */ n.forwardRef(function(o, t) {
  const { render: c, className: v, anchor: g, positionMethod: p = "absolute", side: l = "bottom", align: u = "center", sideOffset: s = 0, alignOffset: r = 0, collisionBoundary: S = "clipping-ancestors", collisionPadding: O = 5, arrowPadding: F = 5, sticky: C = !1, disableAnchorTracking: I = !1, collisionAvoidance: i = Pe, style: m, ...R } = o, { store: a } = b(), y = it(), T = xe(), E = a.useState("floatingRootContext"), x = a.useState("mounted"), h = a.useState("open"), M = a.useState("openChangeReason"), k = a.useState("activeTriggerElement"), w = a.useState("modal"), N = a.useState("openMethod"), j = a.useState("positionerElement"), G = a.useState("instantType"), V = a.useState("transitionStatus"), A = a.useState("hasViewport"), _ = n.useRef(null), H = me(j, !1, !1), f = Ue({
    anchor: g,
    floatingRootContext: E,
    positionMethod: p,
    mounted: x,
    side: l,
    sideOffset: s,
    align: u,
    alignOffset: r,
    arrowPadding: F,
    collisionBoundary: S,
    collisionPadding: O,
    sticky: C,
    disableAnchorTracking: I,
    keepMounted: y,
    nodeId: T,
    collisionAvoidance: i,
    adaptiveOrigin: A ? Le : void 0
  }), K = E.useState("domReferenceElement");
  Y(() => {
    const B = K, J = _.current;
    if (B && (_.current = B), J && B && B !== J) {
      a.set("instantType", void 0);
      const Q = new AbortController();
      return H(() => {
        a.set("instantType", "trigger-change");
      }, Q.signal), () => {
        Q.abort();
      };
    }
  }, [
    K,
    H,
    a
  ]);
  const q = {
    open: h,
    side: f.side,
    align: f.align,
    anchorHidden: f.anchorHidden,
    instant: G
  };
  tt(h && w === !0 && M !== "trigger-hover", N === "touch", j, k);
  const W = n.useCallback((B) => {
    a.set("positionerElement", B);
  }, [a]), L = De(o, q, {
    styles: f.positionerStyles,
    transitionStatus: V,
    props: R,
    refs: [t, W],
    hidden: !x,
    inert: !h
  });
  return /* @__PURE__ */ (0, d.jsxs)(se.Provider, {
    value: f,
    children: [x && w === !0 && M !== "trigger-hover" && /* @__PURE__ */ (0, d.jsx)(Ge, {
      ref: a.context.internalBackdropRef,
      inert: Ze(!h),
      cutout: k
    }), /* @__PURE__ */ (0, d.jsx)(Oe, {
      id: T,
      children: L
    })]
  });
}), ut = /* @__PURE__ */ n.createContext(void 0);
function pt() {
  const [e, o] = n.useState(0), t = pe(() => (o((c) => c + 1), () => {
    o((c) => Math.max(0, c - 1));
  }));
  return {
    context: n.useMemo(() => ({ register: t }), [t]),
    hasClosePart: e > 0
  };
}
function lt(e) {
  const { value: o, children: t } = e;
  return /* @__PURE__ */ (0, d.jsx)(ut.Provider, {
    value: o,
    children: t
  });
}
var dt = {
  ...be,
  ...ge
}, Kt = /* @__PURE__ */ n.forwardRef(function(o, t) {
  const { className: c, render: v, initialFocus: g, finalFocus: p, style: l, ...u } = o, { store: s } = b(), r = ct(), S = et(!0) != null, { context: O, hasClosePart: F } = pt(), C = s.useState("open"), I = s.useState("openMethod"), i = s.useState("instantType"), m = s.useState("transitionStatus"), R = s.useState("popupProps"), a = s.useState("titleElementId"), y = s.useState("descriptionElementId"), T = s.useState("modal"), E = s.useState("mounted"), x = s.useState("openChangeReason"), h = s.useState("activeTriggerElement"), M = s.useState("floatingRootContext");
  fe({
    open: C,
    ref: s.context.popupRef,
    onComplete() {
      C && s.context.onOpenChangeComplete?.(!0);
    }
  });
  const k = s.useState("disabled"), w = s.useState("openOnHover"), N = s.useState("closeDelay");
  we(M, {
    enabled: w && !k,
    closeDelay: N
  });
  function j(f) {
    return f === "touch" ? s.context.popupRef.current : !0;
  }
  const G = g === void 0 ? j : g, V = {
    open: C,
    side: r.side,
    align: r.align,
    instant: i,
    transitionStatus: m
  }, A = T !== !1 && F;
  s.useSyncedValue("focusManagerModal", A);
  const _ = n.useCallback((f) => {
    s.set("popupElement", f);
  }, [s]), H = D("div", o, {
    state: V,
    ref: [
      t,
      s.context.popupRef,
      _
    ],
    props: [
      R,
      {
        "aria-labelledby": a,
        "aria-describedby": y,
        onKeyDown(f) {
          S && $e.has(f.key) && f.stopPropagation();
        }
      },
      Ke(m),
      u
    ],
    stateAttributesMapping: dt
  });
  return /* @__PURE__ */ (0, d.jsx)(Be, {
    context: M,
    openInteractionType: I,
    modal: A,
    disabled: !E || x === "trigger-hover",
    initialFocus: G,
    returnFocus: p,
    restoreFocus: "popup",
    previousFocusableElement: ce(h) ? h : void 0,
    nextFocusableElement: s.context.triggerFocusTargetRef,
    beforeContentFocusGuardRef: s.context.beforeContentFocusGuardRef,
    children: /* @__PURE__ */ (0, d.jsx)(lt, {
      value: O,
      children: H
    })
  });
}), Ut = /* @__PURE__ */ n.forwardRef(function(o, t) {
  const { render: c, className: v, style: g, ...p } = o, { store: l } = b(), u = z(p.id);
  return Y(() => (l.set("titleElementId", u), () => {
    l.set("titleElementId", void 0);
  }), [l, u]), D("h2", o, {
    ref: t,
    props: [{ id: u }, p]
  });
}), Dt = /* @__PURE__ */ n.forwardRef(function(o, t) {
  const { render: c, className: v, style: g, ...p } = o, { store: l } = b(), u = z(p.id);
  return Y(() => (l.set("descriptionElementId", u), () => {
    l.set("descriptionElementId", void 0);
  }), [l, u]), D("p", o, {
    ref: t,
    props: [{ id: u }, p]
  });
});
export {
  Vt as a,
  Lt as i,
  Ut as n,
  Gt as o,
  Kt as r,
  Nt as s,
  Dt as t
};

//# sourceMappingURL=PopoverDescription.js.map