import { notFound } from "next/navigation";

import { VideoGuideView } from "@/components/domains/video-guides";
import { DashboardData, DashboardSchema } from "@/entities/dashboard/types";
import { http } from "@/shared/api/httpClient";
import { API_ROUTES } from "@/shared/constants/api-routes";

// Force dynamic to always get fresh data
export const dynamic = "force-dynamic";

export default async function VideoGuidePage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;

  // Get fresh dashboard data without cache
  const dashboard = await http.get<DashboardData>(API_ROUTES.dashboard(), {
    cache: "no-store",
    schema: DashboardSchema,
  });

  const videoGuide = dashboard.videoGuides?.find(v => v.id === id);

  if (!videoGuide || !videoGuide.isPurchased || !videoGuide.videoLink) {
    notFound();
  }

  return (
    <VideoGuideView
      id={videoGuide.id}
      name={videoGuide.name}
      description={videoGuide.description}
      videoLink={videoGuide.videoLink}
      contentUrl={videoGuide.contentUrl}
    />
  );
}
