import { t as e } from "../../sse-D0HLjufB.js";
import { useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
//#region src/react/hooks/useSSE.ts
function a(a, o) {
	let [s, c] = i("idle"), l = r(o);
	l.current = o;
	let u = a?.url ?? null, d = a?.reconnect, f = a?.reconnectInterval, p = a?.maxRetries, m = a?.withCredentials, h = a?.allowQueryTokenAuth, g = n(() => a === null ? null : new e(a), [
		u,
		d,
		f,
		p,
		m,
		h
	]);
	return t(() => {
		if (g === null) {
			c("idle");
			return;
		}
		c("connecting");
		let e = [], t = l.current;
		if (t) for (let [n, r] of Object.entries(t)) {
			let t = g.on(n, r);
			e.push(t);
		}
		g.connect();
		let n = setInterval(() => {
			g.isConnected() ? c("open") : g.isFailed() ? c("error") : c("connecting");
		}, 200);
		return () => {
			clearInterval(n);
			for (let t of e) t();
			g.disconnect(), c("closed");
		};
	}, [g]), {
		manager: g,
		status: s
	};
}
//#endregion
export { a as useSSE };

//# sourceMappingURL=useSSE.js.map