import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Settings2, Copy } from "lucide-react"; import { useServiceInstances } from "../hooks/useServices"; import { resolveWidget } from "../integrations/registry"; import type { WidgetInstance } from "../types"; import { SectionCard } from "./SectionCard"; interface Props { widget: WidgetInstance; /** When provided, an edit button appears in the top-right corner (hover on desktop, always on mobile). */ onEdit?: (widgetId: string) => void; /** When provided, a copy/detach button appears next to edit (for referenced widgets). */ onCopy?: (widgetId: string) => void; } export function WidgetInstanceCard({ widget, onEdit, onCopy }: Props) { const { data: services = [] } = useServiceInstances(); const resolved = resolveWidget(widget, services); // Edit + copy buttons: always visible on mobile (below md), hover-reveal on desktop. const actionButtons = (
{onCopy ? ( ) : null} {onEdit ? ( ) : null}
); if (!resolved) { const label = widget.service_id ? `Unknown widget: ${widget.widget_kind} (service-bound)` : `Unknown widget: ${widget.widget_kind} (built-in)`; return (
{onEdit || onCopy ? actionButtons : null} {label}
); } const Component = resolved.component; return (
{onEdit || onCopy ? actionButtons : null}
); }