/* 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 Birthday from './Birthday'
import Activities from './Activities'

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 */
  }

  render() {
    const children = [
      <Nav0
        id="Nav0_0"
        key="Nav0_0"
        dataSource={Nav00DataSource}
        isMobile={this.state.isMobile}
      />,
      <Banner2
        id="Banner2_0_sty"
        key="Banner2_0"
        isMobile={this.state.isMobile}
      />,
      <Birthday
        id="birthday"
        key="birthday"
        isMobile={this.state.isMobile}
      />,
      <div id="sr" key="sr">
        <div>
          <h1>员工活动</h1>
          <div>
            <div>
              <img src={require('../../image/1.jpg')} />
              <h3>公司团建</h3>
              <p>趣程在每年的六七月份，面向员工组织公司团建，可以强身健体、增进员工与员工之间的感情。</p>
            </div>
            <div>
              <img src={require('../../image/IMG_0729.jpg')} />
              <h3>公司年会</h3>
              <p>自趣程创立以来，每年年底，全体员工欢聚一堂，凝聚才华与激情创作出一个个精彩的节目，增加同事之间的感情，同时激励员工在新的一年里再接再厉。</p>
            </div>
          </div>
        </div>
      </div>,
      <Activities
        id="activities"
        key="activities"
        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>
    );
  }
}
