import React, { useEffect, useMemo,useState } from 'react';
import { Link } from "react-router-dom";
import { Menu, Dropdown, } from 'antd';

import './index.scss';

const { SubMenu } = Menu;

export default props => {
  const {current_user}=props;
  const main_web_site_url =localStorage.chromesetting&& JSON.parse(localStorage.chromesetting).main_web_site_url;
  const current_main_site_url =localStorage.chromesetting&& JSON.parse(localStorage.chromesetting).current_main_site_url;
  const noticeUrl =localStorage.chromesetting&& JSON.parse(localStorage.chromesetting).api_urls.notice;
  useEffect(()=>{
    sessionStorage.setItem('current_user',JSON.stringify(current_user));
  },[current_user.login]);
  

  const [current,setCurrent]=useState(JSON.parse(sessionStorage.adminRouter||'[]'));
  const [title,setTitle]=useState('');

  function  handleClick (e){
    setCurrent([e.key]);
    setTitle(e.item.props.title);
    sessionStorage.setItem( 'adminRouter',JSON.stringify([e.key]));
  };

  const projectMenu = useMemo(() => {
    return <Menu>
      <Menu.Item><a rel="noopener noreferrer" href={`${current_main_site_url}/admins`}>项目管理后台</a></Menu.Item>
    </Menu>
  });

  const taskMenu = useMemo(() => {
    return <Menu selectedKeys={current} onClick={handleClick}>
      <SubMenu title="基础数据" >
        <Menu.Item><a href={`${main_web_site_url}/admin/categories/list`}>任务领域</a></Menu.Item>
        <Menu.Item><a href={`${main_web_site_url}/admin/industries/list`}>行业信息</a></Menu.Item>
        <Menu.Item><a href={`${main_web_site_url}/admin/placements/list`}>职位信息</a></Menu.Item>
        <Menu.Item><a href={`${main_web_site_url}/admin/task_templates/list`}>需求导入模板</a></Menu.Item>
        <Menu.Item><Link to="/managements/task/agreement/content">协议签订模板</Link></Menu.Item>
        <Menu.Item><a href={`${main_web_site_url}/admin/sign_agreement_setting`}>应征投稿协议内容</a></Menu.Item>
      </SubMenu>
      <SubMenu title="代办事项" >
        <Menu.Item title="task" key="delayManage"><Link to="/managements/task/delayManage">延期任务处理</Link></Menu.Item>
        <Menu.Item title="task" key="payProof"><Link to="/managements/task/payProof">支付报酬凭证上传</Link></Menu.Item>
      </SubMenu>

      <Menu.Item title="task" key="taskAdmin"><Link to="/managements/task/taskAdmin">创客任务列表</Link></Menu.Item>
    </Menu>
  });

  const competitionMenu = useMemo(() => {
    return <Menu selectedKeys={current} onClick={handleClick} >
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/admin/competitions/list`}>竞赛列表</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/admin/competitions/region_zone_edit`}>赛区配置</a></Menu.Item>
      <Menu.Item title="competition" key="competitionReview" ><Link to="/managements/expert/competition">竞赛评审列表</Link></Menu.Item>
    </Menu>
  });

  const userMenu = useMemo(() => {
    return <Menu selectedKeys={current} onClick={handleClick}>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/users`}>用户列表</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/admin/entities`}>主体信息列表</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/users_trial`}>试用授权列表</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/auto_users_trial`}>自动授权列表</a></Menu.Item>
      <Menu.Item title="user" key={'register'}><Link to="/managements/expert/register">专家注册列表</Link></Menu.Item>
      <Menu.Item title="user" key={'expertList'}><Link to="/managements/expert/list">专家库列表</Link></Menu.Item>
    </Menu>
  });

  const forumMenu = useMemo(() => {
    return <Menu >
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/messages_list`}>帖子</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/apply_destroy_memos`}>申请删帖</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/memo_reply_list`}>回贴</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/admin/forum_sections`}>版块配置</a></Menu.Item>
    </Menu>
  });


  const checkMenu = useMemo(() => {
    return <Menu selectedKeys={current} onClick={handleClick}>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/enterprise_authentication`}>企业认证</a></Menu.Item>
      <Menu.Item title="approver" key={"taskManage1"}><Link to="/managements/task/taskManage/1">统筹任务发布审批</Link></Menu.Item>
      <Menu.Item title="approver" key={"taskManage0"}><Link to="/managements/task/taskManage/0">自主任务发布审批</Link></Menu.Item>
      <Menu.Item title="approver" key={"paperManage"}><Link to="/managements/task/paperManage">成果/评论审批</Link></Menu.Item>
      <Menu.Item title="approver" key={"paperComplain"}><Link to="/managements/task/paperComplain">成果上传申诉审批</Link></Menu.Item>
      <Menu.Item title="approver" key={"publicityComplain"}><Link to="/managements/task/publicityComplain">公示期成果申诉审批</Link></Menu.Item>
      <Menu.Item title="approver" key={"agreementManage"}><Link to="/managements/task/agreementManage">协议审批</Link></Menu.Item>
      <Menu.Item ><a rel="noopener noreferrer" href={`${main_web_site_url}/admin/tasks/report_result_tasks`}>成果举报申诉</a></Menu.Item>
      <Menu.Item title="approver" key={"proofManage"}><Link to="/managements/task/proofManage">评选佐证材料</Link></Menu.Item>
    </Menu>
  });


  const limitsMenu = useMemo(() => {
    return <Menu>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/user_admin_roles`}>权限组配置</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/managements/admin_role_permissions`}>权限操作配置</a></Menu.Item>
    </Menu>
  });


  const configMenu = useMemo(() => {
    return <Menu>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/admin/about_infos/new"`}>关于我们</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/admin/home_sections"`}>首页版块</a></Menu.Item>
      <Menu.Item><a rel="noopener noreferrer" href={`${main_web_site_url}/admin/partners`}>合作伙伴</a></Menu.Item>
    </Menu>
  });

  const noticeMenu = useMemo(() => {
    return <Menu>
      <Menu.Item><a rel="noopener noreferrer" href={`${noticeUrl}/admin/index#/`}>招标公告</a></Menu.Item>
    </Menu>
  });

  return (
    <div className="centerbox managements_menus clearfix">
      <Dropdown key={'projectMenu'} overlay={projectMenu} placement="bottomLeft">
        <div  className="drop-div">
          项目
        </div>
      </Dropdown>

      <Dropdown key={'taskMenu'} overlay={taskMenu} placement="bottomLeft">
        <div className={`${title=='task'&&'active'} drop-div`}>
          创客
        </div>
      </Dropdown>

      <Dropdown key={'competitionMenu'} overlay={competitionMenu} placement="bottomLeft">
        <div className={`${title=='competition'&&'active'} drop-div`}>竞赛</div>
      </Dropdown>

      <Dropdown key={'userMenu'} overlay={userMenu} placement="bottomLeft">
        <div className={`${title=='user'&&'active'} drop-div`}>用户</div>
      </Dropdown>

      <Dropdown key={'forumMenu'} overlay={forumMenu} placement="bottomLeft">
        <div className="drop-div">论坛交流</div>
      </Dropdown>

      <Dropdown key={'checkMenu'} overlay={checkMenu} placement="bottomLeft">
        <div className={`${title=='approver'&&'active'} drop-div`}>审批</div>
      </Dropdown>

      <Dropdown key={'limitsMenu'} overlay={limitsMenu} placement="bottomLeft">
        <div className="drop-div">权限管理</div>
      </Dropdown>

      {/* <Dropdown key={'configMenu'} overlay={configMenu} placement="bottomLeft">
        <div className="drop-div">网站配置</div>
      </Dropdown> */}

      <Dropdown key={'notice'} overlay={noticeMenu} placement="bottomLeft">
        <div className="drop-div">招标公告</div>
      </Dropdown>
    </div>
  )
}