import React from 'react';
import {I18nManager} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';

const checkLanguageInLocalStorage = async i18n => {
  try {
    const value = await AsyncStorage.getItem('language');
    if (value !== null) {
      if (value === 'en') {
        I18nManager.forceRTL(false);
        i18n.changeLanguage('en');
      } else if (value === 'ur') {
        I18nManager.forceRTL(true);
        i18n.changeLanguage('ur');
      }
    } else {
      try {
        await AsyncStorage.setItem('language', 'ur');
      } catch (e) {
        console.log(e);
      }
    }
  } catch (e) {
    console.log(e);
  }
};

export default checkLanguageInLocalStorage;
