File size: 3,642 Bytes
ce3593c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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');
}