import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Text } from '../../../../common'; import { useWired } from '../../../../hooks'; import { NitroInput } from '../../../../layout'; import { WiredActionBaseView } from './WiredActionBaseView'; import { CLICKED_USER_SOURCE_VALUE, WiredSourceOption, WiredSourcesSelector } from '../WiredSourcesSelector'; import { WiredHandItemField } from '../WiredHandItemField'; const USER_SOURCE_OPTIONS: WiredSourceOption[] = [ { value: 0, label: 'wiredfurni.params.sources.users.0' }, { value: 200, label: 'wiredfurni.params.sources.users.200' }, { value: 201, label: 'wiredfurni.params.sources.users.201' } ]; const BOT_SOURCE_OPTIONS: WiredSourceOption[] = [ { value: 0, label: 'wiredfurni.params.sources.users.0' }, { value: 100, label: 'wiredfurni.params.sources.users.100' }, { value: 200, label: 'wiredfurni.params.sources.users.200' }, { value: 201, label: 'wiredfurni.params.sources.users.201' } ]; const normalizeUserSource = (value: number) => ((value === CLICKED_USER_SOURCE_VALUE) || USER_SOURCE_OPTIONS.some(option => (option.value === value)) ? value : 0); const normalizeBotSource = (value: number, hasBotName = false) => (BOT_SOURCE_OPTIONS.some(option => (option.value === value)) ? value : (hasBotName ? 100 : 0)); export const WiredActionBotGiveHandItemView: FC<{}> = props => { const [ botName, setBotName ] = useState(''); const [ handItemId, setHandItemId ] = useState(-1); const { trigger = null, setStringParam = null, setIntParams = null } = useWired(); const [ userSource, setUserSource ] = useState(0); const [ botSource, setBotSource ] = useState(100); const save = () => { setStringParam((botSource === 100) ? botName : ''); setIntParams([ handItemId, userSource, botSource ]); }; useEffect(() => { const nextBotName = trigger.stringData || ''; setBotName(nextBotName); setHandItemId((trigger.intData.length > 0) ? trigger.intData[0] : 0); setUserSource((trigger.intData.length > 1) ? normalizeUserSource(trigger.intData[1]) : 0); setBotSource((trigger.intData.length > 2) ? normalizeBotSource(trigger.intData[2], (nextBotName.length > 0)) : normalizeBotSource(-1, (nextBotName.length > 0))); }, [ trigger ]); return (
setBotSource(normalizeBotSource(value, (botName.length > 0))) } /> }>
setBotSource(event.target.checked ? 100 : 0) } />
{ (botSource === 100) &&
{ LocalizeText('wiredfurni.params.bot.name') } setBotName(event.target.value) } />
}
); };