import Image from 'next/image' import { useRouter } from 'next/router' import PropTypes from 'prop-types' import React, { useState } from 'react' import { IconComment, IconDelete, IconEdit } from '../../../assets/icons' import { Tag } from '../../atoms' import { RippleButton } from '../../atoms/Ripple' import { BGColor, PColor } from './../../../assets/colors/index' import { numberFormat } from './../../../utils/index' import { ActionName, Button, ButtonCard, Card, ContainerActions, InputCounter, ItemProQuantity, OverlineCategory, OverlineFree, WrapperButton, WrapperCard } from './styled' export const MemoCardProductSimple = ({ del, edit, fileInputRef, free = false, buttonComment = false, asComment = false, decrement = true, increment = true, handleFree, height, index = 0, pId, pName = '', ProDescription = '', ProDescuento = 0, ProPrice = 0, ProQuantity = 0, render = null, sum, margin, tag, ValueDelivery, widthButton, activeComment, dataExtra = [], dataOptional = [], dispatch = () => { return }, handleComment = () => { return }, handleDecrement = () => { return }, handleDelete = () => { return }, handleFreeProducts = () => { return }, handleIncrement = () => { return }, onClick = () => { return }, onFileInputChange = () => { return }, onTargetClick = () => { return } }) => { const router = useRouter() const [startAnimateUp, setStartAnimateUp] = useState('') const [animateType, setAnimateType] = useState('') const [show, setShow] = useState(false) const handle = () => { setTimeout(() => { setAnimateType('move-up') setStartAnimateUp('') }, 250) } const handleDown = (event) => { handleDecrement(event) setStartAnimateUp('') setAnimateType('') setTimeout(() => { setStartAnimateUp('start-animate-down') setTimeout(() => { setAnimateType('move-down') setStartAnimateUp('') }, 150) }, 0) } const handleUp = (event) => { handleIncrement(event) setStartAnimateUp('') setAnimateType('') setTimeout(() => { setStartAnimateUp('start-animate-up') handle() }, 0) } const urlImage = '/images/DEFAULTBANNER.png' // Determina si mostrar las categorías const showCategories = dataExtra.length > 0 || dataOptional.length > 0 // Crea los formateados const conjunctionFormatter = new Intl.ListFormat('es', { style: 'long', type: 'conjunction' }) const unitFormatter = new Intl.ListFormat('es', { style: 'narrow', type: 'unit' }) // Formatea los datos extras const formattedExtraData = dataExtra .slice(0, 4) .map(product => {return `$ ${numberFormat(product?.extraPrice)}, ${product.extraName}`}) const finalExtraFormat = conjunctionFormatter.format(formattedExtraData) // Formatea los datos opcionales const formattedOptionalData = dataOptional .slice(0, 4) .map(product => {return product?.ExtProductFoodsSubOptionalAll?.map(subProduct => {return subProduct.OptionalSubProName}).join(', ')}) const finalOptionalFormat = unitFormatter.format(formattedOptionalData) // Une las dos listas const listCategories = `${finalExtraFormat}, ${finalOptionalFormat}` const priceOrFree = ProPrice > 0 ? `$ ${numberFormat(ProPrice)}` : 'Gratis' return ( <> {handleFree && ( Gratis )} {del && ( Eliminar )} {buttonComment && ( Comentar )} {edit && ( { return router.push(`/update/products/editar/${pId}`) }} top={'80px'} > Editar )}
{ValueDelivery > 0 && ( Domicilio ${' '} {ValueDelivery > 0 ? numberFormat(ValueDelivery) : 'Gratis'} )}
{ free === 1 ? 'Gratis' : priceOrFree } {ProDescuento > 0 && ( {` $ ${numberFormat( ProDescuento )}`} )}
{sum && ( {decrement && ( )}
{ return setShow(index) }} >
{ProQuantity}
{show === index && ( { return setShow(false) }} onChange={(event) => { return dispatch({ type: 'ON_CHANGE', payload: { value: event.target.value, name: 'name', index: index, id: pId } }) }} onFocus={(event) => { return dispatch({ type: 'ON_CHANGE', payload: { value: event.target.value, name: 'name', index: index, id: pId } }) }} onKeyDown={(event) => { return event.key === 'Enter' ? setShow(false) : null }} show={show} type='number' value={ProQuantity} /> )}
{increment && ( )}
)}

{pName}

{ProDescription}
{render && ( { return onClick() }} padding='0' widthButton={widthButton} > {render} )}
{ return onTargetClick() }} > {pName
{!!tag?.tag && (
)}
{showCategories && ( {listCategories} )} {showCategories && (
)}
) } export const CardProductSimple = React.memo(MemoCardProductSimple) MemoCardProductSimple.propTypes = { ProDescription: PropTypes.any, ProDescuento: PropTypes.number, ProImage: PropTypes.string, ProPrice: PropTypes.any, ProQuantity: PropTypes.any, ValueDelivery: PropTypes.number, activeComment: PropTypes.any, asComment: PropTypes.bool, buttonComment: PropTypes.bool, dataExtra: PropTypes.array, dataOptional: PropTypes.array, decrement: PropTypes.bool, del: PropTypes.any, dispatch: PropTypes.func, edit: PropTypes.any, fileInputRef: PropTypes.any, free: PropTypes.number, handleComment: PropTypes.func, handleDecrement: PropTypes.func, handleDelete: PropTypes.func, handleFree: PropTypes.any, handleFreeProducts: PropTypes.func, handleIncrement: PropTypes.func, height: PropTypes.any, increment: PropTypes.bool, index: PropTypes.any, key: PropTypes.any, margin: PropTypes.any, onClick: PropTypes.func, onFileInputChange: PropTypes.any, onTargetClick: PropTypes.func, pId: PropTypes.any, pName: PropTypes.string, render: PropTypes.any, src: PropTypes.any, sum: PropTypes.any, tag: PropTypes.shape({ tag: PropTypes.any }), widthButton: PropTypes.any }