import { Combobox, Transition } from '@headlessui/react' import clsx from 'clsx' import { FormControl } from 'components/FormControl' import { matchSorter } from 'match-sorter' import { Fragment, useEffect, useState } from 'react' import { FaChevronDown, FaInfoCircle } from 'react-icons/fa' import type { MinterType } from '../actions/Combobox' import type { QueryListItem } from './query' import { BASE_QUERY_LIST, OPEN_EDITION_QUERY_LIST, VENDING_QUERY_LIST } from './query' export interface QueryComboboxProps { value: QueryListItem | null onChange: (item: QueryListItem) => void minterType?: MinterType } export const QueryCombobox = ({ value, onChange, minterType }: QueryComboboxProps) => { const [search, setSearch] = useState('') const [QUERY_LIST, SET_QUERY_LIST] = useState(VENDING_QUERY_LIST) useEffect(() => { if (minterType === 'base') { SET_QUERY_LIST(BASE_QUERY_LIST) } else if (minterType === 'openEdition') { SET_QUERY_LIST(OPEN_EDITION_QUERY_LIST) } else { SET_QUERY_LIST(VENDING_QUERY_LIST) } }, [minterType]) const filtered = search === '' ? QUERY_LIST : matchSorter(QUERY_LIST, search, { keys: ['id', 'name', 'description'] }) return (
val?.name ?? ''} id="message-type" onChange={(event) => setSearch(event.target.value)} placeholder="Select query" /> {({ open }) => setSearch('')} as={Fragment}> {filtered.length < 1 && ( Query not found )} {filtered.map((entry) => ( clsx('flex relative flex-col py-2 px-4 space-y-1 cursor-pointer', { 'bg-stargaze-80': active }) } value={entry} > {entry.name} {entry.description} ))}
{value && (
{value.description}
)}
) }