import React , { useEffect , useState } from 'react';
import { Box , Long , Short , Gap } 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 Group = Loadable({
  loader: () => import("./TeamSettingGroup"),
  loading: Loading,
});
const Member = Loadable({
  loader: () => import("./TeamSettingMember"),
  loading: Loading,
});
const Common = Loadable({
  loader: () => import("./TeamSettingCommon"),
  loading: Loading,
});
const Hooks = Loadable({
  loader: () => import("./TeamSettingHooks"),
  loading: Loading,
});
export default (( props )=>{
  const pathname = props.location.pathname;
  const organizeId = props.match.params.organizeId;

  function returnActive (pathname){
    let a = 0;
    if(pathname === `/organize/${organizeId}/setting/member`){
      a = 1;
    }else if(pathname === `/organize/${organizeId}/setting/group`){
      a = 2;
    }else if(pathname === `/organize/${organizeId}/setting/hooks`){
      a = 3;
    }
    return a;
  }
  const active = returnActive(pathname);
  const array = {list:[
    {name:'基本设置',icon:"icon-base",href:`/organize/${organizeId}/setting`},
    {name:'组织成员管理',icon:"icon-zuzhichengyuan",href:`/organize/${organizeId}/setting/member`},
    {name:'组织团队管理',icon:"icon-zuzhixiangmu",href:`/organize/${organizeId}/setting/group`},
    {name:'管理web钩子',icon:"icon-zhongqingdianxinicon10",href:`/organize/${organizeId}/setting/hooks`}
  ],
    active
  }
  return(
    <Box>
      <Short>
        <Setnav header={<Title>组织设置</Title>} nav={array}></Setnav>
      </Short>
      <Long>
        <Gap>
          <Switch>
            <Route
              path="/organize/:organizeId/setting/hooks"
              render={() => (
                <Hooks {...props} />
              )}
            ></Route>
            <Route
              path="/organize/:organizeId/setting/group"
              render={() => (
                <Group {...props} />
              )}
            ></Route>
            <Route
              path="/organize/:organizeId/setting/member"
              render={() => (
                <Member {...props} />
              )}
            ></Route>
            <Route
              path="/organize/:organizeId/setting"
              render={() => (
                <Common {...props} />
              )}
            ></Route>
          </Switch>
        </Gap>
      </Long>
    </Box>
  )
})