import { Check, ChevronsUpDown, Loader2, Plus } from 'lucide-react' import { useEffect, useState } from 'react' import { ControllerRenderProps } from 'react-hook-form' import { Button, cn, Command_Shadcn_, CommandEmpty_Shadcn_, CommandGroup_Shadcn_, CommandInput_Shadcn_, CommandItem_Shadcn_, CommandList_Shadcn_, CommandSeparator_Shadcn_, Popover_Shadcn_, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, ScrollArea, } from 'ui' interface PublicationsComboBoxProps { publications: string[] isLoadingPublications: boolean isLoadingCheck: boolean onNewPublicationClick: () => void field: ControllerRenderProps } export const PublicationsComboBox = ({ publications, isLoadingPublications, isLoadingCheck, onNewPublicationClick, field, }: PublicationsComboBoxProps) => { const [dropdownOpen, setDropdownOpen] = useState(false) const [selectedPublication, setSelectedPublication] = useState(field?.value || '') const [searchTerm, setSearchTerm] = useState('') function handlePublicationSelect(pub: string) { setSelectedPublication(pub) setDropdownOpen(false) field.onChange(pub) } useEffect(() => { setSelectedPublication(field?.value || '') }, [field?.value]) return ( { setDropdownOpen(open) if (!open && field?.onBlur) { field.onBlur() } }} > {isLoadingPublications ? (
Loading...
) : ( 'No publications found' )}
{publications.length === 0 && (

No publications available

)} 7 ? 'h-[210px]' : ''}> {publications.map((pub) => ( { handlePublicationSelect(pub) }} onClick={() => { handlePublicationSelect(pub) }} > {pub} {selectedPublication === pub && ( )} ))}

New publication

) }