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

export async function load({ params, fetch, cookies }) {
  const token = cookies.get("session_token") || "";
  const [video, modelsResult] = await Promise.all([
    adminGetVideo(params.id, fetch, token).catch(() => null),
    getModels({}, fetch).catch(() => ({ items: [], total: 0 })),
  ]);

  if (!video) throw error(404, "Video not found");

  return { video, models: modelsResult.items };
}
