import type { FC } from 'react';
import { useEffect ,useState} from 'react';
import { Avatar, Card, Col, List, Skeleton, Row, Statistic, Descriptions, Progress, Table, Button } from 'antd';
import { Line, Radar } from '@ant-design/charts';
import { Link, history, useRequest,useParams } from 'umi';
import { PageContainer } from '@ant-design/pro-layout';
import moment from 'moment';
import EditableLinkGroup from './components/EditableLinkGroup';
import styles from './style.less';
import {getExaminationPersonApplyInfo,getPersonPaperId  } from './service';
import cookie from 'react-cookies';
import OfflineData from './components/OfflineData';

//  秒数转化为时分秒
const formatSeconds = (value) => {
  //  秒
  let second = parseInt(value)
  //  分
  let minute = 0
  //  小时
  let hour = 0
  //  天
  //  let day = 0
  //  如果秒数大于60，将秒数转换成整数
  if (second > 60) {
    //  获取分钟，除以60取整数，得到整数分钟
    minute = parseInt(second / 60)
    //  获取秒数，秒数取佘，得到整数秒数
    second = parseInt(second % 60)
    //  如果分钟大于60，将分钟转换成小时
    if (minute > 60) {
      //  获取小时，获取分钟除以60，得到整数小时
      hour = parseInt(minute / 60)
      //  获取小时后取佘的分，获取分钟除以60取佘的分
      minute = parseInt(minute % 60)
      //  如果小时大于24，将小时转换成天
      //  if (hour > 23) {
      //    //  获取天数，获取小时除以24，得到整天数
      //    day = parseInt(hour / 24)
      //    //  获取天数后取余的小时，获取小时除以24取余的小时
      //    hour = parseInt(hour % 24)
      //  }
    }
  }

  let result = '' + parseInt(second) + ' 秒 '
  if (minute > 0) {
    result = '' + parseInt(minute) + ' 分 ' + result
  }
  if (hour > 0) {
    result = '' + parseInt(hour) + ' 小时 ' + result
  }
  //  if (day > 0) {
  //    result = '' + parseInt(day) + '天' + result
  //  }
  console.log('result：', result)
  return result
}
import './index.less';
const Result = () => {
  const [examinationInfo, setExamination] = useState({});
  const [rule, setRule] = useState({});
  const [buttonText, setButtonText] = useState('返回');
  const [passInfo, setPassInfo] = useState(false);
  const [testInfo, setTestInfo] = useState({})
  const params = useParams();
  //获取考试详情
  // const a=2;
  // const b=3;
  const getPass=()=>{
    if(params.score>=params.pass_score){
    // if(a>=b){
      setPassInfo(true)
      setButtonText('返回')
    }else {
      setPassInfo(false);
      run();
    }
  };
  useEffect(() => {

    getPass()
  }, []);

  const personInfo = useRequest(() => {
      return getExaminationPersonApplyInfo({
        examination_id: params.examination_id,
        person_id: cookie.load('person_id')
      });
    },
    {
      formatResult: (result) => {
        return result;
      },
      onSuccess: (result) => {
        if (result.success) {
          console.log('result准考证',result);
          setTestInfo(result.bean);
        }
      }
    });

  const { data: chapterCourse, run } = useRequest(() => {
    return getPersonPaperId({
      examination_id:params.examination_id,
      person_id:cookie.load('person_id')
  });
  },{
    // manual:true,
    formatResult:(result)=>{
      const paper_id='1';
      if(result.paper_id===''){
      // if(paper_id===''){
        setButtonText('返回')
      }else {
        setButtonText('重新考试')
      }
    }
  });

  return (
    <div className="qualification" style={{height:window.innerHeight-300,background:'#fff',width:'100%',padding:20}}>
      <div ><span className="title" onClick={()=>{history.push('/dashboard/workplace')}}>首页</span> / 资质考试 / {params.examination_name}</div>
        <div className={"top"}>{params.examination_name}</div>
      <div style={{position:'absolute',right:'2rem',top:'3.5rem',lineHeight:'2rem'}}>
        <div>
          <span>考生姓名：</span>
          <span>{testInfo?.person_name}</span>
        </div>
        <div>
          <span>准考证号：</span>
          <span>{testInfo?.admission_number}</span>
        </div>
      </div>
        <div style={{width:'12rem',margin:'0 auto'}}>
          <div  className='condition' >
            <div className='condition-title' >考试用时：</div>
            <span className='condition-text' >{params?formatSeconds(params.time):'--分钟'}</span>
          </div>
          <div  className='condition' >
            <div className='condition-title' >得分情况：</div>
            <span className='condition-text' >{params.score}分/{params.sum_score}分</span>
          </div>
          <div  className='condition' >
            <div className='condition-title' >通过情况：</div>
            <span className='condition-text' >{passInfo?'通过':'未通过'}</span>
          </div>
        </div>
      <div className={"tip"} style={{marginBottom:'2rem'}}>
        {
          !passInfo&&buttonText==='返回'?'* 本次考试不及格学员，下次考试时间统一参加补考！':''
        }
      </div>
      <div style={{textAlign:'center'}} >
        <Button type="primary" style={{width:'10rem'}} onClick={()=>{
          if(buttonText==='返回'){
            history.push('/dashboard/workplace')
          }else {
            history.push('/dashboard/qualification/' + params.examination_id)
          }
        }}>{buttonText}</Button>
      </div>
    </div>
  );
};

export default Result;
