import { NextResponse } from "next/server";
import { getProjectConfigs, getScreenshots } from "@/lib/autobuilder";

export const dynamic = "force-dynamic";

export async function GET(
  _req: Request,
  { params }: { params: Promise<{ id: string }> }
) {
  const { id } = await params;
  const configs = await getProjectConfigs();
  const cfg = configs.find((c) => c.name === id);
  if (!cfg) return NextResponse.json({ error: "Project not found" }, { status: 404 });

  const screenshots = await getScreenshots(cfg.autobuilderDir, cfg.dir);
  return NextResponse.json(screenshots);
}
