import { redirect } from "next/navigation"

/** 根路径重定向到移动端首页 */
export default async function RootPage({
  searchParams,
}: {
  searchParams?: Promise<Record<string, string | string[] | undefined>>
}) {
  const resolved = await searchParams
  const params = new URLSearchParams()

  for (const [key, value] of Object.entries(resolved ?? {})) {
    if (typeof value === "string") params.set(key, value)
    else if (Array.isArray(value)) value.forEach((v) => params.append(key, v))
  }

  const qs = params.toString()
  redirect(qs ? `/view?${qs}` : "/view")
}
