import PropTypes from 'prop-types'
import React from 'react'
import { BGColor, PColor } from '../../../assets/colors'
import { IconQuestion } from '../../../assets/icons'
import { Button, Checkbox, Tag, Text } from '../../atoms'
import { InputHooks, QuantityButton } from '../../molecules'
import { ContentCheckbox, GarnishChoicesHeader } from './styled'
export const FormExtra = ({
isEdit = false,
numberLimit = '',
selectedExtra = {},
setCheck,
showTooltip,
title = '',
handleAddList = () => {
return
},
setSelectedExtra = () => {
return
},
handleCheck = () => {
return
},
handleShowTooltip = () => {
return
},
setNumberLimit = () => {
return
},
setShowTooltip = () => {
return
},
setTitle = () => {
return
},
sendNotification = () => {
return
}
}) => {
const defaultTitle = 'Escoge tu... '
const finalTitle = title || defaultTitle
const emptyTitle = title?.trim() === ''
return (
{finalTitle}
Escoge hasta {isEdit ? selectedExtra?.numberLimit : numberLimit}{' '}
opciones.
{isEdit
? !!selectedExtra?.required &&
: setCheck.exState === true && }
{!isEdit && (
)}
{
if (isEdit)
return setSelectedExtra({
...selectedExtra,
title: e.target.value
})
return setTitle(e.target.value)
}}
onKeyDown={(e) => {
if (isEdit) return
if (e.key === 'Enter') {
handleAddList({ title: title, numberLimit: numberLimit })
}
}}
title='Añadir nueva lista'
type='text'
value={isEdit ? selectedExtra?.title : title}
/>
{
if (isEdit) {
setSelectedExtra((prevSelectedExtra) => {return {
...selectedExtra,
required: prevSelectedExtra.required === 1 ? 0 : 1
}})
} else {
handleCheck(e)
}
}}
type='checkbox'
/>
{
if (isEdit)
return setSelectedExtra({
...selectedExtra,
numberLimit: selectedExtra?.numberLimit - 1
})
return setNumberLimit(numberLimit === 0 ? 0 : numberLimit - 1)
}}
handleIncrement={() => {
if (isEdit)
return setSelectedExtra({
...selectedExtra,
numberLimit: selectedExtra?.numberLimit + 1
})
return setNumberLimit(numberLimit + 1)
}}
quantity={isEdit ? selectedExtra?.numberLimit : numberLimit}
showNegativeButton={isEdit ? (selectedExtra?.numberLimit === 1) : (numberLimit === 1)}
/>
{!isEdit && (
{
if (emptyTitle) {
return sendNotification({
description: 'hace falta el titulo de la sobremesa',
title: 'Error',
backgroundColor: 'error'
})
}
return handleAddList({
title: title,
numberLimit: numberLimit
})
}}
type='button'
width='100%'
>
Añadir
)}
)
}
FormExtra.propTypes = {
handleAddList: PropTypes.func,
handleCheck: PropTypes.func,
handleShowTooltip: PropTypes.func,
isEdit: PropTypes.bool,
numberLimit: PropTypes.string,
selectedExtra: PropTypes.object,
sendNotification: PropTypes.func,
setCheck: PropTypes.shape({
exState: PropTypes.bool
}),
setNumberLimit: PropTypes.func,
setSelectedExtra: PropTypes.func,
setShowTooltip: PropTypes.func,
setTitle: PropTypes.func,
showTooltip: PropTypes.string,
title: PropTypes.string
}