import { createFileRoute, useParams } from '@tanstack/react-router' import { FileText, Download, RefreshCcw, ExternalLink, CheckCircle2, Clock, FileJson, } from 'lucide-react' import { useCallback, useEffect, useState } from 'react' import { Button } from '@/components/ui/button' import { Card, CardContent } from '@/components/ui/card' import { fetchPlanPdf } from '@/data/api/document.api' export const Route = createFileRoute('/planes/$planId/_detalle/documento')({ component: RouteComponent, }) function RouteComponent() { const { planId } = useParams({ from: '/planes/$planId/_detalle/documento' }) const [pdfUrl, setPdfUrl] = useState(null) const [isLoading, setIsLoading] = useState(true) const loadPdfPreview = useCallback(async () => { try { setIsLoading(true) const pdfBlob = await fetchPlanPdf({ plan_estudio_id: planId }) const url = window.URL.createObjectURL(pdfBlob) // Limpiar URL anterior si existe para evitar fugas de memoria if (pdfUrl) window.URL.revokeObjectURL(pdfUrl) setPdfUrl(url) } catch (error) { console.error('Error cargando preview:', error) } finally { setIsLoading(false) } }, [planId]) useEffect(() => { loadPdfPreview() return () => { if (pdfUrl) window.URL.revokeObjectURL(pdfUrl) } }, [loadPdfPreview]) const handleDownloadPdf = async () => { try { const pdfBlob = await fetchPlanPdf({ plan_estudio_id: planId, }) const url = window.URL.createObjectURL(pdfBlob) const link = document.createElement('a') link.href = url link.download = 'plan_estudios.pdf' document.body.appendChild(link) link.click() link.remove() window.URL.revokeObjectURL(url) } catch (error) { console.error(error) alert('No se pudo generar el PDF') } } return (
{/* HEADER DE ACCIONES */}

Documento del Plan

Vista previa y descarga del documento oficial

{/* TARJETAS DE ESTADO */}
} label="Estado" value="Generado" /> } label="Última generación" value="28 Ene 2024, 11:30" /> } label="Versión" value="v1.2" />
{/* CONTENEDOR DEL DOCUMENTO (Visor) */} {/* CONTENEDOR DEL VISOR REAL */}
Preview_Documento.pdf
{pdfUrl && ( )}
{isLoading ? (

Generando vista previa del PDF...

) : pdfUrl ? ( /* 3. VISOR DE PDF REAL */