"use client"; import { CertificateStatusContent } from "@app/components/CertificateStatus"; import { Popover, PopoverAnchor, PopoverContent } from "@app/components/ui/popover"; import { useCertificate } from "@app/hooks/useCertificate"; import { cn } from "@app/lib/cn"; import { FileBadge } from "lucide-react"; import { useTranslations } from "next-intl"; import { useCallback, useEffect, useRef, useState, type ReactNode } from "react"; type ResourceAccessCertIndicatorProps = { orgId: string; domainId: string; fullDomain: string; }; function getStatusColor(status: string) { switch (status) { case "valid": return "text-green-500"; case "pending": case "requested": return "text-yellow-500"; case "expired": case "failed": return "text-red-500"; default: return "text-muted-foreground"; } } /** Compact cert icon + hover popover with full certificate status (shared by proxy and client resource tables). */ export function ResourceAccessCertIndicator({ orgId, domainId, fullDomain }: ResourceAccessCertIndicatorProps) { const t = useTranslations(); const [open, setOpen] = useState(false); const closeTimerRef = useRef | null>(null); const certificate = useCertificate({ orgId, domainId, fullDomain, autoFetch: true, polling: open, pollingInterval: 5000 }); const { cert, certLoading, certError, refreshing, fetchCert } = certificate; useEffect(() => { if (!open) return; void fetchCert(false); }, [open, fetchCert]); const clearCloseTimer = useCallback(() => { if (closeTimerRef.current != null) { clearTimeout(closeTimerRef.current); closeTimerRef.current = null; } }, []); const scheduleClose = useCallback(() => { clearCloseTimer(); closeTimerRef.current = setTimeout(() => setOpen(false), 280); }, [clearCloseTimer]); const handleEnterOpen = useCallback(() => { clearCloseTimer(); setOpen(true); }, [clearCloseTimer]); useEffect(() => { return () => clearCloseTimer(); }, [clearCloseTimer]); let triggerBody: ReactNode; if (certLoading) { triggerBody = (
); } else if (refreshing) { triggerBody = ( ); } else if (certError) { triggerBody = ( ); } else if (cert) { triggerBody = ( ); } else { triggerBody = ( ); } return ( e.preventDefault()} >

{t("certificateStatusAutoRefreshHint")}

); }