import { Alert, Box, Button, Stack, Typography } from '@mui/material';
import { useNavigate } from 'react-router-dom';
import { useAppStore } from '../store/useAppStore';
import { downloadBlob } from '../utils/fileUtils';

const DownloadStep = () => {
  const navigate = useNavigate();
  const generatedEpub = useAppStore((state) => state.generatedEpub);

  if (!generatedEpub) {
    return (
      <Stack spacing={2}>
        <Alert severity="info">Önce EPUB dosyasını oluştur.</Alert>
        <Button variant="contained" onClick={() => navigate('/epub')}>
          EPUB adımına dön
        </Button>
      </Stack>
    );
  }

  return (
    <Stack spacing={4}>
      <Box textAlign="center">
        <Typography variant="h5">EPUB hazır</Typography>
        <Typography color="text.secondary">
          Tüm OCR metinleri tek bir EPUB dosyasında toplandı.
        </Typography>
      </Box>
      <Button
        variant="contained"
        color="primary"
        onClick={() => downloadBlob(generatedEpub.url, generatedEpub.filename)}
      >
        EPUB&apos;i indir
      </Button>
      <Button variant="text" onClick={() => navigate('/')}
      >
        Baştan başla
      </Button>
    </Stack>
  );
};

export default DownloadStep;
