import { Tooltip, Tag ,message} from 'antd';
import { QuestionCircleOutlined } from '@ant-design/icons';
import React, { useEffect, useState } from 'react';
import { connect, SelectLang } from 'umi';
import Avatar from './AvatarDropdown';
import HeaderSearch from '../HeaderSearch';
import styles from './index.less';
import NoticeIconView from './NoticeIconView';

const ENVTagColor = {
  dev: 'orange',
  test: 'green',
  pre: '#87d068',
};

const GlobalHeaderRight = (props) => {
  const { theme, layout, dispatch, taskName,collaborative_type } = props;
  const [idInfo, setIdInfo] = useState({});
  let className = styles.right;

  if (theme === 'dark' && layout === 'top') {
    className = `${styles.right}  ${styles.dark}`;
  }

  useEffect(()=>{
    let token = window.location.search.split('token=') && window.location.search.split('token=')[1];
    dispatch({
      type: 'editReport/getIdByToken',
      payload: {
        token
      }
    }).then(res=>{
      //{result: "fail", cause: "身份验证失败，请重新点击按钮进入答题页面"}
      if(res.result === 'success'){
        let idInfo = {
          roleId:res.roleId,
          caseId:res.caseId,
          examId:res.examId,
          userId:res.userId,
          case_take_id:res.caseId + '-' + res.examId,
        }
        setIdInfo(idInfo);
      }else{
        //错误处理
        message.error(res.cause);
        console.log(res)
      }
    })
  },[])


  useEffect(() => {
    console.log('这里发请求了，right');
    if (idInfo && idInfo.examId) {
      dispatch({
        type: 'report/getTaskName',
        payload: { examId: idInfo.examId },
      });
      dispatch({
        type: 'editReport/getOsType',
        payload: { examId: idInfo.examId },
      },[idInfo.examId])
    }
  },[dispatch, idInfo.examId]);

  return (
    <div className={className}>
      {/*<NoticeIconView />*/}
      <h3>{taskName ? `${taskName} [${collaborative_type==='0' ? '智能推荐模式' : ''}]` : ''}</h3>
      {/*<h3>{taskName || ''}</h3>*/}
      {/*<SelectLang className={styles.action}/>*/}
    </div>
  );
};

export default connect(({ report, settings }) => ({
  theme: settings.navTheme,
  layout: settings.layout,
  taskName: report.taskName,
  collaborative_type: report.collaborative_type,
}))(GlobalHeaderRight);
