import { AnimatePresence, motion, usePresence } from 'framer-motion' import PropTypes from 'prop-types' import React, { useRef } from 'react' import { AwesomeModal } from '..' import { APColor, EColor } from '../../../assets/colors' import { IconDelete, IconEdit, IconMiniCheck } from '../../../assets/icons' import { getGlobalStyle, numberFormat } from '../../../utils' import { Checkbox, RippleButton, Row, Tag } from '../../atoms' import { InputHooks, QuantityButton } from '../../molecules' import { Action, ContentLinesItems, ContentModal } from './styled' export const CreateExtra = ({ LineItems = { Lines: [] }, loading = false, modal = false, inputRefs, pId = null, selected = { loading: false, exPid: null }, CleanLines = () => { return }, handleAdd = () => { return }, handleEdit = (i, item) => { return { i, item } }, handleFocusChange = (i) => { return i}, handleSelect = (item, index) => { return { item, index } }, handleLineChange = (i, extraName, value) => { return { i, extraName, value }}, handleRemove = (i, exPid) => { return { i, exPid } }, onSubmitUpdate = ({ pId }) => { return pId }, setModal = () => { return } }) => { const disabled = false const transition = { type: 'spring', stiffness: 300, damping: 30 } const [isPresent, safeToRemove] = usePresence() const animations = { layout: true, initial: 'out', style: { position: isPresent ? 'static' : 'absolute' }, animate: isPresent ? 'in' : 'out', whileTap: 'tapped', variants: { in: { y: 0, opacity: 1 }, out: { y: 30, opacity: 0, zIndex: -1 } }, onAnimationComplete: () => {return !isPresent && safeToRemove()}, transition } const endOfListRef = useRef({ scrollIntoView: (args) => { return args }, current: null }) return ( { return setModal() }} onHide={() => { return setModal() }} padding={0} question={false} show={modal} size='90%' sizeIconClose='30px' title='AƱade Complementos' zIndex={getGlobalStyle('--z-index-99999')} >
{LineItems?.Lines?.length ? LineItems?.Lines?.map((extra, i) => { const price = numberFormat(extra?.extraPrice) const exPid = extra?.exPid ?? null const forEdit = extra?.forEdit || false const isSelect = selected.exPid === exPid return ( { const value = e.target.value return handleLineChange(i, 'extraName', value) }} onFocus={() => { return handleFocusChange(i) }} placeholder='Nombre' reference={inputRefs && inputRefs?.current[i]} value={extra?.extraName} /> { const value = e.target.value const price = numberFormat(value) return handleLineChange(i, 'extraPrice', price) }} onFocus={() => { return handleFocusChange(i) }} placeholder='Precio' value={price} /> { return handleLineChange(i, 'exState', value) }} /> { return handleRemove(i, exPid) }} type='button' widthButton='min-content' > {forEdit ? <> { if (isSelect) return handleEdit(i, exPid) return handleSelect(extra, i) }} type='button' widthButton='min-content' > {selected?.exPid === exPid ? : } : <> } ) }) : null}
Eliminar { if (endOfListRef?.current) { endOfListRef.current.scrollIntoView({ behavior: 'smooth' }) } return handleAdd() }} quantity={Number(LineItems?.Lines?.length || 0)} showNegativeButton={true} style={{ margin: '0 20px 0 0', width: '60%' }} /> { e.preventDefault() return onSubmitUpdate({ pId }) }} widthButton='140px' > Guardar ) } CreateExtra.propTypes = { CleanLines: PropTypes.func, LineItems: PropTypes.shape({ Lines: PropTypes.shape({ length: PropTypes.any, map: PropTypes.func }) }), handleAdd: PropTypes.func, handleEdit: PropTypes.func, handleFocusChange: PropTypes.func, handleLineChange: PropTypes.func, handleRemove: PropTypes.func, handleSelect: PropTypes.func, inputRefs: PropTypes.shape({ current: PropTypes.any }), loading: PropTypes.bool, modal: PropTypes.bool, onSubmitUpdate: PropTypes.func, pId: PropTypes.any, selected: PropTypes.shape({ exPid: PropTypes.any, loading: PropTypes.bool }), setModal: PropTypes.func }