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

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

export default async function VideoPage({ searchParams }: Props) {
  const query = await searchParams;
  const videoId = query?.videoId as string;
  const episodeId = query?.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} />;
}
