'use client'
import React from 'react'
import type { Certificate } from '@/lib/sdk/academy/types'
// =============================================================================
// CERTIFICATE ROW
// =============================================================================
function CertificateRow({ cert }: { cert: Certificate }) {
const now = new Date()
const validUntil = new Date(cert.validUntil)
const daysLeft = Math.ceil((validUntil.getTime() - now.getTime()) / (1000 * 60 * 60 * 24))
const isExpired = daysLeft <= 0
const isExpiringSoon = daysLeft > 0 && daysLeft <= 30
return (
| {cert.userName} |
{cert.courseName} |
{new Date(cert.issuedAt).toLocaleDateString('de-DE')} |
{validUntil.toLocaleDateString('de-DE')} |
{isExpired ? (
Abgelaufen
) : isExpiringSoon ? (
Laeuft bald ab
) : (
Gueltig
)}
|
{cert.pdfUrl ? (
PDF Download
) : (
Nicht verfuegbar
)}
|
)
}
// =============================================================================
// CERTIFICATES TAB
// =============================================================================
export function CertificatesTab({
certificates,
certSearch,
onSearchChange
}: {
certificates: Certificate[]
certSearch: string
onSearchChange: (s: string) => void
}) {
const now = new Date()
const total = certificates.length
const valid = certificates.filter(c => new Date(c.validUntil) > now).length
const expired = certificates.filter(c => new Date(c.validUntil) <= now).length
return (
{/* Stats */}
{/* Search */}
onSearchChange(e.target.value)}
className="w-full px-4 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-purple-500 focus:border-purple-500"
/>
{/* Table */}
{certificates.length === 0 ? (
Noch keine Zertifikate ausgestellt
Zertifikate werden automatisch nach Kursabschluss generiert.
) : (
| Mitarbeiter |
Kurs |
Ausgestellt am |
Gueltig bis |
Status |
Aktionen |
{certificates
.filter(c =>
!certSearch ||
c.userName.toLowerCase().includes(certSearch.toLowerCase()) ||
c.courseName.toLowerCase().includes(certSearch.toLowerCase())
)
.map(cert => )
}
)}
)
}