import { isPc } from '@/utils/index'
import { getStorage, setStorage } from '@/utils/localStorage'
import { getIframeUrl } from '@/api/app'
const app = {
  state: {
    appFlag: false,
    networkPopup: false,
    isMobile: isPc(),
    language: getStorage('language') || 'en',
    currencyList: {},
    showAssets: getStorage('showAssets') === false ? false : true,
    currency: getStorage('currency') || 'USD',
    updateSymbolList: [],
    appParams: {},
    iframeUrlObj: null,
    metaInfo: {
      title: '极度证券 JDNX | 全球持牌合规股票差价合约交易平台_场外期权报价商_国际黄金_比特币合约 | 极度新星交易平台',
      description: '极度证券是由FSP、SEC、FINRA和FINTRAC联合监管，拥有RIA牌照的正规衍生品交易平台。作为创新的互联网交易商，极度以行业领先技术与服务支持，为客户提供股票差价合约、场外期权、股票期权、融资融券、黄金、比特币、货币对等金融产品和服务。',
      keywords: '港股合约, 美股合约, A股合约，场外期权，股票期权，融资融券, 股票配资, 黄金交易，比特币交易'
    },
  },
  mutations: {
    setShowAssets: (state, sign) => {
      state.showAssets = sign
      setStorage('showAssets', sign)
    },
    setLang: (state, language) => {
      state.language = language
      setStorage('language', language)
    },
    setCurrencyList: (state, list) => {
      state.currencyList = list || {}
    },
    setCurrency: (state, currency) => {
      state.currency = currency
      setStorage('currency', currency)
    },
    setUpdateSymbolList: (state, list) => {
      state.updateSymbolList = list || []
    },
    setAppParams: (state, params) => {
      state.appParams = params
    },
    setAppFlag: (state) => {
      state.appFlag = true
    },
    setNetwork: (state, b) => {
      state.networkPopup = b
    },
    setIframeUrlObj: (state, obj) => {
      state.iframeUrlObj = obj
    },
    CHANGE_META_INFO(state, metaInfo) {
      state.metaInfo = {
        title: metaInfo.title,
        description: metaInfo.description,
        keywords: metaInfo.keywords,
      };
    },
  },
  actions: {
    getIframeUrl({ commit, state }, market) {
      return new Promise((resolve, reject) => {
        getIframeUrl((Math.random() * 100000).toFixed(0)).then(res => {
          commit('setIframeUrlObj', res)
          resolve()
        }).catch(error => {
        })
      })
    },
  }
}

export default app
