import { LKSProductCardProps } from '../type'; import { LKSProductCardInfoTypeList, LKS_PRODUCT_CARD_CARD_LAYOUT, LKS_PRODUCT_CARD_INFO_TYPE, } from '../constants'; import clsx from 'clsx'; import { parsePrice } from '@/utils'; import { ProductItem } from '@/services/type'; const PREFIX = 'lks-product-card__products'; export const LKSProductCard = ({ products, moduleLayout, cardLayout, showInfos, pictureSize, isEdit, }: LKSProductCardProps & { isEdit?: boolean; }) => { const infos = cardLayout === LKS_PRODUCT_CARD_CARD_LAYOUT.LEFT_RIGHT ? LKSProductCardInfoTypeList : showInfos; const isEmpty = !products.length; const getInfoDisplay = (infoType: LKS_PRODUCT_CARD_INFO_TYPE) => { return infos.includes(infoType); }; const showInfo = () => { if (!infos.length) return false; return true; }; const getDiscountPrice = (product: ProductItem) => { const currency = product.currency?.currency_symbol || '$'; const price = parsePrice(product.coupon_after_price); return `${currency} ${price}`; }; const getOriginalPrice = (product: ProductItem) => { const currency = product.currency?.currency_symbol || '$'; const price = parsePrice(product.item_price); return `${currency} ${price}`; }; if (isEmpty) return null; return (
{products.map(product => ( {showInfo() && (
{getInfoDisplay(LKS_PRODUCT_CARD_INFO_TYPE.BRAND) && product.brand?.brand_en_name && (
{product.brand.brand_en_name}
)} {getInfoDisplay(LKS_PRODUCT_CARD_INFO_TYPE.CATEGORY) && product.category?.category_name && (
{product.category?.category_name}
)} {getInfoDisplay(LKS_PRODUCT_CARD_INFO_TYPE.PRODUCT_NAME) && product.item_title && (
{product.item_title}
)}
{getInfoDisplay(LKS_PRODUCT_CARD_INFO_TYPE.DISCOUNT_PRICE) && product.coupon_after_price && (
{getDiscountPrice(product)}
)} {getInfoDisplay(LKS_PRODUCT_CARD_INFO_TYPE.ORIGINAL_PRICE) && product.item_price && (
{getOriginalPrice(product)}
)}
)}
))}
); };