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 { MintRule } from '../creation/ImageUploadDetails' import type { ActionListItem } from './actions' import { BY_KEY_ACTION_LIST, BY_KEYS_ACTION_LIST, BY_MINTER_ACTION_LIST } from './actions' export interface ActionsComboboxProps { value: ActionListItem | null onChange: (item: ActionListItem) => void mintRule?: MintRule } export const ActionsCombobox = ({ value, onChange, mintRule }: ActionsComboboxProps) => { const [search, setSearch] = useState('') const [ACTION_LIST, SET_ACTION_LIST] = useState(BY_KEY_ACTION_LIST) useEffect(() => { if (mintRule === 'by_keys') { SET_ACTION_LIST(BY_KEYS_ACTION_LIST) } else if (mintRule === 'by_minter') { SET_ACTION_LIST(BY_MINTER_ACTION_LIST) } else { SET_ACTION_LIST(BY_KEY_ACTION_LIST) } }, [mintRule]) const filtered = search === '' ? ACTION_LIST : matchSorter(ACTION_LIST, search, { keys: ['id', 'name', 'description'] }) return (
val?.name ?? ''} id="message-type" onChange={(event) => setSearch(event.target.value)} placeholder="Select action" /> {({ open }) => setSearch('')} as={Fragment}> {filtered.length < 1 && ( Action 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}
)}
) }