import { redirect } from "next/navigation"

type HomeSearchParams = Promise<{ mail?: string | string[] }>

export default async function Home({
  searchParams,
}: {
  searchParams: HomeSearchParams
}) {
  const sp = await searchParams
  const raw = sp.mail
  const mail = Array.isArray(raw) ? raw[0] : raw
  if (mail && mail.length > 0) {
    redirect(`/mail/inbox/message/${encodeURIComponent(mail)}`)
  }
  redirect("/mail/inbox")
}
