import InfoGroup from '@/components/InfoGroup';
import { downloadCommonFile, MimeType } from '@/utils/downloadfile';
import { Button } from 'antd';
import styles from './index.less';

type ExperimentResultProps = {
  fileUrl?: string;
  modelPath?: string;
};

function ExperimentResult({ fileUrl, modelPath }: ExperimentResultProps) {
  return (
    <div className={styles['experiment-result']}>
      <InfoGroup title="数据选择查看" width="100%">
        {fileUrl && (
          <div>
            <Button
              type="primary"
              onClick={() => {
                const fileName = 'data.json';
                let url = fileUrl;
                if (process.env.NODE_ENV === 'development') {
                  url = fileUrl.replace('172.168.15.197:31213', 'localhost:8000');
                }
                downloadCommonFile(url, MimeType.JSON, fileName);
              }}
            >
              数据选择下载
            </Button>
          </div>
        )}
      </InfoGroup>
      <InfoGroup title="模型下载" style={{ margin: '16px 0' }}>
        {modelPath && (
          <div>
            <Button
              type="primary"
              onClick={() => {
                window.location.href = modelPath;
              }}
            >
              模型下载
            </Button>
          </div>
        )}
      </InfoGroup>
    </div>
  );
}

export default ExperimentResult;
