'use client'
import Image from '@/framework/image'
import { Select, Group, Text } from '@pikku/mantine/core'
import { useParams, usePathname, useRouter } from '@/framework/navigation'
import { LANGUAGES } from '@/config'
import { useI18n } from '@/context/i18n-provider'
export default function LanguageSelector() {
const t = useI18n()
const params = useParams<{ lang?: string }>()
const pathname = usePathname()
const router = useRouter()
// Extract lang from params or pathname (for routes like /en/legal/imprint)
const lang = params.lang || pathname.split('/')[1]
const selectedLanguage = LANGUAGES.find(language => language.value === lang)!
const switchLanguage = (to: string | null) => {
if (to && to !== lang) {
// Store language preference in cookie
document.cookie = `NEXT_LOCALE=${to}; path=/; max-age=31536000; SameSite=Lax`
// Create new path with updated language
const newPath = pathname.replace(`/${lang}`, `/${to}`)
// Navigate to new language
router.push(newPath)
router.refresh()
}
}
return (
}
renderOption={({ option }) => {
const language = LANGUAGES.find(lang => lang.value === option.value)
if (language) {
return (
{t(`language.${language.value}` as any)}
)
}
}}
/>
)
}