import V 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/formatErrorMessage.js";
import * as c from "react";
import { useTooltipRootContext as H } from "../root/TooltipRootContext.js";
import { triggerOpenStateMapping as _ } from "../../utils/popupStateMapping.js";
import { useRenderElement as j } from "../../utils/useRenderElement.js";
import { useBaseUiId as k } from "../../utils/useBaseUiId.js";
import { useTooltipProviderContext as U } from "../provider/TooltipProviderContext.js";
import { OPEN_DELAY as W } from "../utils/constants.js";
import { useDelayGroup as F } from "../../floating-ui-react/components/FloatingDelayGroup.js";
import { useHoverReferenceInteraction as G } from "../../floating-ui-react/hooks/useHoverReferenceInteraction.js";
import { safePolygon as L } from "../../floating-ui-react/safePolygon.js";
import { useTriggerDataForwarding as Y } from "../../utils/popups/popupStoreUtils.js";
const q = /* @__PURE__ */ c.forwardRef(function(u, b) {
  const {
    className: J,
    render: K,
    handle: s,
    payload: h,
    disabled: v,
    delay: d,
    closeDelay: g,
    id: D,
    ...P
  } = u, R = H(!0), e = (s == null ? void 0 : s.store) ?? R;
  if (!e)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: <Tooltip.Trigger> must be either used within a <Tooltip.Root> component or provided with a handle." : V(82));
  const o = k(D), E = e.useState("isTriggerActive", o), i = e.useState("isOpenedByTrigger", o), m = e.useState("floatingRootContext"), n = c.useRef(null), f = d ?? W, T = g ?? 0, {
    registerTrigger: S,
    isMountedByThisTrigger: C
  } = Y(o, n, e, {
    payload: h,
    closeDelay: T
  }), a = U(), {
    delayRef: t,
    isInstantPhase: O,
    hasProvider: y
  } = F(m, {
    open: i
  });
  e.useSyncedValue("isInstantPhase", O);
  const x = e.useState("disabled"), A = v ?? x, M = e.useState("trackCursorAxis"), N = e.useState("disableHoverablePopup"), w = G(m, {
    enabled: !A,
    mouseOnly: !0,
    move: !1,
    handleClose: !N && M !== "both" ? L() : null,
    restMs() {
      const l = a == null ? void 0 : a.delay, r = typeof t.current == "object" ? t.current.open : void 0;
      let p = f;
      return y && (r !== 0 ? p = d ?? l ?? f : p = 0), p;
    },
    delay() {
      const l = typeof t.current == "object" ? t.current.close : void 0;
      let r = T;
      return g == null && y && (r = l), {
        close: r
      };
    },
    triggerElementRef: n,
    isActiveTrigger: E
  }), I = c.useMemo(() => ({
    open: i
  }), [i]), B = e.useState("triggerProps", C);
  return j("button", u, {
    state: I,
    ref: [b, S, n],
    props: [w, B, {
      id: o
    }, P],
    stateAttributesMapping: _
  });
});
process.env.NODE_ENV !== "production" && (q.displayName = "TooltipTrigger");
export {
  q as TooltipTrigger
};
