'use client'

import { useLocale } from 'next-intl'
import { usePathname, useRouter } from '@/i18n/navigation'
import { routing } from '@/i18n/routing'

const LABELS: Record<string, string> = { es: 'ES', en: 'EN' }

export function LanguageSwitcher() {
  const locale = useLocale()
  const pathname = usePathname() // sin prefijo de idioma
  const router = useRouter()

  return (
    <select
      value={locale}
      onChange={(e) => router.replace(pathname, { locale: e.target.value })}
      className="rounded border border-amber-900/60 bg-[#2c1e14] px-2 py-1 text-sm"
      aria-label="language"
    >
      {routing.locales.map((loc) => (
        <option key={loc} value={loc}>
          {LABELS[loc] ?? loc.toUpperCase()}
        </option>
      ))}
    </select>
  )
}
