import { redirect } from "next/navigation";

export default async function HomePage({
  searchParams
}: Readonly<{
  searchParams?: Promise<{ lang?: string; mode?: string; project?: string; routine?: string }>;
}>) {
  const params = await searchParams;
  const nextParams = new URLSearchParams();
  if (params?.lang === "en") {
    nextParams.set("lang", "en");
  }
  for (const key of ["project", "mode", "routine"] as const) {
    const value = params?.[key];
    if (value) {
      nextParams.set(key, value);
    }
  }
  const suffix = nextParams.size > 0 ? `?${nextParams.toString()}` : "";

  redirect(`/editor${suffix}`);
}
