import { cookies } from 'next/headers'
import { SHARED_LANGUAGE_COOKIE, isCarplaceLanguage, type CarplaceLanguage } from './i18n'

export async function getCarplaceLanguage(): Promise<CarplaceLanguage> {
  const cookieValue = (await cookies()).get(SHARED_LANGUAGE_COOKIE)?.value
  return isCarplaceLanguage(cookieValue) ? cookieValue : 'en'
}
