import { redirect } from "next/navigation";

export const dynamic = "force-dynamic";

type RootPortfolioProjectsPageProps = {
  searchParams?: {
    category?: string;
    status?: "all" | "draft" | "published";
    success?: string;
    error?: string;
  };
};

export default async function RootPortfolioProjectsPage({
  searchParams,
}: RootPortfolioProjectsPageProps) {
  const params = new URLSearchParams();

  if (searchParams?.category) {
    params.set("category", searchParams.category);
  }

  if (searchParams?.status) {
    params.set("status", searchParams.status);
  }

  if (searchParams?.success) {
    params.set("success", searchParams.success);
  }

  if (searchParams?.error) {
    params.set("error", searchParams.error);
  }

  redirect(params.toString() ? `/root/portfolio?${params.toString()}` : "/root/portfolio");
}
