import { z } from "zod";
const RenderInfo = z.object({
	width: z.number().positive(),
	height: z.number().positive(),
	fps: z.number().positive(),
	durationMs: z.number().positive(),
	assets: z.object({
		efMedia: z.record(z.any()),
		efCaptions: z.array(z.string()),
		efImage: z.array(z.string())
	})
});
const getRenderInfo = async () => {
	const rootTimeGroup = document.querySelector("ef-timegroup");
	if (!rootTimeGroup) throw new Error("No ef-timegroup found");
	console.error("Waiting for media durations", rootTimeGroup);
	await rootTimeGroup.waitForMediaDurations();
	const width = rootTimeGroup.clientWidth;
	const height = rootTimeGroup.clientHeight;
	const fps = 30;
	const durationMs = Math.round(rootTimeGroup.durationMs);
	const elements = document.querySelectorAll("ef-audio, ef-video, ef-image, ef-captions");
	const assets = {
		efMedia: {},
		efCaptions: /* @__PURE__ */ new Set(),
		efImage: /* @__PURE__ */ new Set()
	};
	for (const element of elements) switch (element.tagName) {
		case "EF-AUDIO":
		case "EF-VIDEO": {
			const src = element.src;
			console.error("Processing element", element.tagName, src);
			const mediaEngine = element.mediaEngineTask.value;
			if (mediaEngine && "data" in mediaEngine) assets.efMedia[src] = mediaEngine.data;
			break;
		}
		case "EF-IMAGE": {
			const src = element.src;
			console.error("Processing element", element.tagName, src);
			assets.efImage.add(src);
			break;
		}
		case "EF-CAPTIONS": {
			const src = element.targetElement?.src;
			console.error("Processing element", element.tagName, src);
			assets.efCaptions.add(src);
			break;
		}
	}
	const renderInfo = {
		width,
		height,
		fps,
		durationMs,
		assets: {
			efMedia: assets.efMedia,
			efCaptions: Array.from(assets.efCaptions),
			efImage: Array.from(assets.efImage)
		}
	};
	console.error("Render info", renderInfo);
	return renderInfo;
};
export { RenderInfo, getRenderInfo };
