import React from 'react' import { Column, Row, Text } from '../PDF' import { View } from '@react-pdf/renderer' import type { ProductFood } from '../../pages/GenerateSales/types' import { styles } from './styles' interface ListPDFProps { data: ProductFood[] numberFormat?: (number: number) => string } export const ListPDF: React.FC = ({ data = [], numberFormat = (number: number) => number.toFixed(2) }) => { return ( {data?.map((product: ProductFood, index: number) => { const { pId, pName, ProPrice, ProQuantity, free, unitPrice, dataOptional, dataExtra } = product ?? { pId: '', pName: '', dataOptional: [], dataExtra: [], ProPrice: 0, ProQuantity: 0, free: false, unitPrice: 0 } return ( {`${index + 1}`} {pName ?? ''} {dataExtra?.map((subItem, idx) => { const subItemName = `${subItem?.quantity}x ${subItem?.extraName}` const formattedPrice = `$ ${numberFormat( subItem.newExtraPrice ?? 0 )}` const isLastItem = idx === dataExtra.length - 1 return ( {` - ${subItemName} ${formattedPrice} ${ isLastItem ? '' : ', ' }`} ) })} {Array.isArray(dataOptional) && dataOptional.length > 0 && ' - '} {dataOptional?.map((productItem, idx) => { const subItems = productItem?.ExtProductFoodsSubOptionalAll ?? [] const isLastItem = idx === dataOptional.length - 1 return subItems.map((subItem, index) => ( {`- ${subItem?.OptionalSubProName !== null ? `1x ${subItem?.OptionalSubProName}` : ''}${isLastItem ? '' : ', '}`} )) })} {ProQuantity ?? ''} {(free === true) ? 'Gratis' : `${numberFormat(unitPrice ?? 0)}` } {numberFormat(ProPrice as number)} ) })} ) }