import type { VideoSegment } from "../types/lecture";

const preloadedSegments = new Set<string>();

export function preloadVideoSegment(segment: VideoSegment) {
  if (typeof document === "undefined" || preloadedSegments.has(segment.id)) {
    return;
  }

  const video = document.createElement("video");
  video.preload = "metadata";
  video.src = segment.src;
  preloadedSegments.add(segment.id);
}

export function preloadVideoSegments(segments: VideoSegment[]) {
  segments.forEach((segment) => {
    preloadVideoSegment(segment);
  });
}
