import React from "react"; import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui"; import { Badge } from "@/components/ui"; import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui"; import { Button } from "@/components/ui"; import { Copy, Network, X } from "lucide-react"; import { Loader2 } from "lucide-react"; import { PortForwardDialog } from "./PortForwardDialog"; import { YamlEditor } from "./YamlEditor"; import { getPodLogsCmd } from "@/lib/tauriCommands"; import type { PodInfo } from "@/lib/tauriCommands"; interface PodDetailProps { clusterId: string; namespace: string; pod: PodInfo; onClose?: () => void; } export function PodDetail({ clusterId, namespace, pod, onClose }: PodDetailProps) { const [activeTab, setActiveTab] = React.useState("overview"); const [selectedContainer, setSelectedContainer] = React.useState(pod.containers[0] ?? ""); const [logs, setLogs] = React.useState(null); const [logsLoading, setLogsLoading] = React.useState(false); const [logsError, setLogsError] = React.useState(null); const [portForwardOpen, setPortForwardOpen] = React.useState(false); const fetchLogs = React.useCallback( async (containerName: string) => { if (!containerName) return; setLogsLoading(true); setLogsError(null); setLogs(null); try { const response = await getPodLogsCmd(clusterId, namespace, pod.name, containerName); setLogs(response.logs); } catch (err) { setLogsError(err instanceof Error ? err.message : String(err)); } finally { setLogsLoading(false); } }, [clusterId, namespace, pod.name] ); const handleTabChange = (tab: string) => { setActiveTab(tab); if (tab === "logs" && logs === null && !logsLoading && !logsError) { void fetchLogs(selectedContainer); } }; const handleContainerChange = (e: React.ChangeEvent) => { const name = e.target.value; setSelectedContainer(name); void fetchLogs(name); }; const copyLogs = () => { if (logs) void navigator.clipboard.writeText(logs); }; return (

Pod: {pod.name}

{namespace}
Overview Logs YAML
Pod Information
Name {pod.name}
Namespace {namespace}
Status {pod.status}
Ready {pod.ready}
Age {pod.age}
Containers Name {pod.containers.map((c) => ( {c} ))}
Container Logs
{pod.containers.length > 1 && ( )}
{logsLoading && (
Loading logs…
)} {logsError && (
Failed to load logs: {logsError}
)} {!logsLoading && !logsError && logs !== null && (
{logs}
)} {!logsLoading && !logsError && logs === null && ( Select a container to view logs. )}
); }