import { o as B } from "./rolldown-runtime.js";
import { i as J, r as Q, t as X } from "./vendor/react.js";
import { s as b, t as V, u as Y } from "./useRenderElement.js";
import { n as Z, t as W } from "./useIsoLayoutEffect.js";
import { t as $ } from "./utils.js";
import { a as ee, n as te } from "./useTransitionStatus.js";
import { t as oe } from "./useBaseUiId.js";
import { A as re, E as ne, a as se, f as N, g as ae, h as ie, l as le, m as ce, o as de, p as pe, r as ue, s as ge } from "./popupStateMapping.js";
import { n as fe, r as me, t as ve } from "./safePolygon.js";
import { S as Ce, l as Pe, t as he } from "./createBaseUIEventDetails.js";
import { i as Se, n as xe, r as ye, t as Te } from "./usePositioner.js";
import { a as we, i as Re, n as Oe, o as Ie, r as be, t as Ee } from "./useSyncedFloatingRootContext.js";
import { t as _e } from "./useFocus.js";
import { t as je } from "./FloatingPortalLite.js";
import { a as D, i as Ae, n as Me, o as He, t as Fe } from "./_shared.js";
var n = /* @__PURE__ */ B(J()), U = /* @__PURE__ */ n.createContext(void 0);
function O(t) {
  const e = n.useContext(U);
  if (e === void 0 && !t) throw new Error(b(50));
  return e;
}
var Ne = /* @__PURE__ */ B(Q()), De = {
  ...be,
  instantType: N((t) => t.instantType),
  hasViewport: N((t) => t.hasViewport)
}, ke = class z extends le {
  constructor(e) {
    super({
      ...Be(),
      ...e
    }, {
      popupRef: /* @__PURE__ */ n.createRef(),
      onOpenChange: void 0,
      onOpenChangeComplete: void 0,
      triggerElements: new ge(),
      closeDelayRef: { current: 300 }
    }, De);
  }
  setOpen = (e, o) => {
    const a = o.reason, l = a === Ce, u = e && a === "trigger-focus", m = !e && (a === "trigger-press" || a === "escape-key");
    if (o.preventUnmountOnClose = () => {
      this.set("preventUnmountingOnClose", !0);
    }, this.context.onOpenChange?.(e, o), o.isCanceled) return;
    this.state.floatingRootContext.dispatchOpenChange(e, o);
    const s = () => {
      const c = { open: e };
      u ? c.instantType = "focus" : m ? c.instantType = "dismiss" : a === "trigger-hover" && (c.instantType = void 0);
      const g = o.trigger?.id ?? null;
      (g || e) && (c.activeTriggerId = g, c.activeTriggerElement = o.trigger ?? null), this.update(c);
    };
    l ? Ne.flushSync(s) : s();
  };
  static useStore(e, o) {
    const a = Y(() => new z(o)).current, l = e ?? a, u = Ee({
      popupStore: l,
      onOpenChange: l.setOpen
    });
    return l.state.floatingRootContext = u, l;
  }
};
function Be() {
  return {
    ...Oe(),
    instantType: void 0,
    hasViewport: !1
  };
}
var p = X();
function k(t) {
  const { open: e, defaultOpen: o = !1, onOpenChange: a, onOpenChangeComplete: l, actionsRef: u, handle: m, triggerId: s, defaultTriggerId: c = null, children: g } = t, r = ke.useStore(m?.store, {
    open: o,
    openProp: e,
    activeTriggerId: c,
    triggerIdProp: s
  });
  re(() => {
    e === void 0 && r.state.open === !1 && o === !0 && r.update({
      open: !0,
      activeTriggerId: c
    });
  }), r.useControlledProp("openProp", e), r.useControlledProp("triggerIdProp", s), r.useContextCallback("onOpenChange", a), r.useContextCallback("onOpenChangeComplete", l);
  const v = r.useState("open"), C = r.select("floatingRootContext"), i = r.useState("activeTriggerId"), f = r.useState("payload");
  Re(r);
  const { forceUnmount: x } = we(v, r);
  W(() => {
    v && i == null && r.set("payload", void 0);
  }, [
    r,
    i,
    v
  ]);
  const y = n.useCallback(() => {
    r.setOpen(!1, he(Pe));
  }, [r]);
  n.useImperativeHandle(u, () => ({
    unmount: x,
    close: y
  }), [x, y]);
  const { getReferenceProps: T, getTriggerProps: P, getFloatingProps: d } = de([pe(C)]), S = n.useMemo(() => T(), [T]), w = n.useMemo(() => P(), [P]), h = n.useMemo(() => d(), [d]);
  return r.useSyncedValues({
    activeTriggerProps: S,
    inactiveTriggerProps: w,
    popupProps: h
  }), /* @__PURE__ */ (0, p.jsx)(U.Provider, {
    value: r,
    children: typeof g == "function" ? g({ payload: f }) : g
  });
}
function Ve(t) {
  return O(!0) ? /* @__PURE__ */ (0, p.jsx)(k, { ...t }) : /* @__PURE__ */ (0, p.jsx)(ie, { children: /* @__PURE__ */ (0, p.jsx)(k, { ...t }) });
}
var L = /* @__PURE__ */ n.createContext(void 0);
function We() {
  const t = n.useContext(L);
  if (t === void 0) throw new Error(b(48));
  return t;
}
var Ue = /* @__PURE__ */ n.forwardRef(function(e, o) {
  const { keepMounted: a = !1, ...l } = e;
  return O().useState("mounted") || a ? /* @__PURE__ */ (0, p.jsx)(L.Provider, {
    value: a,
    children: /* @__PURE__ */ (0, p.jsx)(je, {
      ref: o,
      ...l
    })
  }) : null;
}), ze = /* @__PURE__ */ n.forwardRef(function(e, o) {
  const { render: a, className: l, delay: u, closeDelay: m, id: s, payload: c, handle: g, style: r, ...v } = e, C = O(!0), i = g?.store ?? C;
  if (!i) throw new Error(b(89));
  const f = oe(s), x = i.useState("isTriggerActive", f), y = i.useState("isOpenedByTrigger", f), T = i.useState("floatingRootContext"), P = n.useRef(null), d = u ?? 600, S = m ?? 300, { registerTrigger: w, isMountedByThisTrigger: h } = Ie(f, P, i, { payload: c });
  W(() => {
    h && (i.context.closeDelayRef.current = S);
  }, [
    i,
    h,
    S
  ]);
  const I = fe(T, {
    mouseOnly: !0,
    move: !1,
    handleClose: ve(),
    delay: () => ({
      open: d,
      close: S
    }),
    triggerElementRef: P,
    isActiveTrigger: x,
    isClosing: () => i.select("transitionStatus") === "ending"
  }), E = _e(T, { delay: d }), _ = { open: y }, j = i.useState("triggerProps", h);
  return V("a", e, {
    state: _,
    ref: [
      o,
      w,
      P
    ],
    props: [
      I,
      E.reference,
      j,
      { id: f },
      v
    ],
    stateAttributesMapping: se
  });
}), q = /* @__PURE__ */ n.createContext(void 0);
function Le() {
  const t = n.useContext(q);
  if (t === void 0) throw new Error(b(49));
  return t;
}
var qe = /* @__PURE__ */ n.forwardRef(function(e, o) {
  const { render: a, className: l, anchor: u, positionMethod: m = "absolute", side: s = "bottom", align: c = "center", sideOffset: g = 0, alignOffset: r = 0, collisionBoundary: v = "clipping-ancestors", collisionPadding: C = 5, arrowPadding: i = 5, sticky: f = !1, disableAnchorTracking: x = !1, collisionAvoidance: y = ne, style: T, ...P } = e, d = O(), S = We(), w = ae(), h = d.useState("open"), I = d.useState("mounted"), E = d.useState("floatingRootContext"), _ = d.useState("instantType"), j = d.useState("transitionStatus"), R = ye({
    anchor: u,
    floatingRootContext: E,
    positionMethod: m,
    mounted: I,
    side: s,
    sideOffset: g,
    align: c,
    alignOffset: r,
    arrowPadding: i,
    collisionBoundary: v,
    collisionPadding: C,
    sticky: f,
    disableAnchorTracking: x,
    keepMounted: S,
    nodeId: w,
    collisionAvoidance: y,
    adaptiveOrigin: d.useState("hasViewport") ? Se : void 0
  }), G = Te(e, {
    open: h,
    side: R.side,
    align: R.align,
    anchorHidden: R.anchorHidden,
    instant: _
  }, {
    styles: R.positionerStyles,
    transitionStatus: j,
    props: P,
    refs: [o, d.useStateSetter("positionerElement")],
    hidden: !I,
    inert: !h
  });
  return /* @__PURE__ */ (0, p.jsx)(q.Provider, {
    value: R,
    children: /* @__PURE__ */ (0, p.jsx)(ce, {
      id: w,
      children: G
    })
  });
}), Ke = {
  ...ue,
  ...ee
}, Ge = /* @__PURE__ */ n.forwardRef(function(e, o) {
  const { className: a, render: l, style: u, ...m } = e, s = O(), { side: c, align: g } = Le(), r = s.useState("open"), v = s.useState("instantType"), C = s.useState("transitionStatus"), i = s.useState("popupProps"), f = s.useState("floatingRootContext");
  return te({
    open: r,
    ref: s.context.popupRef,
    onComplete() {
      r && s.context.onOpenChangeComplete?.(!0);
    }
  }), me(f, { closeDelay: Z(() => s.context.closeDelayRef.current) }), V("div", e, {
    state: {
      open: r,
      side: c,
      align: g,
      instant: v,
      transitionStatus: C
    },
    ref: [
      o,
      s.context.popupRef,
      s.useStateSetter("popupElement")
    ],
    props: [
      i,
      xe(C),
      m
    ],
    stateAttributesMapping: Ke
  });
});
function A({ ...t }) {
  return /* @__PURE__ */ (0, p.jsx)(Ve, {
    "data-slot": "hover-card",
    ...t
  });
}
A.displayName = "HoverCard";
function H({ ...t }) {
  return /* @__PURE__ */ (0, p.jsx)(ze, {
    "data-slot": "hover-card-trigger",
    ...t
  });
}
H.displayName = "HoverCard.Trigger";
function F({ className: t, side: e = "bottom", sideOffset: o = 4, align: a = "center", alignOffset: l = 4, ...u }) {
  return /* @__PURE__ */ (0, p.jsx)(Ue, {
    "data-slot": "hover-card-portal",
    children: /* @__PURE__ */ (0, p.jsx)(qe, {
      align: a,
      alignOffset: l,
      side: e,
      sideOffset: o,
      className: "isolate z-50",
      children: /* @__PURE__ */ (0, p.jsx)(Ge, {
        "data-slot": "hover-card-popup",
        className: $("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 motion-reduce:animate-none ring-foreground/10 bg-popover text-popover-foreground w-64 rounded-lg p-4 text-sm shadow-lg ring-1 duration-150 z-50 origin-(--transform-origin) outline-hidden [&>*]:delight-fade-in [&>*]:motion-reduce:!animate-none", t),
        ...u
      })
    })
  });
}
F.displayName = "HoverCard.Popup";
var Je = Object.assign(A, {
  Root: A,
  Trigger: H,
  Popup: F
}), M = {
  side: "string",
  align: "string",
  sideOffset: "number",
  alignOffset: "number"
}, K = class extends Fe {
  get propDefs() {
    return M;
  }
  static get observedAttributes() {
    return Object.keys(M).map(Me);
  }
  _renderReact() {
    const t = this._readAllProps(), e = this._getSlot("trigger"), o = this._getSlot("content") || this._getDefaultSlot();
    return n.createElement(Je, {}, e ? n.createElement(H, { render: n.createElement("span", { style: { display: "contents" } }, D(e)) }) : null, o ? n.createElement(F, {
      side: t.side || "bottom",
      align: t.align || "center",
      sideOffset: t.sideOffset || 4,
      alignOffset: t.alignOffset || 4
    }, D(o)) : null);
  }
};
Ae(K, M);
He("hf-hover-card", K);
export {
  K as HoverCardWC,
  K as default
};

//# sourceMappingURL=hf-hover-card.js.map