import { auth } from "@/auth";
import { redirect } from "next/navigation";
import { db } from "@/lib/db";
import { PipelineQueueClient } from "./PipelineQueueClient";

export const dynamic = "force-dynamic";

export default async function PipelinePage() {
  const session = await auth();
  if (!session?.user) redirect("/login");
  if (session.user.role === "CLIENT") redirect("/dashboard");

  const projects = await db.project.findMany({
    where: { status: { in: ["ACTIVE", "ON_HOLD"] } },
    select: { id: true, name: true, code: true },
    orderBy: { name: "asc" },
  });

  return <PipelineQueueClient projects={projects} />;
}
