import { FC, HTMLProps, memo, useMemo } from 'react' import { EnrichedEntity } from '../../../src/types' import styles from './EntitySpan.module.css' import { RecipeSpan } from '../Recipe/Recipe' import { LeftClickIcon } from '../../icons/LeftClickIcon' import cx from 'classnames' import { EntityIcon } from '../EntityIcon/EntityIcon' import { useFactories } from '../../contexts/FactoryProvider' import { I18n } from '../../shared/I18n/I18n' interface Props extends Omit, 'value'> { value: EnrichedEntity | string state?: 'base' | 'produced' | 'unknown' leftClickText?: string rightClickText?: string simpleStyle?: boolean className?: string } const EntitySpanBase: FC = ({ className, value, state, leftClickText, rightClickText, simpleStyle, ...rest }) => { const { findFactory } = useFactories() const entity = useMemo(() => { return typeof value === 'object' ? value : findFactory(value) ?? { usedBy: [], href: value, name: value, image: value, recipe: undefined } }, [findFactory, value]) return ( {/* eslint-disable-next-line @next/next/no-img-element */} {entity.name} {entity.recipe && ( <> > )} {entity.usedBy?.length ? ( <> {entity.usedBy.map(used => ( ))} > ) : null} {(leftClickText || rightClickText) && ( <> {leftClickText && ( {' '} {leftClickText} )} {rightClickText && ( {' '} {rightClickText} )} > )} ) } export const EntitySpan = memo(EntitySpanBase)