import { StorageService } from '../../others'
import ActionModel from '../ActionModel'
import { AppGlobalAN, } from '../constants'
import { AppGlobalStateM, } from '../../models/stateModels'
 

(async function() {
    initialState.langKey = await StorageService.getLangKey() 
})()

const initialState: AppGlobalStateM = {
    langKey: 'en',
}


var reducer = function(state = initialState, action: ActionModel): AppGlobalStateM
{
    let { payload } = action

    switch(action.type)
    {
        case AppGlobalAN.SET_STATE:
            return { ...state, ...payload }

        case AppGlobalAN.CHANGE_LANG_KEY:
            return { ...state, langKey: payload }

        case AppGlobalAN.CHANGE_VOICE_PRANK_CATEGORY:
            return { ...state, langKey: payload }
    }

    return state
}

export default reducer
