import { ExpandLess, ExpandMore } from '@mui/icons-material' import { Box, Collapse } from '@mui/material' import type { TokenAmount } from '@openocean.finance/widget-sdk' import { isGaslessStep } from '@openocean.finance/widget-sdk' import type { MouseEventHandler } from 'react' import { useState } from 'react' import { useTranslation } from 'react-i18next' import { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js' import { HiddenUI } from '../../types/widget.js' import type { CardProps } from '../Card/Card.js' import { Card } from '../Card/Card.js' import { CardIconButton } from '../Card/CardIconButton.js' import { CardLabel, CardLabelTypography } from '../Card/CardLabel.js' import { StepActions } from '../StepActions/StepActions.js' import { Token } from '../Token/Token.js' import { TokenContainer } from './RouteCard.style.js' import { RouteCardEssentials } from './RouteCardEssentials.js' import { RouteCardEssentialsExpanded } from './RouteCardEssentialsExpanded.js' import { getMatchingLabels } from './getMatchingLabels.js' import type { RouteCardProps } from './types.js' export const RouteCard: React.FC< RouteCardProps & Omit > = ({ route, active, variant = 'default', expanded: defaulExpanded, ...other }) => { const { t } = useTranslation() const { subvariant, subvariantOptions, routeLabels, hiddenUI } = useWidgetConfig() const [cardExpanded, setCardExpanded] = useState(defaulExpanded) const handleExpand: MouseEventHandler = (e) => { e.stopPropagation() setCardExpanded((expanded) => !expanded) } const token: TokenAmount = subvariant === 'custom' && subvariantOptions?.custom !== 'deposit' ? { ...route.fromToken, amount: BigInt(route.fromAmount) } : { ...route.toToken, amount: BigInt(route.toAmount) } const impactToken: TokenAmount | undefined = subvariant !== 'custom' ? { ...route.fromToken, amount: BigInt(route.fromAmount) } : undefined const customLabels = getMatchingLabels(route, routeLabels) const mainTag = route.tags?.find( (tag) => tag === 'CHEAPEST' || tag === 'FASTEST' ) const tags: string[] = mainTag ? [mainTag] : [] const hasGaslessSupport = route.steps.some(isGaslessStep) if (hasGaslessSupport) { tags.push('GASLESS') } const cardContent = ( {subvariant !== 'refuel' && (tags.length || customLabels.length) ? ( {tags?.map((tag) => ( {t(`main.tags.${tag.toLowerCase()}` as any)} ))} {customLabels.map((label, index) => ( {label.text} ))} ) : null} {!defaulExpanded ? ( {cardExpanded ? ( ) : ( )} ) : null} {route.steps.map((step) => ( ))} ) return subvariant === 'refuel' || variant === 'cardless' ? ( cardContent ) : ( {cardContent} ) }