import { adminGetArticle, adminListUsers } from "$lib/services";
import { error } from "@sveltejs/kit";

export async function load({ params, fetch, cookies }) {
  const token = cookies.get("session_token") || "";
  const [article, modelsResult] = await Promise.all([
    adminGetArticle(params.id, fetch, token).catch(() => null),
    adminListUsers({ role: "model", limit: 200 }, fetch, token).catch(() => ({
      items: [],
      total: 0,
    })),
  ]);

  if (!article) throw error(404, "Article not found");

  return { article, authors: modelsResult.items };
}
