import PropTypes from 'prop-types'
import Link from 'next/link'
import React from 'react'
import { Text } from '../../atoms'
import { APColor, PColor } from '../../../assets'
import Image from 'next/image'
import { getGlobalStyle } from '../../../utils'
import styles from './styles.module.css'
export const ProductCheckout = ({
product = {
ExtProductFoodsAll: [],
salesExtProductFoodOptional: [],
ShoppingCard: '',
cantProducts: 0,
productFood: {
ProDescuento: 0,
ProPrice: 0,
ValueDelivery: 0,
pName: ''
}
},
url = '',
nameStore,
comment = '',
handleEditProduct = (product) => { return product},
numberFormat = (number) => { return number },
handleDeleteItemShopping = (product) => { return product},
sumProduct = (ProPrice, ValueDelivery, quantity ) => { return ProPrice, ValueDelivery, quantity }
}) => {
const salesExtProductFoodOptional = product?.salesExtProductFoodOptional
return (
{nameStore}
{product.productFood?.pName ?? ''}
{comment && (
Obs: {comment}
)}
${' '}
{numberFormat(product.productFood?.ProPrice)}
Cantidad {numberFormat(product.cantProducts)}
${' '}
{numberFormat(
product.productFood?.ProDescuento || 0
)}
{product?.ExtProductFoodsAll?.map((subItem, idx) => {
const subItemName = `${subItem?.quantity}x ${subItem?.extraName}`
const isLastItem = idx === product.ExtProductFoodsAll.length - 1
return (
{subItemName}
{isLastItem ? '' : ', '}
)
})}
{Boolean(salesExtProductFoodOptional?.length > 0) && ' - '}
{salesExtProductFoodOptional?.map((productItem, idx) => {
const subItems = productItem?.ExtProductFoodsSubOptionalAll
const isLastItem = idx === subItems?.length - 1
return subItems?.map((subItem, index) => {return (
{subItem?.OptionalSubProName ? `1x ${subItem?.OptionalSubProName}` : ''}
{isLastItem ? '' : ', '}
)})
})}
Subtotal
$ {numberFormat(product.productFood?.ProPrice)}
Costo de envĂo
{product.productFood?.ValueDelivery !== null ||
0
? (
${' '}
{numberFormat(
product.productFood?.ValueDelivery
)}
)
: (
Gratis
)}
Costo Final
${' '}
{numberFormat(
sumProduct(
product.productFood?.ProPrice,
product.productFood?.ValueDelivery,
product.cantProducts
)
)}
)
}
ProductCheckout.propTypes = {
comment: PropTypes.string,
handleDeleteItemShopping: PropTypes.func,
handleEditProduct: PropTypes.func,
nameStore: PropTypes.any,
numberFormat: PropTypes.func,
product: PropTypes.shape({
ExtProductFoodsAll: PropTypes.shape({
length: PropTypes.number,
map: PropTypes.func
}),
ShoppingCard: PropTypes.any,
cantProducts: PropTypes.any,
productFood: PropTypes.shape({
ProDescuento: PropTypes.number,
ProPrice: PropTypes.any,
ValueDelivery: PropTypes.any,
pName: PropTypes.string
})
}),
sumProduct: PropTypes.func,
url: PropTypes.any
}