import * as c from "react";
import { useIsoLayoutEffect as d } 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/useIsoLayoutEffect.js";
import { AnimationFrame as u } 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/useAnimationFrame.js";
function g(t, s = !1, f = !1) {
  const [n, r] = c.useState(t && s ? "idle" : void 0), [i, a] = c.useState(t);
  return t && !i && (a(!0), r("starting")), !t && i && n !== "ending" && !f && r("ending"), !t && !i && n === "ending" && r(void 0), d(() => {
    if (!t && i && n !== "ending" && f) {
      const e = u.request(() => {
        r("ending");
      });
      return () => {
        u.cancel(e);
      };
    }
  }, [t, i, n, f]), d(() => {
    if (!t || s)
      return;
    const e = u.request(() => {
      r(void 0);
    });
    return () => {
      u.cancel(e);
    };
  }, [s, t]), d(() => {
    if (!t || !s)
      return;
    t && i && n !== "idle" && r("starting");
    const e = u.request(() => {
      r("idle");
    });
    return () => {
      u.cancel(e);
    };
  }, [s, t, i, r, n]), c.useMemo(() => ({
    mounted: i,
    setMounted: a,
    transitionStatus: n
  }), [i, n]);
}
export {
  g as useTransitionStatus
};
