import type { PreviewAnnotationPayload } from "@t3tools/contracts"; import { Frame, MousePointerClick, Paintbrush, PenLine, X } from "lucide-react"; import type { ReactNode } from "react"; import type { ComposerImageAttachment } from "~/composerDraftStore"; import { formatElementContextLabel, normalizeElementContextSelection } from "~/lib/elementContext"; import { cn } from "~/lib/utils"; import { Button } from "../ui/button"; import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; interface ComposerPreviewAnnotationCardsProps { annotations: ReadonlyArray; images: ReadonlyArray; onRemove: (annotationId: string) => void; onExpandImage: (imageId: string) => void; className?: string; } function TargetStat(props: { icon: ReactNode; count: number; label: string }) { const tooltipText = `${props.count} ${props.label}${props.count === 1 ? "" : "s"}`; return ( {props.icon} {props.count} } /> {tooltipText} ); } export function ComposerPreviewAnnotationCards({ annotations, images, onRemove, onExpandImage, className, }: ComposerPreviewAnnotationCardsProps) { if (annotations.length === 0) return null; const imagesById = new Map(images.map((image) => [image.id, image])); return (
{annotations.map((annotation) => { const image = imagesById.get(annotation.id); const elementLabels = annotation.elements.flatMap((target) => { const context = normalizeElementContextSelection(target.element); return context ? [{ id: target.id, label: formatElementContextLabel(context) }] : []; }); return (
{image?.previewUrl ? ( ) : ( )}
{annotation.comment.trim() ? (

{annotation.comment.trim()}

) : null}
{elementLabels.length > 0 ? (
{elementLabels.slice(0, 2).map(({ id, label }) => ( {label} ))} {elementLabels.length > 2 ? ( +{elementLabels.length - 2} ) : null}
) : null}
{annotation.elements.length > 0 ? ( } count={annotation.elements.length} label="element" /> ) : null} {annotation.regions.length > 0 ? ( } count={annotation.regions.length} label="region" /> ) : null} {annotation.strokes.length > 0 ? ( } count={annotation.strokes.length} label="drawing" /> ) : null} {annotation.styleChanges.length > 0 ? ( } count={annotation.styleChanges.length} label="style change" /> ) : null}
); })}
); }