import { useState } from 'react';
import { ChevronDown, ChevronRight, ShieldCheck, ShieldAlert, Clock, Building2, Globe } from 'lucide-react';
import { CopyButton } from './CopyButton';
import type { CertificateInfo as CertInfo } from '../types';
interface CertificateInfoProps {
cert: CertInfo;
index?: number;
defaultExpanded?: boolean;
}
function formatDate(iso: string): string {
return new Date(iso).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
});
}
function InfoRow({ label, value, mono }: { label: string; value: string | number; mono?: boolean }) {
return (
{label}
{value}
);
}
export function CertificateInfoCard({ cert, index, defaultExpanded = true }: CertificateInfoProps) {
const [expanded, setExpanded] = useState(defaultExpanded);
const [showPem, setShowPem] = useState(false);
const roleLabel = !cert.isCA
? 'End Entity'
: cert.isSelfSigned
? 'Root CA'
: 'Intermediate CA';
const roleBadge = !cert.isCA ? 'badge-blue' : cert.isSelfSigned ? 'badge-amber' : 'badge-blue';
return (
{expanded && (
{/* Subject */}
Subject
{Object.entries(cert.subject).map(([key, val]) => (
))}
{/* Issuer */}
Issuer
{Object.entries(cert.issuer).map(([key, val]) => (
))}
{/* Validity */}
{/* SANs */}
{cert.sans.length > 0 && (
Subject Alternative Names ({cert.sans.length})
{cert.sans.map((san, i) => (
{san}
))}
)}
{/* Technical Details */}
{/* Key Usage */}
{(cert.keyUsage.length > 0 || cert.extKeyUsage.length > 0) && (
{cert.keyUsage.length > 0 && (
)}
{cert.extKeyUsage.length > 0 && (
)}
)}
{/* Fingerprints */}
{/* PEM */}
{showPem && (
)}
)}
);
}