import { Component, PropsWithChildren } from 'react'
import './app.scss'
import '@/context/locales/index'
import { Provider } from 'react-redux'
import store from './store/store'
import { View } from '@tarojs/components'
import GlobalModal from './components/layout/GlobalModal'
import Taro from '@tarojs/taro'

// import 'taro-ui/dist/style/index.scss'


const App: React.FC<PropsWithChildren> = ({ children }) => {
  if (process.env.TARO_ENV == 'weapp') {
    global.isDebug = Taro.getStorageSync('isDebug')

    const updateManager = Taro.getUpdateManager()
    updateManager.onUpdateReady(function () {
      Taro.showModal({
        title: '更新提示',
        content: '新版本已经准备好，是否重启应用？',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            updateManager.applyUpdate();
          }
        }
      });
    });
    updateManager.onUpdateFailed(function () {
      // 新版本下载失败
      Taro.showModal({
        title: '已经有新版本喽~',
        content: '请您删除当前小程序，到微信 “发现-小程序” 页，重新搜索打开哦~',
        showCancel: false,
      });
    });

  }
  else {
    // Taro.getStorage({
    //   key:'isDebug',
    //   success:res=>{
    //     // global.isDebug = res
    //   }
    // })
  }

  return <Provider store={store}>
    {children}
  </Provider>
}

// class App extends Component<PropsWithChildren> {

//   componentDidMount () {}

//   componentDidShow () {}

//   componentDidHide () {}

//   // this.props.children 是将要会渲染的页面
//   render () {
//     return this.props.children
//   }
// }
export default App
