/*
 * @Author: 赵伟
 * @Date: 2024-09-02 08:42:57
 * @Description: 可视化
 */

import IframePage, { IframePageType } from '@/components/IFramePage';
import { getExpMetricsReq } from '@/services/activeLearn';
import { to } from '@/utils/promise';
import SessionStorage from '@/utils/sessionStorage';
import { useEffect, useState } from 'react';

type ExperimentVisualResultProps = {
  metricsId?: string;
};

function ExperimentVisualResult({ metricsId }: ExperimentVisualResultProps) {
  const [aimUrl, setAimUrl] = useState('');
  useEffect(() => {
    // 获取 AIM Url
    const getExpMetrics = async (metricsId: string) => {
      const [res] = await to(getExpMetricsReq([metricsId]));
      if (res && res.data) {
        const url = res.data;
        SessionStorage.setItem(SessionStorage.aimUrlKey, url);
        setAimUrl(url);
      }
    };

    if (metricsId) {
      getExpMetrics(metricsId);
    }
  }, [metricsId]);

  return <>{aimUrl && <IframePage type={IframePageType.Aim}></IframePage>}</>;
}

export default ExperimentVisualResult;
