'use client' import Image from 'next/image' import React from 'react' import { Button, Column, Icon, Row, Tag, Text } from '../../atoms' import { getGlobalStyle, numberFormat } from './../../../utils/index' import type { IButton, CardProductSimpleProps } from './types' import { formatProductData } from './utils' import { QuantityButtonFloat } from '../../molecules/QuantityButtonFloat' import styles from './styles.module.css' import { PercentBadge } from '../../molecules' export const MemoCardProductSimple: React.FC = ({ del = false, edit = false, fileInputRef = null, free = false, accept = [], index = 0, decrement = true, increment = true, handleFree, height, pId, pName = '', ProDescription = '', ProDescuento = 0, ProPrice = 0, ProQuantity = 0, sum = false, tag = { tag: '' }, ValueDelivery = 0, ProImage = '/images/dish-image-placeholder.png', dataExtra = [] as Array<{ extraPrice: number, extraName: string }>, dataOptional = [] as Array<{ ExtProductFoodsSubOptionalAll: Array<{ OptionalSubProName: string }> }>, dispatch = (_p0: { type: string, payload: { value: string, name: string, index: number, id: any } }) => { }, handleDecrement = () => { }, handleDelete = () => { }, handleFreeProducts = () => { }, handleIncrement = () => { }, onClick = () => { }, onFileInputChange = () => { }, onTargetClick = () => { }, handleEdit = () => { } }) => { // HANDLERS const handleDown = (event?: React.MouseEvent): void => { if (event != null) handleDecrement(event) } const handleUp = (event?: React.MouseEvent): void => { if (event != null) handleIncrement(event) } // Determina si mostrar las categorías const showCategories = dataExtra.length > 0 || dataOptional.length > 0 const listCategories = formatProductData(dataExtra ?? [], dataOptional ?? []) const priceOrFree = numberFormat(ProPrice as number) const delivery = `Domicilio: ${+(`${ValueDelivery}`.replace(/\./g, '').replace(',', '.')) > 0 ? numberFormat(ValueDelivery) : 'Gratis'}` const actions = [ (del) && { icon: 'IconDelete', onClick: handleDelete, className: styles['delete-button'] }, (edit) && { icon: 'IconEdit', onClick: handleEdit, className: styles['edit-button'] } ].filter(Boolean) as IButton[] return ( <>
{handleFree != null && ( )}
{actions.map((action, index) => Boolean(action) && ( ))} {delivery} {free ? 'Gratis' : priceOrFree} {Boolean(ProDescuento) && } {numberFormat(ProDescuento)} {sum && (
{ if (event != null) return handleUp(event) }} handleDecrement={(event) => { if (event != null) return handleDown(event) }} handleChangeQuantity={(event) => { return dispatch({ type: 'ON_CHANGE', payload: { value: String(event.target.value), name: 'name', index, id: pId } }) }} increment={increment} decrement={decrement} open={true} editable={false} editing={true} quantity={ProQuantity} />
)} {pName} {ProDescription}
{ fileInputRef?.current?.click() return onTargetClick() }} > {pName
{Boolean(tag?.tag) && (
)}
{showCategories && ( )}
) } export const CardProductSimple = React.memo(MemoCardProductSimple)