"use client"; import { useId } from "react"; import { useFocusTrap } from "@/hooks/use-focus-trap"; import { useTranslations } from "next-intl"; import { Button } from "@/components/ui/button"; import { ShieldCheck, X } from "lucide-react"; import type { SmimeKeyRecord, SmimePublicCert } from "@/lib/smime/types"; interface SmimeCertificateModalProps { isOpen: boolean; onClose: () => void; record: SmimeKeyRecord | SmimePublicCert | null; type: "private" | "public"; } export function SmimeCertificateModal({ isOpen, onClose, record, type: _type, }: SmimeCertificateModalProps) { const t = useTranslations("smime"); const id = useId(); const dialogRef = useFocusTrap({ isActive: isOpen, onEscape: onClose, restoreFocus: true, }); if (!isOpen || !record) return null; const isExpired = new Date(record.notAfter) < new Date(); const isNotYetValid = new Date(record.notBefore) > new Date(); const rows: { label: string; value: string }[] = [ { label: t("cert_subject"), value: record.subject ?? "" }, { label: t("cert_issuer"), value: record.issuer ?? "" }, { label: t("cert_email"), value: record.email }, { label: t("cert_validity"), value: `${new Date(record.notBefore).toLocaleDateString()} - ${new Date(record.notAfter).toLocaleDateString()}`, }, { label: t("cert_fingerprint"), value: record.fingerprint }, ]; if ("serialNumber" in record) { rows.splice(2, 0, { label: t("cert_serial"), value: record.serialNumber }); } if ("algorithm" in record) { rows.push({ label: t("cert_algorithm"), value: record.algorithm }); } if ("capabilities" in record) { const caps: string[] = []; if (record.capabilities.canSign) caps.push(t("cap_sign")); if (record.capabilities.canEncrypt) caps.push(t("cap_encrypt")); rows.push({ label: t("cert_capabilities"), value: caps.join(", ") || t("cap_none") }); } if ("source" in record) { rows.push({ label: t("cert_source"), value: record.source }); } return (

{t("certificate_details")}

{(isExpired || isNotYetValid) && (
{isExpired ? t("cert_expired") : t("cert_not_yet_valid")}
)} {rows.map(({ label, value }) => (
{label}
{value}
))}
); }