import { useApiHost } from "@/api"; import { useCameraFriendlyName } from "@/hooks/use-camera-friendly-name"; import { useTranslation } from "react-i18next"; import useSWR from "swr"; import { LuX, LuExternalLink } from "react-icons/lu"; import { Button } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import ActivityIndicator from "@/components/indicators/activity-indicator"; import { cn } from "@/lib/utils"; import { getTranslatedLabel } from "@/utils/i18n"; type ChatAttachmentChipProps = { eventId: string; mode: "composer" | "bubble"; onRemove?: () => void; }; /** * Small horizontal chip rendering an event as an "attachment": a thumbnail, * a friendly label like "Person on driveway", an optional remove X (composer * mode), and an external-link icon that opens the event in Explore. */ export function ChatAttachmentChip({ eventId, mode, onRemove, }: ChatAttachmentChipProps) { const apiHost = useApiHost(); const { t } = useTranslation(["views/chat"]); const { data: eventData } = useSWR<{ label: string; camera: string }[]>( `event_ids?ids=${eventId}`, ); const evt = eventData?.[0]; const cameraName = useCameraFriendlyName(evt?.camera); const displayLabel = evt ? t("attachment_chip_label", { label: getTranslatedLabel(evt.label), camera: cameraName, }) : eventId; return (
{ (e.currentTarget as HTMLImageElement).style.visibility = "hidden"; }} />
{evt ? ( {displayLabel} ) : ( )} e.stopPropagation()} aria-label={t("open_in_explore")} > {t("open_in_explore")} {mode === "composer" && onRemove && ( )}
); }