import { adminListArticles } from "$lib/services";
import { error } from "@sveltejs/kit";

export async function load({ params, fetch, cookies }) {
  const token = cookies.get("session_token") || "";
  const articles = await adminListArticles(fetch, token).catch(() => []);
  const article = articles.find((a) => a.id === params.id);
  if (!article) throw error(404, "Article not found");
  return { article };
}
