import { BufferedSeekingInput } from "../BufferedSeekingInput.js";
import { EFMedia } from "../../EFMedia.js";
import { Task } from "@lit/task";
const makeScrubVideoInputTask = (host) => {
	return new Task(host, {
		args: () => [host.scrubVideoInitSegmentFetchTask.value, host.scrubVideoSegmentFetchTask.value],
		onError: (error) => {
			console.error("scrubVideoInputTask error", error);
		},
		onComplete: (_value) => {},
		task: async () => {
			const initSegment = await host.scrubVideoInitSegmentFetchTask.taskComplete;
			const segment = await host.scrubVideoSegmentFetchTask.taskComplete;
			if (!initSegment || !segment) throw new Error("Scrub init segment or segment is not available");
			const mediaEngine = await host.mediaEngineTask.taskComplete;
			const scrubRendition = mediaEngine.getScrubVideoRendition();
			const startTimeOffsetMs = scrubRendition?.startTimeOffsetMs;
			const input = new BufferedSeekingInput(await new Blob([initSegment, segment]).arrayBuffer(), {
				videoBufferSize: EFMedia.VIDEO_SAMPLE_BUFFER_SIZE,
				audioBufferSize: EFMedia.AUDIO_SAMPLE_BUFFER_SIZE,
				startTimeOffsetMs
			});
			return input;
		}
	});
};
export { makeScrubVideoInputTask };
