<template>
  <div id="app">
    <keep-alive include="Layout,Mine,MinePage|Layout,Initiate,UserInitiate|Layout,Initiate,Founder">
      <router-view v-if="!cabilityChecked"></router-view>
      <app-wait v-else-if="cabilityChecked === 2" />
      <app-res v-else-if="cabilityChecked === 3" :type="type" :res="res" :text="text" />
      <app-error v-else-if="cabilityChecked === 4" />
      <van-loading v-else class="w-full h-full flex items-center justify-center bg-app-drak-1" type="spinner" />
    </keep-alive>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import { mapState } from 'vuex'
import { Loading } from 'vant'
import { getCurrentBTYAddress } from '@/utils/bridge'  // 币钱包环境
// import { test } from '@/constants/test'  // 本地测试
// import {routes} from '@/router/index'
// import { permissionList } from '@/constants/permission'
Vue.use(Loading)
export default Vue.extend({
  components: { 
    'app-wait': () => import('@/components/Wait.vue'),
    'app-res': () => import('@/components/Result.vue'),
    'app-error': () => import('@/views/Error.vue')
  },
  name: 'Home',
  data(){
    return{
      // cabilityChecked: this.$store.getters['app/loadingStatus']
    }
  },
  computed: {
    cabilityChecked() {
      return this.$store.state.app.loading
    },
    ...mapState({
        isLoading: state => (state as any).app.loading
    }),
    type() {
      return this.$store.state.app.type
    },
    res() {
      return this.$store.state.app.res
    },
    text() {
      return this.$store.state.app.text1
    }
  },
  async mounted() {
    // this.$store.commit('app/SET_ADDRESS', test.addr)
    getCurrentBTYAddress('',(res: any) => {
      console.log('res', res)
      this.$store.commit('app/SET_ADDRESS', res)
      // const _routes = routes[0].children as NavItem[]
      // if (permissionList.indexOf(res) > -1) {
        // _routes[2].meta.text = '发起活动'
      // }
      // console.log(_routes)
    })
    
    // window.onresize = function () {
    //   const ua = navigator.userAgent;
    //   const isAndroid = /android|Android/i.test(ua); //android终端
    //   if(!isAndroid) {
    //     console.log('resize')
    //     if ((document.activeElement as any).tagName == "INPUT" || (document.activeElement as any).tagName == "TEXTAREA") {
    //       setTimeout(function () {
    //         const top = (document.activeElement as any).getBoundingClientRect().top;
    //         console.log('top',top)
    //         window.scrollTo(0,top);
    //       }, 0);
    //     }
    //   }
    // }
    // const config ={
    //   url: 'https://mainnet.infura.io/v3/',
    //   id:'ab632ac39b8d4aff98d65429af748550'
    // }
    // let a = ETH_PROVIDER(config)
    // const fee = await a.provider.eth.getBalance('0xfc55a938a349dc526a4d633a8395a82ca661820f')
    // console.log(fee);
    // this.appReady()
  },
  methods:{
    appReady(){
      
      // web3.ready,
      // Vue.prototype.$ETHweb3 = ETH_PROVIDER('b186ce03905e4f759fb7243fac5fc0df')
      // db.ready,
      // this.cabilityChecked = true
    }
  },
});
</script>
