import { useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { Play, Square, RotateCw, ChevronDown, ChevronRight } from "lucide-react";
import { toast } from "sonner";
import { Badge, Button, Card, Spinner, StatusDot } from "@/components/ui";
import { ContainerPorts } from "@/components/stacks/ContainerPorts";
import { containersApi, type ContainerAction } from "@/api/containers";
import { apiErrorMessage } from "@/api/client";
import type { ContainerInfo } from "@/types";
export function ContainerCard({
container,
agentId,
host,
isAdmin,
onChanged,
}: {
container: ContainerInfo;
agentId?: number;
host?: string;
isAdmin: boolean;
onChanged?: () => void;
}) {
const [open, setOpen] = useState(false);
const [busy, setBusy] = useState(false);
const running = container.state === "running";
const detail = useQuery({
queryKey: ["container", agentId ?? "local", container.id],
queryFn: () => containersApi.inspect(container.id, agentId),
enabled: open,
});
const act = async (action: ContainerAction) => {
setBusy(true);
const t = toast.loading(`${action} ${container.service}…`);
try {
await containersApi.action(container.id, action, agentId);
toast.success(`${container.service}: ${action} ok`, { id: t });
onChanged?.();
if (open) detail.refetch();
} catch (e) {
toast.error(apiErrorMessage(e), { id: t });
} finally {
setBusy(false);
}
};
return (
Mounts Environment {apiErrorMessage(detail.error)}
{detail.data.mounts.map((m, i) => (
{detail.data.env.join("\n")}