import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Helmet } from 'react-helmet-async'; import { RotateCw } from 'lucide-react'; import FileUploader from '@/components/shared/FileUploader'; import ProgressBar from '@/components/shared/ProgressBar'; import DownloadButton from '@/components/shared/DownloadButton'; import AdSlot from '@/components/layout/AdSlot'; import { useFileUpload } from '@/hooks/useFileUpload'; import { useTaskPolling } from '@/hooks/useTaskPolling'; import { generateToolSchema } from '@/utils/seo'; type Rotation = 90 | 180 | 270; export default function RotatePdf() { const { t } = useTranslation(); const [phase, setPhase] = useState<'upload' | 'processing' | 'done'>('upload'); const [rotation, setRotation] = useState(90); const { file, uploadProgress, isUploading, taskId, error: uploadError, selectFile, startUpload, reset, } = useFileUpload({ endpoint: '/pdf-tools/rotate', maxSizeMB: 20, acceptedTypes: ['pdf'], extraData: { rotation: rotation.toString(), pages: 'all' }, }); const { status, result, error: taskError } = useTaskPolling({ taskId, onComplete: () => setPhase('done'), onError: () => setPhase('done'), }); const handleUpload = async () => { const id = await startUpload(); if (id) setPhase('processing'); }; const handleReset = () => { reset(); setPhase('upload'); }; const rotations: { value: Rotation; label: string }[] = [ { value: 90, label: '90°' }, { value: 180, label: '180°' }, { value: 270, label: '270°' }, ]; const schema = generateToolSchema({ name: t('tools.rotatePdf.title'), description: t('tools.rotatePdf.description'), url: `${window.location.origin}/tools/rotate-pdf`, }); return ( <> {t('tools.rotatePdf.title')} — {t('common.appName')}

{t('tools.rotatePdf.title')}

{t('tools.rotatePdf.description')}

{phase === 'upload' && (
{file && !isUploading && ( <>
{rotations.map((r) => ( ))}
)}
)} {phase === 'processing' && !result && ( )} {phase === 'done' && result && result.status === 'completed' && ( )} {phase === 'done' && taskError && (

{taskError}

)}
); }