/* eslint no-undef: 0 */
/* eslint arrow-parens: 0 */
import React from 'react';
import { enquireScreen } from 'enquire-js';

import Nav0 from './Nav0';
import Banner2 from './Banner2';
import Footer1 from './Footer1';
import AboutUs from './AboutUs'
import Introduction from '../Introduce/Introduction';
import SenseOfWorth from '../About/SenseOfWorth';

import Partners from '../../components/Partners'

import {
  Nav00DataSource,
  Footer10DataSource,
} from './data.source';

import './less/antMotionStyle.less';

let isMobile;
enquireScreen((b) => {
  isMobile = b;
});

const { location = {} } = typeof window !== 'undefined' ? window : {};

export default class Home extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isMobile,
      show: !location.port, // 如果不是 dva 2.0 请删除
    };
  }

  componentDidMount() {
    // 适配手机屏幕;
    enquireScreen((b) => {
      this.setState({ isMobile: !!b });
    });
    // dva 2.0 样式在组件渲染之后动态加载，导致滚动组件不生效；线上不影响；
    /* 如果不是 dva 2.0 请删除 start */
    if (location.port) {
      // 样式 build 时间在 200-300ms 之间;
      setTimeout(() => {
        this.setState({
          show: true,
        });
      }, 500);
    }
    /* 如果不是 dva 2.0 请删除 end */
    // 预加载图片
    ["http://questnet.cn/image/trophy/a.png",
      "http://questnet.cn/image/trophy/b.png",
      "http://questnet.cn/image/trophy/c.png",
      "http://questnet.cn/image/trophy/d.png",
      "http://questnet.cn/image/trophy/e.png",
      "http://questnet.cn/image/trophy/f.png",
      "http://questnet.cn/image/trophy/g.png",
      "http://questnet.cn/image/trophy/h.png",
      "http://questnet.cn/image/trophy/i.png",
      "http://questnet.cn/image/trophy/j.png",
      "http://questnet.cn/image/trophy/k.png",
      "http://questnet.cn/image/trophy/l.png",
      "http://questnet.cn/image/trophy/m.png",
      "http://questnet.cn/image/sr/1.png",
      "http://questnet.cn/image/sr/2.png",
      "http://questnet.cn/image/sr/3.png",
      "http://questnet.cn/image/sr/4.png",
      "http://questnet.cn/image/sr/5.png",
      "http://questnet.cn/image/sr/6.png",
      "http://questnet.cn/image/sr/7.png",
      "http://questnet.cn/image/sr/8.png",
      "http://questnet.cn/image/sr/9.png",
      "http://questnet.cn/image/sr/10.png",
      "http://questnet.cn/image/sr/11.png",
      "http://questnet.cn/image/sr/12.png",
      "http://questnet.cn/image/sr/13.png",
      "http://questnet.cn/image/sr/14.png",
      "http://questnet.cn/image/sr/15.png",
      "http://questnet.cn/image/sthd/21.png",
      "http://questnet.cn/image/sthd/22.png",
      "http://questnet.cn/image/sthd/23.png",
      "http://questnet.cn/image/sthd/24.png",
      "http://questnet.cn/image/sthd/25.png",
      "http://questnet.cn/image/sthd/26.png",
      "http://questnet.cn/image/sthd/27.png",
      "http://questnet.cn/image/sthd/28.png",
      "http://questnet.cn/image/sthd/29.png",
      "http://questnet.cn/image/sthd/30.png",
      "http://questnet.cn/image/sthd/31.png",
      "http://questnet.cn/image/sthd/32.png",
      "http://questnet.cn/image/sthd/33.png",
      "http://questnet.cn/image/sthd/34.png",
      "http://questnet.cn/image/sthd/35.png"].forEach((v, idx, arr) => {
        let img = new Image();
        img.src = v;
        img.onload = () => {
          arr.successLength = (arr.successLength || 0) + 1;
          console.log(`进度：${arr.successLength / arr.length}`)
        }
      })
  }



  render() {
    const children = [
      <Nav0
        id="Nav0_0"
        key="Nav0_0"
        dataSource={Nav00DataSource}
        isMobile={this.state.isMobile}
      />,
      <Banner2
        id="Banner2_0"
        key="Banner2_0"
        // dataSource={Banner20DataSource}
        isMobile={this.state.isMobile}
      />,
      <AboutUs
        key="AboutUs11_0"
        isMobile={this.state.isMobile}
      />,
      <SenseOfWorth 
        key="SenseOfWorth12_1"
        isMobile={this.state.isMobile}
      />,
      <Introduction
        key="Introduction"
      />,
      <Partners
        id="partners1_1"
        key="partners1_1"
        isMobile={this.state.isMobile}
      />,
      <Footer1
        id="Footer1_0"
        key="Footer1_0"
        dataSource={Footer10DataSource}
        isMobile={this.state.isMobile}
      />,
    ];
    return (
      <div
        className="templates-wrapper"
        ref={(d) => {
          this.dom = d;
        }}
      >
        {/* 如果不是 dva 2.0 替换成 {children} start */}
        {this.state.show && children}
        {/* 如果不是 dva 2.0 替换成 {children} end */}
      </div>
    );
  }
}
