'use client' import { useState } from 'react' import { Certificate } from '@/lib/sdk/academy/types' import { downloadCertificatePDF } from '@/lib/sdk/academy/api' interface CertificateViewerProps { certificate: Certificate onClose?: () => void } export default function CertificateViewer({ certificate, onClose }: CertificateViewerProps) { const [downloading, setDownloading] = useState(false) const [error, setError] = useState(null) const handleDownloadPDF = async () => { setDownloading(true) setError(null) try { const blob = await downloadCertificatePDF(certificate.id) const url = window.URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = `zertifikat-${certificate.id.slice(0, 8)}.pdf` document.body.appendChild(a) a.click() document.body.removeChild(a) window.URL.revokeObjectURL(url) } catch (err) { setError(err instanceof Error ? err.message : 'PDF-Download fehlgeschlagen') } finally { setDownloading(false) } } const issuedDate = new Date(certificate.issuedAt).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' }) const validDate = new Date(certificate.validUntil).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' }) const isExpired = new Date(certificate.validUntil) < new Date() return (
{/* Certificate Preview */}
{/* Decorative border */}
{/* Company */}

BreakPilot Compliance

{/* Title */}

SCHULUNGSZERTIFIKAT

{/* Decorative line */}
{/* Body */}

Hiermit wird bescheinigt, dass

{certificate.userName}

die folgende Compliance-Schulung erfolgreich abgeschlossen hat:

{certificate.courseName}

{/* Score */} {certificate.score > 0 && (

Testergebnis: {certificate.score}%

)} {/* Dates */}
Abschlussdatum: {issuedDate} Gueltig bis: {validDate} {isExpired && ' (abgelaufen)'}
{/* Certificate ID */}

Zertifikats-Nr.: {certificate.id.slice(0, 12)}

{/* Actions */}
Elektronisch erstellt - ohne Unterschrift gueltig
{onClose && ( )}
{/* Error */} {error && (
{error}
)}
) }