import React, { useState } from 'react'
import styled from "styled-components"
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { useDispatch, useSelector } from 'react-redux'
import { findRecipeById } from '../../../redux/slices/recipesSlice'
//styles
import {
StyledModal, ModalHeader, WrapperButtons, VerticalSeperator, Button, Input, WrapperDropdown, ModalDescription, WrapperInput, IconCheck, IconWrong, Wrapper, ButtonText
} from '../styles/modal'
import Ingredient from '../../recipes/Ingredient&Button'
import { itemAdded } from '../../../redux/slices/groceryList/itemsSlice'
import Dropdown from '../../Dropdown'
import theme from '../../../styles/theme';
import { Text } from 'react-native';
const IconList = () =>
const IconMeal = () =>
const ModalAddIngredients = (props) => {
const dispatch = useDispatch()
const recipe = useSelector(state => findRecipeById(state, props.id))
let amountOfServings = recipe.servings ? recipe.servings : 1
const lists = useSelector(state => state.lists.entities)
const [listName, setListName] = useState('')
const [focused, setFocused] = useState(false)
const [servings, setServings] = useState(amountOfServings)
let servingsMultiplier = Math.ceil(servings / amountOfServings)
const IngredientsList = recipe.ingredients.map((ingredient, index) => {
return (
)
})
const handleSubmit = () => {
if (lists.find(list => list.listName === listName) && recipe.ingredients.find(ingredient => ingredient.checked)) {
console.log('were sending the ingredients baby')
recipe.ingredients.forEach(ingredient => ingredient.checked === true && dispatch(itemAdded({
productName: ingredient.productName,
amount: {
am: ingredient.amount * servingsMultiplier,
qt: ingredient.portion,
},
tag: ingredient.tag,
price: ingredient.price,
person: '',
details: `For ${recipe.name} (${ingredient.portion}) `,
listId: lists.find(list => list.listName === listName)._id
})))
props.closeModal()
}
else {
alert('You should fill in a valid grocery list and/or select at least 1 ingredient')
}
}
return (
Add to grocerylist
Choose a grocery list and select the ingredients you would like to add to it
setListName(text)}
onFocus={() => setFocused(true)} onBlur={() => { setTimeout(() => { setFocused(false) }, 100) }}
placeholder="Grocery list" />
{listName ? : }
{focused &&
list.listName)} text={listName} setElement={setListName} />
}
setServings(text)}
min={amountOfServings}
step={amountOfServings}
placeholder="Multiplier" />
servings
{IngredientsList}
)
}
export default ModalAddIngredients