import { notFound } from "next/navigation";
import { fetchVideoContent } from "@/lib/data";
import VideoPlayerUI from "../../../src/components/VideoDetailUI/VideoDetailsUi";

type Props = {
  params: { slug: string[] };
  searchParams: { [key: string]: string | string[] | undefined };
};

export default async function VideoPage({ params, searchParams }: Props) {
  const videoId = searchParams?.videoId as string;
  const episodeId = searchParams?.episodeId as string;

  if (!videoId && !episodeId) {
    console.error("[DEBUG] Neither videoId nor episodeId provided");
    notFound();
  }

  const videoData = await fetchVideoContent(videoId, episodeId);

  if (!videoData) {
    console.error("[DEBUG] No video data returned, calling notFound()");
    notFound();
  }

  return <VideoPlayerUI data={videoData} />;
}
