import { useTranslation } from "react-i18next";
import i18n, { LOCALE_KEY } from "./index";

export function useLocale() {
  const { i18n: instance } = useTranslation();

  const setLocale = (lng: "en" | "sv") => {
    localStorage.setItem(LOCALE_KEY, lng);
    void i18n.changeLanguage(lng);
  };

  return { locale: instance.language, setLocale };
}
