import { __toESM as e } from "../_virtual/_rolldown/runtime.js";
import { getChildWorkflowsCacheKey as t, getDocumentsCacheKey as n, getWorkflowCacheKey as r } from "../hooks/query-keys.js";
import { SseClientEvents as i } from "../events/sse-client-events.js";
import { eventBus as a } from "../services/eventEmitter.js";
import "../services/index.js";
import { useStudio as o } from "./StudioProvider.js";
import { require_debounce as s } from "../frontend/studio/node_modules/lodash/debounce.js";
import { useEffect as c, useRef as l } from "react";
import { useQueryClient as u } from "@tanstack/react-query";
//#region src/providers/InvalidationEventsProvider.tsx
var d = /* @__PURE__ */ e(s(), 1), f = 300;
function p(e, t) {
	return (0, d.default)(() => {
		e.invalidateQueries({ queryKey: t });
	}, f);
}
function m() {
	let { environment: e } = o(), s = u(), d = l(/* @__PURE__ */ new Map());
	return c(() => {
		if (!e.id) return;
		let o = e.id, c = d.current;
		function l(e) {
			let t = JSON.stringify(e);
			c.has(t) || c.set(t, p(s, e)), c.get(t)();
		}
		let u = a.on(i.WORKFLOW_CREATED, (e) => {
			e.parentId && l(t(o, e.parentId));
		}), f = a.on(i.WORKFLOW_UPDATED, (e) => {
			e.id && l(r(o, e.id)), e.parentId && l(t(o, e.parentId));
		}), m = a.on(i.DOCUMENT_CREATED, (e) => {
			e.workflowId && l(n(o, e.workflowId));
		});
		return () => {
			u(), f(), m(), c.forEach((e) => e.cancel()), c.clear();
		};
	}, [s, e.id]), null;
}
//#endregion
export { m as InvalidationEventsProvider };
