import { useMemo } from 'react' import ReactSelect, { components } from 'react-select' import { Flex, Image } from 'theme-ui' import { assetsBucketBaseUrl } from '../../../lib/consts' import { BattlesuitData } from '../../../lib/honkai3rd/battlesuits' interface BattlesuitSelectProps { instanceId: string value: string optionIds: string[] battlesuits: BattlesuitData[] onChange: (newValue: string) => void } const BattlesuitSelect = ({ instanceId, optionIds, value, battlesuits, onChange, }: BattlesuitSelectProps) => { const battlesuitOptions = useMemo(() => { return optionIds.map((battlesuitId) => { const battlesuit = battlesuits.find((aBattlesuit) => { return aBattlesuit.id === battlesuitId }) if (battlesuit == null) { return { value: 'unknown', label: 'unknown', } } return { value: battlesuit.id, label: battlesuit.name, } }) }, [battlesuits, optionIds]) const battlesuit = battlesuits.find((battlesuit) => { return battlesuit.id === value }) return ( { if (option == null) { return } onChange(option.value) }} options={battlesuitOptions} components={{ SingleValue: (props) => { return ( <> {props.data.label} {props.children} ) }, Option: (props) => { return ( <> {props.data.label} {props.children} ) }, }} /> ) } export default BattlesuitSelect