import React, { memo, useCallback, } from 'react'; import classNames from 'classnames'; import Spottable from '@enact/spotlight/Spottable'; import { $L } from '../../utils/helperMethods'; import { SpotlightIds } from '../../utils/SpotlightIds'; import css from './TItemCard.module.less'; const SpottableComponent = Spottable("li"); const TYPE_VERTICAL = "vertical"; const TYPE_HORIZONTAL = "horizontal"; const SOLD_OUT_STRING = "SOLD OUT"; const TOP_STRING = "TOP"; export default memo(function TItemCard({ children, imageAlt, imageSource, isBestSeller = false, onCardClick, priceInfo, productId, productName, rank, soldoutFlag, type = TYPE_VERTICAL, ...rest }) { const handleClick = useCallback( (productId) => { onCardClick && onCardClick(productId); }, [onCardClick, productId] ); const parsePriceInfo = useCallback( (priceInfo) => { const priceParts = priceInfo .split("|") .filter((part) => part !== "N") .map((item) => item.trim()); let originalPrice, discountedPrice, discountRate; if (priceParts.length === 4) { [originalPrice, discountedPrice, , discountRate] = priceParts; } else if (priceParts.length === 2) { [originalPrice, discountedPrice] = priceParts; discountRate = null; } else { originalPrice = null; discountedPrice = null; discountRate = null; } return { originalPrice, discountedPrice, discountRate }; }, [priceInfo] ); const { originalPrice, discountedPrice, discountRate } = parsePriceInfo(priceInfo); return ( handleClick(productId)} spotlightId={SpotlightIds.TITEM_CARD + productId} >
{imageAlt} {discountRate && {discountRate}} {soldoutFlag && soldoutFlag === "Y" &&
{$L(SOLD_OUT_STRING)}
}

{productName}

{discountRate ? discountedPrice : originalPrice} {discountRate && {originalPrice}}

{isBestSeller && rank && (
{$L(TOP_STRING)} {rank}
)}
); });