import type { HTMLAttributes, MouseEventHandler } from 'react' import React, { forwardRef } from 'react' import type { PriceDefinition } from '../../typings/PriceDefinition' import { Badge, Button, DiscountBadge, Icon, Label, Link, type LinkElementType, type LinkProps, ProductPrice, Rating, } from '../../' type DeliveryPromiseBadge = { label: string availability: boolean } export interface ProductCardContentProps extends HTMLAttributes { /** * ID to find this component in testing tools (e.g.: cypress, testing library, and jest). */ testId?: string /** * Specifies the product's title. */ title: string /** * Props for the link from the ProductCard component. */ linkProps?: Partial> /** * Specifies product's prices. */ price?: PriceDefinition /** * Enables an outOfStock status. */ outOfStock?: boolean /** * Specifies the OutOfStock badge's label. */ outOfStockLabel?: string /** * Specifies the Rating Value of the product. */ ratingValue?: number /** * Specifies the button's label. */ buttonLabel?: string /** * Enables a DiscountBadge to the component. */ showDiscountBadge?: boolean /** * Callback function when the button is clicked. */ onButtonClick?: MouseEventHandler /** * Specifies whether the displayed price should include taxes. */ includeTaxes?: boolean /** * Specifies the include taxes label, if taxes are included. */ includeTaxesLabel?: string /** * Specifies if the displayed product is sponsored. */ sponsored?: boolean /** * Specifies the sponsored label, if advertisement is applicable. */ sponsoredLabel?: string /** * List delivery badges, if enabled and available. */ deliveryPromiseBadges?: DeliveryPromiseBadge[] } const ProductCardContent = forwardRef( function CardContent( { testId = 'fs-product-card-content', title, linkProps, price, outOfStock, outOfStockLabel, ratingValue, showDiscountBadge, buttonLabel, onButtonClick, children, includeTaxes = false, includeTaxesLabel, sponsored = false, sponsoredLabel, deliveryPromiseBadges, ...otherProps }, ref ) { const listingPrice = price?.listPrice ? price.listPrice : 0 const sellingPrice = price?.value ? price.value : 0 return (
{sponsored && ( {sponsoredLabel} )}

{title}

{!outOfStock && ( )} {includeTaxes && ( )} {ratingValue && ( } /> )}
{showDiscountBadge && !outOfStock && ( )} {outOfStock && {outOfStockLabel}} {deliveryPromiseBadges && (
{deliveryPromiseBadges.map((badge: DeliveryPromiseBadge) => ( {badge.label} ))}
)} {onButtonClick && !outOfStock && (
)}
) } ) export default ProductCardContent