import { memo } from "react"; import type { Connection, Tag } from "../../lib/types"; import { DB_ICONS, DB_LABELS } from "../../lib/dbIcons"; import { ENV_LABELS, ENV_COLORS } from "../../lib/environment"; import { TagBadge } from "../tags/TagBadge"; import { Check, GripVertical } from "lucide-react"; import { useUiStore } from "../../stores/uiStore"; import { useDraggable } from "@dnd-kit/core"; import { CSS } from "@dnd-kit/utilities"; interface ConnectionCardProps { connection: Connection; tags: Tag[]; onTagToggle?: (id: string) => void; onOpenDbViewer?: (connectionId: string) => void; } function ConnectionCardBase({ connection, tags, onTagToggle, onOpenDbViewer, }: ConnectionCardProps) { const selectedItemIds = useUiStore((s) => s.selectedItemIds); const toggleItemSelection = useUiStore((s) => s.toggleItemSelection); const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({ id: connection.id, data: { type: "connection", connection }, }); const style: React.CSSProperties = { transform: CSS.Translate.toString(transform), opacity: isDragging ? 0.5 : 1, cursor: isDragging ? "grabbing" : "default", }; const tagMap = new Map(tags.map((t) => [t.id, t])); const cardTags = connection.tag_ids .map((id) => tagMap.get(id)) .filter(Boolean) as Tag[]; const hostLabel = connection.port ? `${connection.host}:${connection.port}` : connection.host; const isSelected = selectedItemIds.includes(connection.id); const handleClick = () => { if (selectedItemIds.length > 0) { // Something already selected — toggle this item in the selection toggleItemSelection(connection.id); } else { // Nothing selected — open the connection onOpenDbViewer?.(connection.id); } }; return (