import { useMemo, useState } from "react" import { Link } from "react-router-dom" import { Globe, RefreshCw, FileText } from "lucide-react" import type { GatewayInfo, HealthStatus } from "@/types" import { useGatewayReload, useCaddyfile } from "@/services/api/hooks" import { HealthBadge } from "./HealthBadge" interface GatewayPanelProps { gateway: GatewayInfo statuses: HealthStatus[] } export function GatewayPanel({ gateway, statuses }: GatewayPanelProps) { const statusMap = new Map(statuses.map((s) => [s.id, s])) const { mutate: reload, isPending: reloading } = useGatewayReload() const [showCaddyfile, setShowCaddyfile] = useState(false) const { data: caddyfileData } = useCaddyfile(showCaddyfile) const multiNode = useMemo(() => { const nodes = new Set(gateway.routes.map((r) => r.node)) return nodes.size > 1 }, [gateway.routes]) return (
{/* Header */}

Gateway

{gateway.hostname} · port {gateway.port} · {gateway.routes.length} route{gateway.routes.length !== 1 ? "s" : ""}
{/* Route table */} {gateway.routes.length > 0 && ( {multiNode && ( )} {gateway.routes.map((route) => { const health = statusMap.get(route.component) return ( {multiNode && ( )} ) })}
Path Component PortNodeHealth
{route.path} {route.component} {route.target_port} {route.node} {health ? ( ) : ( )}
)} {gateway.routes.length === 0 && (

No proxy routes configured.

)} {/* Caddyfile viewer */} {showCaddyfile && caddyfileData && (
            {caddyfileData.content}
          
)}
) }