import {
  defaultMode,
  isLocale,
  localizedModePath,
  type Locale,
} from '@/lib/localization/config'
import { isThemePreference, themeCookie } from '@/lib/theme/config'
import { cookies } from 'next/headers'
import { notFound, redirect } from 'next/navigation'

export default async function LegacySignInPage({
  params,
}: {
  params: Promise<{ locale: string }>
}) {
  const { locale: localeValue } = await params
  if (!isLocale(localeValue)) notFound()
  const cookieStore = await cookies()
  const cookieMode = cookieStore.get(themeCookie)?.value
  const mode = isThemePreference(cookieMode) ? cookieMode : defaultMode
  redirect(localizedModePath('sign-in', localeValue as Locale, mode))
}
