import { useState } from 'react' import { FileDown, Loader2, X } from 'lucide-react' import { exportarPDF, SECCIONES_EXPORTABLES } from '../../utils/exportPdf' export default function PdfExportModal({ year, onClose }) { const [seleccionadas, setSeleccionadas] = useState( SECCIONES_EXPORTABLES.map(s => s.id) ) const [generando, setGenerando] = useState(false) const [progreso, setProgreso] = useState(0) const [error, setError] = useState(null) function toggleSeccion(id) { setSeleccionadas(prev => prev.includes(id) ? prev.filter(s => s !== id) : [...prev, id] ) } function toggleTodas() { setSeleccionadas(prev => prev.length === SECCIONES_EXPORTABLES.length ? [] : SECCIONES_EXPORTABLES.map(s => s.id) ) } async function handleExportar() { if (!seleccionadas.length) return setGenerando(true) setProgreso(0) setError(null) try { await exportarPDF({ seccionesIds: SECCIONES_EXPORTABLES .map(s => s.id) .filter(id => seleccionadas.includes(id)), year, onProgress: setProgreso, }) onClose() } catch (e) { console.error(e) setError('Ocurrió un error al generar el PDF. Intentá de nuevo.') } finally { setGenerando(false) } } const todasMarcadas = seleccionadas.length === SECCIONES_EXPORTABLES.length return (
Seleccioná las secciones a incluir en el informe {year}.