import { cookies } from 'next/headers'
import { MARKETPLACE_LANGUAGE_COOKIE, SHARED_LANGUAGE_COOKIE, isMarketplaceLanguage, type MarketplaceLanguage } from './i18n'

export function getMarketplaceLanguage(): MarketplaceLanguage {
  const cookieStore = cookies()
  const cookieValue =
    cookieStore.get(SHARED_LANGUAGE_COOKIE)?.value ??
    cookieStore.get(MARKETPLACE_LANGUAGE_COOKIE)?.value
  return isMarketplaceLanguage(cookieValue) ? cookieValue : 'en'
}
