import { useTranslation } from "react-i18next";
import { Languages } from "../translations";
import AsyncStorage from '@react-native-async-storage/async-storage'

export const useLang = () => {
    const { i18n } = useTranslation();
    const changeLanguage = (lang: Languages) => {
        i18n.changeLanguage(lang);
        AsyncStorage.setItem("lang", lang);
    }

    const toggleLanguage = () => {
        const lang = i18n.language === Languages.SPANISH ? Languages.ENGLISH : Languages.SPANISH;
        changeLanguage(lang);
    }

    return {
        changeLanguage,
        toggleLanguage
    };
}