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

function HyperparameterInfo() {
  const params = useParams();
  const hyperparameterId = safeInvoke(Number)(params.id);
  const [hyperparameterInfo, setHyperparameterInfo] = useState<HyperParameterData | undefined>(
    undefined,
  );

  // 获取详情
  const getHyperparameterInfo = useCallback(async () => {
    const [res] = await to(getRayInfoReq({ id: hyperparameterId }));
    if (res && res.data) {
      setHyperparameterInfo(res.data);
    }
  }, [hyperparameterId]);

  useEffect(() => {
    if (hyperparameterId) {
      getHyperparameterInfo();
    }
  }, [hyperparameterId, getHyperparameterInfo]);

  return (
    <div className={styles['hyper-parameter-info']}>
      <PageTitle title="实验详情"></PageTitle>
      <div className={styles['hyper-parameter-info__content']}>
        <HyperParameterBasic info={hyperparameterInfo} />
      </div>
    </div>
  );
}

export default HyperparameterInfo;
