import { useTranslation } from "react-i18next"; import type { ChatMentionAutocompleteVM, ChatMentionSuggestionVM } from "@hivegrid/view-models"; import { Button } from "~/ui/components/Button"; import { ButtonGroup } from "~/ui/components/ButtonGroup"; import { Card } from "~/ui/components/Card"; import { EmptyState } from "~/ui/components/EmptyState"; import { LoadingIndicatorSkeleton } from "~/ui/components/LoadingIndicatorSkeleton"; export function ChatMentionAutocomplete({ vm, open, loading, activeIndex, listboxId, actions, }: { readonly vm: ChatMentionAutocompleteVM | null; readonly open: boolean; readonly loading: boolean; readonly activeIndex: number; readonly listboxId: string; readonly actions: { readonly onSelect: (suggestion: ChatMentionSuggestionVM) => void; readonly onActiveIndexChange: (index: number) => void; }; }): React.JSX.Element | null { const { t } = useTranslation(); if (!open) return null; const items = vm?.groups.flatMap((group) => group.items) ?? []; let itemOffset = 0; return ( {t("chat.mention.help")}
{loading ? ( ) : items.length === 0 ? ( ) : ( {vm?.groups.map((group) => { const startIndex = itemOffset; itemOffset += group.items.length; return (
{t(group.labelKey)} {group.items.map((item, index) => { const absoluteIndex = startIndex + index; const selected = absoluteIndex === activeIndex; return ( ); })}
); })}
)}
); }