Spaces:
Sleeping
Sleeping
| document.getElementById('submit-btn').addEventListener('click', function () { | |
| const userMessage = document.getElementById('user-message').value; | |
| if (!userMessage) return; | |
| addMessage(userMessage, 'user'); | |
| if (userMessage.toLowerCase() === 'yes' || userMessage.toLowerCase() === 'yeah') { | |
| setTimeout(() => { | |
| addMessage("Great! Please select a food category:", 'bot'); | |
| showCategorySelection(); | |
| }, 1000); | |
| } else { | |
| setTimeout(() => { | |
| addMessage("Okay, let me know if you change your mind!", 'bot'); | |
| }, 1000); | |
| } | |
| document.getElementById('user-message').value = ''; | |
| }); | |
| function addMessage(message, sender) { | |
| const messageContainer = document.createElement('div'); | |
| messageContainer.classList.add(sender + '-message'); | |
| messageContainer.textContent = message; | |
| document.getElementById('chat-box').appendChild(messageContainer); | |
| document.getElementById('chat-box').scrollTop = document.getElementById('chat-box').scrollHeight; | |
| } | |
| function showCategorySelection() { | |
| document.getElementById('category-dropdown').hidden = false; | |
| document.getElementById('category-dropdown').addEventListener('change', function () { | |
| const selectedCategory = this.value; | |
| setTimeout(() => { | |
| addMessage(`You selected: ${selectedCategory}. Now, please select your nutrition preference.`, 'bot'); | |
| showNutritionSelection(); | |
| }, 1000); | |
| }); | |
| } | |
| function showNutritionSelection() { | |
| document.getElementById('nutrition-dropdown').hidden = false; | |
| document.getElementById('nutrition-dropdown').addEventListener('change', function () { | |
| const selectedNutrition = this.value; | |
| setTimeout(() => { | |
| addMessage(`You selected: ${selectedNutrition}. Here are the ingredients based on your selection:`, 'bot'); | |
| showIngredientsList(selectedNutrition); | |
| }, 1000); | |
| }); | |
| } | |
| function showIngredientsList(selectedNutrition) { | |
| const ingredients = { | |
| "Veg": ["Paneer", "Potato", "Cabbage", "Gobi"], | |
| "Non-Veg": ["Chicken", "Fish", "Mutton"], | |
| "Vegan": ["Tofu", "Tempeh", "Seitan"], | |
| "Pasta & Noodles": ["Whole Wheat Pasta", "Rice Noodles"], | |
| "Breads & Baked Goods": ["Whole Grain Bread", "Gluten-Free Bread"] | |
| }; | |
| const ingredientList = ingredients[selectedCategory] || []; | |
| const ingredientDropdown = document.getElementById('ingredient-dropdown'); | |
| ingredientDropdown.innerHTML = ingredientList.map(ingredient => `<option value="${ingredient}">${ingredient}</option>`).join(''); | |
| ingredientDropdown.hidden = false; | |
| ingredientDropdown.addEventListener('change', function () { | |
| const selectedIngredient = this.value; | |
| setTimeout(() => { | |
| addMessage(`You selected: ${selectedIngredient}. Here are the food items you can make:`, 'bot'); | |
| showFoodItems(selectedIngredient); | |
| }, 1000); | |
| }); | |
| } | |
| function showFoodItems(selectedIngredient) { | |
| const foodItems = { | |
| "Paneer": ["Paneer Tikka", "Paneer Curry", "Paneer Manchurian", "Paneer Butter Masala"], | |
| "Potato": ["Aloo Dal", "Potato and Chickpea Salad", "Paneer-Stuffed Potatoes", "Potato and Black Bean Tacos"], | |
| "Cabbage": ["Cabbage and Chickpea Curry", "Cabbage Stir-Fry with Tofu", "Cabbage and Lentil Soup"], | |
| "Chicken": ["Grilled Chicken Breast", "Chicken Tikka Masala", "Chicken Stir-Fry", "Chicken Biryani"], | |
| "Fish": ["Grilled Salmon", "Fish Curry", "Baked Fish with Herbs", "Fish Tacos"], | |
| "Mutton": ["Mutton Curry", "Mutton Biryani", "Grilled Lamb Chops", "Mutton Rogan Josh"], | |
| "Tofu": ["Tofu Stir-Fry", "Crispy Tofu Nuggets", "Tofu Scramble", "Tofu Curry"] | |
| }; | |
| const dishes = foodItems[selectedIngredient] || []; | |
| addMessage(dishes.join(", "), 'bot'); | |
| } | |