import { Progress, Button } from 'antd'

import { downloadFile } from '@components/factory'

export const ReportCreationNotify = ({ progressData }) => (
  <>
    <Progress percent={ Number(progressData.progress?.toFixed(2)) } />
    <br/>
    <span>{progressData.operation} стр {progressData.currentPage} из {progressData.totalPages}</span>
    {progressData.file && (
      <Button
        type={'link'}
        onClick={() => {downloadFile(progressData.file)}}
        download={progressData.file.name}
      >
        {progressData.file.name}
      </Button>
    )}
  </>
)

ReportCreationNotify.defaultProps = {
  progressData: {
    progress: 0.0,
    operation: 'Создание отчета',
    currentPage: 0,
    totalPages: 0,
    file: null
  }
}
