"use client"; import { useState } from "react"; import { IconCheck, IconCopy, IconTrash, IconX } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import type { Annotation } from "@/lib/preview-inspect-bridge"; import { formatAnnotations } from "@/lib/preview-inspect-bridge"; import { copyToClipboard } from "@/lib/utils/copy-to-clipboard"; import { useTranslation } from "react-i18next"; import { t } from "@/lib/i18n"; interface AnnotationsPanelProps { annotations: Annotation[]; onRemove: (id: string) => void; onClear: () => void; } // Module-level `t` rather than a hook: this runs from render, after a locale is // active. The `tag`/`#id`/`.class` suffix is inspected DOM data, never copy. function describeAnnotation(a: Annotation): string { if (a.kind === "pin") { const el = a.element; if (!el) return t("task:annotationPin"); let suffix = ""; if (el.id) suffix = `#${el.id}`; else if (el.classes) suffix = `.${el.classes.split(/\s+/)[0]}`; return `${el.tag}${suffix}`; } const r = a.rect; return r ? t("task:annotationAreaSized", { w: Math.round(r.w), h: Math.round(r.h) }) : t("task:annotationArea"); } export function AnnotationsPanel({ annotations, onRemove, onClear }: AnnotationsPanelProps) { const { t } = useTranslation(); const [copied, setCopied] = useState(false); if (annotations.length === 0) return null; async function handleCopy() { if (await copyToClipboard(formatAnnotations(annotations))) { setCopied(true); setTimeout(() => setCopied(false), 2000); } else { console.error("AnnotationsPanel: clipboard write failed"); } } return (
{t("task:annotationCount", { count: annotations.length })}
); }