import { useIntl } from "react-intl";


export const useLocale = (label: string = '') => {
   
    try {
        const { messages } = useIntl() 

        let parseLabel: string = ''

        if(Array.isArray(label)){
            parseLabel = label[0].toLowerCase()
        }

        if(typeof label === "string"){
            parseLabel = label.toLowerCase()
        }

        if(typeof parseLabel !== "string") return label

        const newLabel: string = messages[parseLabel] ? messages[parseLabel].toString() : label.toString()
        return newLabel
        
    } catch {
        return label
    }
    
}

export const useCurrentLang = () => {
    try{
        const { locale } = useIntl()
        return locale
    } catch{
        return 'en'
    }
}