/** * External dependencies */ import { __ } from '@wordpress/i18n'; import PropTypes from 'prop-types'; import QuantitySelector from '@woocommerce/base-components/quantity-selector'; import { getCurrency } from '@woocommerce/base-utils'; import { useStoreCartItemQuantity } from '@woocommerce/base-hooks'; import { Icon, trash } from '@woocommerce/icons'; import { getSetting } from '@woocommerce/settings'; import { ProductImage, ProductLowStockBadge, ProductMetadata, ProductName, ProductPrice, ProductSaleBadge, } from '@woocommerce/base-components/cart-checkout'; /** * @typedef {import('@woocommerce/type-defs/cart').CartItem} CartItem */ /** * * @param {boolean} backOrdersAllowed Whether to allow backorders or not. * @param {number|null} lowStockAmount If present the number of stock * remaining. * * @return {number} The maximum number value for the quantity input. */ const getMaximumQuantity = ( backOrdersAllowed, lowStockAmount ) => { const maxQuantityLimit = getSetting( 'quantitySelectLimit', 99 ); if ( backOrdersAllowed || ! lowStockAmount ) { return maxQuantityLimit; } return Math.min( lowStockAmount, maxQuantityLimit ); }; /** * Cart line item table row component. */ const CartLineItemRow = ( { lineItem } ) => { const { name, summary, low_stock_remaining: lowStockRemaining = null, backorders_allowed: backOrdersAllowed, permalink, images, variation, prices, } = lineItem; const { quantity, changeQuantity, removeItem, isPending: itemQuantityDisabled, } = useStoreCartItemQuantity( lineItem ); const currency = getCurrency( prices ); const regularPrice = parseInt( prices.regular_price, 10 ) * quantity; const purchasePrice = parseInt( prices.price, 10 ) * quantity; const saleAmount = regularPrice - purchasePrice; return (