import React , { useState } from 'react';
import { Box , Long , Short , Gap , WhiteBack } from '../../Component/layout';
import Title from '../../Component/Title';
import Setnav from '../../Component/Setnav';

import { Route, Switch } from "react-router-dom";
import Loadable from "react-loadable";
import Loading from "../../../Loading";

const Common = Loadable({
  loader: () => import("./SettingCommon"),
  loading: Loading,
});
const Member = Loadable({
  loader: () => import("./Setting/GroupMemberSetting"),
  loading: Loading,
});
const Project = Loadable({
  loader: () => import("./Setting/GroupProjectSetting"),
  loading: Loading,
});
export default (props)=>{
  const pathname = props.location.pathname;
  const OIdentifier = props.match.params.OIdentifier;
  const groupId = props.match.params.groupId;
  
  function returnActive (pathname){
    let a = 0;
    if(pathname === `/${OIdentifier}/teams/${groupId}/setting/member`){
      a = 1;
    }else if(pathname === `/${OIdentifier}/teams/${groupId}/setting/project`){
      a = 2;
    }
    return a;
  }
  const active = returnActive(pathname);
  const array = {list:[
    {name:'基本设置',icon:"icon-base",href:`/${OIdentifier}/teams/${groupId}/setting`},
    {name:'团队成员管理',icon:"icon-zuzhichengyuan",href:`/${OIdentifier}/teams/${groupId}/setting/member`},
    {name:'团队项目管理',icon:"icon-zuzhixiangmu",href:`/${OIdentifier}/teams/${groupId}/setting/project`},
  ],
    active
  }
  return(
    <Box>
      <Short>
        <Setnav header={<Title>团队设置</Title>} nav={array}></Setnav>
      </Short>
      <Long>
        <Gap>
          <WhiteBack style={{border:'1px solid #eee'}}>
            <Switch>
              <Route
                path="/:OIdentifier/teams/:groupId/setting/project"
                render={() => (
                  <Project {...props} />
                )}
              ></Route>
              <Route
                path="/:OIdentifier/teams/:groupId/setting/member"
                render={() => (
                  <Member {...props} />
                )}
              ></Route>
              <Route
                path="/:OIdentifier/teams/:groupId/setting"
                render={() => (
                  <Common {...props} />
                )}
              ></Route>
            </Switch>
          </WhiteBack>
        </Gap>
      </Long>
    </Box>
  )
}