import { Check, ChevronsUpDown } from 'lucide-react' import { useState } from 'react' import { Alert, AlertDescription, AlertTitle, Button, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Popover, PopoverContent, PopoverTrigger, ScrollArea, } from 'ui' import { useSchemasQuery } from '@/data/database/schemas-query' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' interface SchemaComboBoxProps { className?: string disabled?: boolean size?: 'tiny' | 'small' showError?: boolean selectedSchemas: string[] supportSelectAll?: boolean excludedSchemas?: string[] onSelectSchemas: (schemas: string[]) => void label: string } export const SchemaComboBox = ({ className, disabled = false, size = 'tiny', showError = true, selectedSchemas = [], excludedSchemas = [], label, onSelectSchemas, }: SchemaComboBoxProps) => { const [open, setOpen] = useState(false) const { data: project } = useSelectedProjectQuery() const { data, isPending: isSchemasLoading, isSuccess: isSchemasSuccess, isError: isSchemasError, error: schemasError, refetch: refetchSchemas, } = useSchemasQuery({ projectRef: project?.ref, connectionString: project?.connectionString, }) const schemas = (data || []) .filter((schema) => !excludedSchemas.includes(schema.name)) .sort((a, b) => a.name.localeCompare(b.name)) const toggleSchema = (schema: string) => { if (selectedSchemas.includes(schema)) { onSelectSchemas(selectedSchemas.filter((s) => s !== schema)) } else { const newSelectedSchemas = [...selectedSchemas, schema].sort((a, b) => a.localeCompare(b)) onSelectSchemas(newSelectedSchemas) } } return (