/*
 * @Author: 赵伟
 * @Date: 2024-04-16 13:58:08
 * @Description: 自主机器学习详情
 */
import PageTitle from '@/components/PageTitle';
import { getAutoMLInfoReq } from '@/services/autoML';
import { parseJsonText } from '@/utils';
import { safeInvoke } from '@/utils/functional';
import { to } from '@/utils/promise';
import { useParams } from '@umijs/max';
import { useEffect, useState } from 'react';
import AutoMLBasic from '../components/AutoMLBasic';
import { AutoMLData } from '../types';
import styles from './index.less';

function AutoMLInfo() {
  const params = useParams();
  const autoMLId = safeInvoke(Number)(params.id);
  const [autoMLInfo, setAutoMLInfo] = useState<AutoMLData | undefined>(undefined);

  useEffect(() => {
    // 获取自动机器学习详情
    const getAutoMLInfo = async () => {
      const [res] = await to(getAutoMLInfoReq({ id: autoMLId }));
      if (res && res.data) {
        const info = res.data;
        const param = info.param;

        setAutoMLInfo({
          ...info,
          param: undefined,
          ...parseJsonText(param),
        });
      }
    };

    if (autoMLId) {
      getAutoMLInfo();
    }
  }, [autoMLId]);

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

export default AutoMLInfo;
