import { adminListVideos, getModels } from "$lib/services";
import { error } from "@sveltejs/kit";

export async function load({ params, fetch, cookies }) {
  const token = cookies.get("session_token") || "";
  const [allVideos, models] = await Promise.all([
    adminListVideos(fetch, token).catch(() => []),
    getModels(fetch).catch(() => []),
  ]);

  const video = allVideos.find((v) => v.id === params.id);
  if (!video) throw error(404, "Video not found");

  return { video, models };
}
