import React, { Suspense } from 'react';
import ReactDOM from 'react-dom';
import antd from 'antd-mobile';
antd;

import './_reset.less';

import { HashRouter } from 'react-router-dom';
import PageLoading from '@/components/Page/PageLoading';
import {RouteList} from './route';


if(MOCK){
  let mock = require('@/mock');
  mock;
}

window.appLog=(txt)=>{
  console.log(txt);
}

/* eslint-disable */

if(BUILD_ENV!='prod'){
  let VConsole =  require('vconsole');
  const vConsole = new VConsole();
  setTimeout(() => {
    vConsole.setSwitchPosition(70, 10);
  }, 2000);
}

if(BUILD_ENV){
  window.appLog(`代码环境类型：${BUILD_ENV}`);
}
if (VERSION_HASH) {
  window.appLog(`VERSION_HASH：${VERSION_HASH}`);
}
window.appLog(`log init`);
window.appLog(`${location.href}`);
window.appLog(`ua:${navigator.userAgent}`);
window.appLog(`safe top-bottom:${getComputedStyle(document.documentElement).getPropertyValue("--safeTop")}-${getComputedStyle(document.documentElement).getPropertyValue("--safeBottom")}`);

/* eslint-enable */



// 处理移动端输入框聚焦后没有正确弹起
// window.addEventListener("resize", function() {
//   // window.appLog(`resizeHeight:${window.screen.height},${window.screen.availHeight},${document.body.clientHeight},${document.documentElement.clientHeight }`);
//   if (document.activeElement) {
//     if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
//       if (document.activeElement.scrollIntoViewIfNeeded) {
//         window.setTimeout(function() {
//           document.activeElement.scrollIntoViewIfNeeded();
//         }, 0);
//       }
//     }
//   }
// });

window.onInputBlur=()=>{
  setTimeout(() => {
    const currentPosition = document.documentElement.scrollTop || document.body.scrollTop||0;
    window.scrollTo(0, currentPosition); 
  }, 100);
}

const BasicRoute = () => {
  return (
  <HashRouter>
    <Suspense fallback={<PageLoading />}>
      {RouteList}
    </Suspense>
  </HashRouter>
  );
}

ReactDOM.render(<BasicRoute />, document.getElementById('main-view'));
