/*
 * @Author: 赵伟
 * @Date: 2024-04-16 13:58:08
 * @Description: 主动学习实验详情
 */
import PageTitle from '@/components/PageTitle';
import { getActiveLearnInfoReq } from '@/services/activeLearn';
import { safeInvoke } from '@/utils/functional';
import { to } from '@/utils/promise';
import { useParams } from '@umijs/max';
import { useEffect, useState } from 'react';
import ActiveLearnBasic from '../components/ActiveLearnBasic';
import { ActiveLearnData } from '../types';
import styles from './index.less';

function ActiveLearnInfo() {
  const params = useParams();
  const id = safeInvoke(Number)(params.id);
  const [info, setInfo] = useState<ActiveLearnData | undefined>(undefined);

  useEffect(() => {
    // 获取详情
    const getActiveLearnInfo = async () => {
      const [res] = await to(getActiveLearnInfoReq({ id: id }));
      if (res && res.data) {
        setInfo(res.data);
      }
    };
    if (id) {
      getActiveLearnInfo();
    }
  }, [id]);

  return (
    <div className={styles['auto-ml-info']}>
      <PageTitle title="实验详情"></PageTitle>
      <div className={styles['auto-ml-info__content']}>
        <ActiveLearnBasic info={info} />
      </div>
    </div>
  );
}

export default ActiveLearnInfo;
