import { Fragment, useState } from 'react' import { Combobox, ComboboxInput, ComboboxButton, ComboboxOptions, ComboboxOption, Transition, } from '@headlessui/react' import { MagnifyingGlassIcon } from '@heroicons/react/24/solid' import { getCollectionName, CollectionId } from '@/reports/helpers/subject' import { validateNsid } from '@/lib/util' /** Collections that can be the subject of a report on a record. */ const recordCollections: CollectionId[] = [ CollectionId.Post, CollectionId.Profile, CollectionId.List, CollectionId.FeedGenerator, CollectionId.StarterPack, ] const knownCollections = recordCollections.map((id) => ({ value: id, label: getCollectionName(id), })) export function CollectionAutocomplete({ value, id, name, placeholder, onChange, className, }: { value: string | undefined id?: string name?: string placeholder?: string onChange?: (value: string | undefined) => void className?: string }) { const [query, setQuery] = useState('') const filtered = knownCollections.filter((c) => { if (!query) return true const q = query.toLowerCase() return ( c.value.toLowerCase().includes(q) || c.label.toLowerCase().includes(q) ) }) const nsidError = value ? validateNsid(value) : null return (
{/* show a space so this element maintains its height */} {nsidError ?? '\u00A0'}