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 { ActionListItem } from './actions' import { BASE_ACTION_LIST, OPEN_EDITION_ACTION_LIST, SG721_UPDATABLE_ACTION_LIST, VENDING_ACTION_LIST } from './actions' export type MinterType = 'base' | 'vending' | 'openEdition' export type Sg721Type = 'updatable' | 'base' export interface ActionsComboboxProps { value: ActionListItem | null onChange: (item: ActionListItem) => void minterType?: MinterType sg721Type?: Sg721Type } export const ActionsCombobox = ({ value, onChange, minterType, sg721Type }: ActionsComboboxProps) => { const [search, setSearch] = useState('') const [ACTION_LIST, SET_ACTION_LIST] = useState(VENDING_ACTION_LIST) useEffect(() => { if (minterType === 'base') { if (sg721Type === 'updatable') SET_ACTION_LIST(BASE_ACTION_LIST.concat(SG721_UPDATABLE_ACTION_LIST)) else SET_ACTION_LIST(BASE_ACTION_LIST) } else if (minterType === 'vending') { if (sg721Type === 'updatable') SET_ACTION_LIST(VENDING_ACTION_LIST.concat(SG721_UPDATABLE_ACTION_LIST)) else SET_ACTION_LIST(VENDING_ACTION_LIST) } else if (minterType === 'openEdition') { if (sg721Type === 'updatable') SET_ACTION_LIST(OPEN_EDITION_ACTION_LIST.concat(SG721_UPDATABLE_ACTION_LIST)) else SET_ACTION_LIST(OPEN_EDITION_ACTION_LIST) } else SET_ACTION_LIST(VENDING_ACTION_LIST.concat(SG721_UPDATABLE_ACTION_LIST)) }, [minterType, sg721Type]) 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}
)}
) }