import { detectLang } from '../messages/index.js';

interface LangSwitchProps {
  /** Override target paths. [enTarget, ruTarget]. Default: ['/', '/ru'] */
  targets?: [string, string];
}

export function LangSwitch({ targets }: LangSwitchProps) {
  const lang = detectLang();
  const [enTarget, ruTarget] = targets ?? ['/', '/ru'];

  const TO: Record<string, { label: string; href: string }> = {
    en: { label: 'en', href: ruTarget },
    ru: { label: 'ru', href: enTarget },
  };
  const { label, href } = TO[lang];

  return (
    <a
      href={href}
      style={{
        position: 'absolute',
        top: '8px',
        right: '12px',
        fontSize: '0.7rem',
        fontWeight: 'bold',
        color: '#787c7e',
        textDecoration: 'none',
        border: 'none',
        background: 'none',
        cursor: 'pointer',
        fontFamily: 'monospace',
        textTransform: 'uppercase',
      }}
    >
      {label}
    </a>
  );
}
