import { getLatestMediaEngine } from "../tasks/makeMediaEngineTask.js";
import { Task } from "@lit/task";
const makeScrubVideoSegmentFetchTask = (host) => {
	return new Task(host, {
		args: () => [host.mediaEngineTask.value, host.scrubVideoSegmentIdTask.value],
		onError: (error) => {
			console.error("scrubVideoSegmentFetchTask error", error);
		},
		onComplete: (_value) => {},
		task: async (_, { signal }) => {
			const mediaEngine = await getLatestMediaEngine(host, signal);
			const segmentId = await host.scrubVideoSegmentIdTask.taskComplete;
			if (segmentId === void 0) throw new Error("Scrub segment ID is not available for video");
			const scrubRendition = mediaEngine.getScrubVideoRendition();
			if (!scrubRendition) throw new Error("No scrub rendition available");
			return mediaEngine.fetchMediaSegment(segmentId, {
				...scrubRendition,
				src: mediaEngine.src
			}, signal);
		}
	});
};
export { makeScrubVideoSegmentFetchTask };
