import { useTranslation } from "react-i18next";

import { languages } from "./languages";
import type { Language } from "./languages";

export function useLanguages(): {
  languages: Language[];
  current: Language;
  setLanguage: (key: string) => void;
} {
  const { i18n } = useTranslation();

  const current = languages.find((lang) => lang.key === i18n.language)!;

  const setLanguage = (key: string): void => {
    i18n.changeLanguage(key);
  };

  return { languages, current, setLanguage };
}
