import { convertToLocale } from "@lib/util/money" import { HttpTypes } from "@medusajs/types" import { clx } from "@modules/common/components/ui" type LineItemUnitPriceProps = { item: HttpTypes.StoreCartLineItem | HttpTypes.StoreOrderLineItem style?: "default" | "tight" currencyCode: string } const LineItemUnitPrice = ({ item, style = "default", currencyCode, }: LineItemUnitPriceProps) => { const total = item.total ?? 0 const original_total = item.original_total ?? 0 const hasReducedPrice = total < original_total const percentage_diff = Math.round( ((original_total - total) / original_total) * 100 ) return (
{hasReducedPrice && ( <>

{style === "default" && ( Original: )} {convertToLocale({ amount: original_total / item.quantity, currency_code: currencyCode, })}

{style === "default" && ( -{percentage_diff}% )} )} {convertToLocale({ amount: total / item.quantity, currency_code: currencyCode, })}
) } export default LineItemUnitPrice