import { switchLanguage } from 'src/utils/i18n'
import { setBaseUrlByServerMode, setLanguage } from '../../api/api'

// action type
export const ACTION_APP_SET_TOKEN = 'APP_SET_TOKEN'
export const ACTION_APP_CLEAN_TOKEN = 'APP_SET_CLEAN_TOKEN'
export const ACTION_APP_SET_PUSH_TOKEN = 'APP_SET_PUSH_TOKEN_TOKEN'
export const ACTION_APP_SET_DEVICE = 'ACTION_APP_SET_DEVICE'
export const ACTION_APP_CLEAN_DEVICE = 'ACTION_APP_CLEAN_DEVICE'
export const ACTION_APP_SET_USER = 'ACTION_APP_SET_USER'
export const ACTION_APP_CLEAN_USER = 'ACTION_APP_CLEAN_USER'
export const ACTION_APP_SET_NOTIFICATION = 'ACTION_APP_SET_NOTIFICATION'
export const ACTION_APP_CHANGE_NOTIFICATION = 'ACTION_APP_CHANGE_NOTIFICATION'
export const ACTION_APP_SET_PROJECT_ID = 'ACTION_APP_SET_PROJECT_ID'
export const ACTION_APP_CLEAN_PROJECT_ID = 'ACTION_APP_CLEAN_PROJECT_ID'
export const ACTION_APP_SET_LANGUAGE = 'ACTION_APP_SET_LANGUAGE'
export const ACTION_APP_SET_SERVER_MODE = 'ACTION_APP_SET_SERVER_MODE'
export const ACTION_SET_POPUP_NOTIFICATION = 'ACTION_SET_POPUP_NOTIFICATION'

// action creator
export function appSetToken (token) {
  console.log('token appSetToken >>>>>>>>>>>>>>> ', token)
  return {
    type: ACTION_APP_SET_TOKEN,
    token
  }
}

export function appSetNotification (count) {
  return {
    type: ACTION_APP_SET_NOTIFICATION,
    count_noti: count
  }
}

export function appChangeNotification (notification) {
  return {
    type: ACTION_APP_CHANGE_NOTIFICATION,
    notification
  }
}

export function appCleanToken () {
  return {
    type: ACTION_APP_CLEAN_TOKEN
  }
}

export function appSetPushToken (pushToken) {
  return {
    type: ACTION_APP_SET_PUSH_TOKEN,
    pushToken
  }
}

export function appSetDevice (device) {
  return {
    type: ACTION_APP_SET_DEVICE,
    device
  }
}

export function appCleanDevice () {
  return {
    type: ACTION_APP_CLEAN_DEVICE,
  }
}

export function appSetUser (user) {
  return {
    type: ACTION_APP_SET_USER,
    user
  }
}

export function appCleanUser () {
  return {
    type: ACTION_APP_CLEAN_USER,
  }
}

export function appSetProjectID (projectId) {
  return {
    type: ACTION_APP_SET_PROJECT_ID,
    project_id: projectId
  }
}

export function appCleanProjectID () {
  return {
    type: ACTION_APP_CLEAN_PROJECT_ID,
  }
}

export function appSetLanguage (langCode) {
  switchLanguage(langCode)
  setLanguage(langCode)
  return {
    type: ACTION_APP_SET_LANGUAGE,
    lang: langCode
  }
}

export function setServerMode (mode) {
  setBaseUrlByServerMode(mode)
  return {
    type: ACTION_APP_SET_SERVER_MODE,
    mode
  }
}

export function setPopupNotification(data) {
  return {
    type: ACTION_SET_POPUP_NOTIFICATION,
    popup_notification : data
  }
}
