import React from "react";
import Route from "react-router/lib/Route";
import { message } from "antd";
import { WeaLocaleProvider } from "ecCom";
import { Provider } from 'mobx-react';
import Home from "./components/Home";
import RankScheme from "./components/postionrank/RankScheme";
import JobLevel from "./components/postionrank/JobLevel";
import JobGrade from "./components/postionrank/JobGrade";
import Sequence from "./components/sequence/Sequence";
import Group from "./components/group/Group";
import OfficeManage from "./components/office/officeManage";
import CompanyExtend from "./components/company/CompanyExtend";
import BranchNumSetting from "./components/numberSetting/branchNumSetting";
import DeptNumberSet from "./components/numberSetting/deptNumberSet";
import PostNumberSet from "./components/numberSetting/postNumberSet";
import ResourceNumberSet from "./components/numberSetting/resourceNumberSet";
import Company from "./components/company/company";
import StaffScheme from "./components/staff/StaffScheme";
import Staff from "./components/staff/Staff";
import Job from "./components/job/Job";
import JobExtend from "./components/job/JobExtend";
import Department from "./components/department/department";
import DepartmentExtendStore from "./components/department/departmentExtend";
import FieldDefined from "./components/fieldDefinedSet/FieldDefined";
import Resource from "./components/resource/resource";
import ResourceExtend from "./components/resource/ResourceExtend";
import BasicInfoImport from "./components/import";
import HrmInfoExtend from "./components/resource/HrmInfoExtend";
import NewImport from "./components/newImport"
import StaffWorkflowSet from "./components/staff/StaffWorkflowSet"
import ResourceBasicInfo from "./components/resource/ResourceBasicInfo";
import ResourceCard from "./components/resource/ResourceCard";
import ManagerDetach from "./components/detach/ManagerDetach";
import ColumnSetting from "./components/columnSetting";
import PersonnelResume from "./components/resource/PersonnelResume";
import QuickSearch from "./components/fieldDefinedSet/QuickSearch";
import QtxConfig from "./components/fieldDefinedSet/QtxConfig";

import stores from "./stores";
import "./style/index";

// 全局配置
message.config({
  duration: 0.8, // 默认持续时间为 3 秒
  maxCount: 1, // 全局最大显示数量为 3
});

// 读取系统多语言配置
let getLocaleLabel = WeaLocaleProvider.getLocaleLabel.bind(
  this,
  "HRM"
);




const Routes = (
  <Route
    key="organization"
    name="organization"
    path="organization"
    onEnter={getLocaleLabel}
    component={Home}>
    <Route key="rankscheme" path="rankscheme" component={RankScheme} />
    <Route key="joblevel" path="joblevel" component={JobLevel} />
    <Route key="jobgrade" path="jobgrade" component={JobGrade} />
    <Route key="sequence" path="sequence" component={Sequence} />
    <Route key="group" path="group" component={Group} />
    <Route key="officeManage" path="officeManage" component={OfficeManage} />
    <Route key="companyExtend" path="companyExtend/:id" component={CompanyExtend} />
    <Route
      key="branchNumSetting"
      path="branchNumSetting"
      component={BranchNumSetting}
    />
    <Route key="deptNumberSet" path="deptNumberSet" component={DeptNumberSet} />
    <Route key="postNumberSet" path="postNumberSet" component={PostNumberSet} />
    <Route
      key="resourceNumberSet"
      path="resourceNumberSet"
      component={ResourceNumberSet}
    />
    <Route key="company" path="company" component={Company} />
    <Route key="department" path="department" component={Department} />
    <Route
      key="departmentExtend"
      path="departmentExtend/:id"
      component={DepartmentExtendStore}
    />
    <Route key="staffscheme" path="staffscheme" component={StaffScheme} />
    <Route key="staff" path="staff" component={Staff} />
    <Route key="job" path="job" component={Job} />
    <Route key="jobExtend" path="jobExtend/:id" component={JobExtend} />
    <Route name="fieldDef" path="fieldDef/:type" component={FieldDefined} />
    <Route key="resource" path="resource" component={Resource} />
    <Route key="resourceExtend" path="resourceExtend/:id" component={ResourceExtend} />
    <Route key="hrmInfoExtend" path="hrmInfoExtend" component={HrmInfoExtend} />
    <Route key="basicinfoimport" path="basicinfoimport" component={BasicInfoImport} />
    <Route key="newImport" path="newImport" component={NewImport} />
    <Route key="staffWorkflowSet" path="staffWorkflowSet" component={StaffWorkflowSet} />
    <Route key="resourceBasicInfo" path="resourceBasicInfo" component={ResourceBasicInfo} />
    <Route key="resourceCard" path="resourceCard/:id" component={ResourceCard} />
    <Route key="managerDetach" path="managerDetach" component={ManagerDetach} />
    <Route key="columnSetting" path="columnSetting" component={ColumnSetting} />
    <Route key="personnelResume" path="personnelResume/:id" component={PersonnelResume} />
    <Route key="quickSearch" path="quickSearch" component={QuickSearch} />
    <Route key="qtxConfig" path="qtxConfig" component={QtxConfig} />
  </Route>
);


const { getLocaleLabelByCode } = WeaLocaleProvider;

class NetworkStrategy extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reRender: false,
    };
  }

  componentDidMount() {
    //多语言加载之后，已经 mount 的组件，需要重新 render 一次，刷新多语言配置。
    getLocaleLabelByCode('organization').then(() => this.setState({
        reRender: true
    }));
  }

  render = () => (
    <Provider
      ecId={`${(this && this.props && this.props.ecId) || ""}_Provider@is207z`}
      {...stores}>
      <Home
        ecId={`${(this && this.props && this.props.ecId) || ""}_Home@6rat5p`}>
      </Home>
    </Provider>
  );
}

module.exports = {
  Route: Routes,
  store: stores,
  com: {
    NetworkStrategy
  },
};

