nagasurendra commited on
Commit
cf13fed
·
verified ·
1 Parent(s): 492f069

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +905 -13
templates/menu.html CHANGED
@@ -39,6 +39,7 @@
39
  transition: opacity 0.3s ease-in-out;
40
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
41
  }
 
42
  .menu-card.visible {
43
  opacity: 1;
44
  }
@@ -1071,6 +1072,322 @@
1071
  font-size: 0.9rem;
1072
  }
1073
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1074
  </style>
1075
  </head>
1076
  <body>
@@ -1118,19 +1435,16 @@
1118
  <div class="container mt-4">
1119
  {% if selected_category == "Customized Dish" %}
1120
  <div id="custom-dish-form" class="mt-4">
1121
- <h3>Create Your Custom Dish</h3>
1122
- <form method="POST" action="/customdish/generate_custom_dish">
1123
- <div class="mb-3">
1124
- <label for="custom-dish-name" class="form-label">Dish Name</label>
1125
- <input type="text" class="form-control" id="custom-dish-name" name="name" required>
1126
- </div>
1127
- <div class="mb-3 position-relative">
1128
- <label for="custom-dish-description" class="form-label">Dish Description</label>
1129
- <textarea class="form-control" id="custom-dish-description" name="description" required></textarea>
1130
- <div id="descriptionSuggestions" class="autocomplete-suggestions"></div>
1131
- </div>
1132
- <button type="submit" class="btn btn-primary">Submit Custom Dish</button>
1133
- </form>
1134
  </div>
1135
  {% else %}
1136
  {% if ordered_menu.items()|length == 0 %}
@@ -1848,6 +2162,584 @@
1848
  quantityInput.value = quantity;
1849
  });
1850
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1851
  </script>
1852
  </body>
1853
  </html>
 
39
  transition: opacity 0.3s ease-in-out;
40
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
41
  }
42
+
43
  .menu-card.visible {
44
  opacity: 1;
45
  }
 
1072
  font-size: 0.9rem;
1073
  }
1074
  }
1075
+ .chat-container {
1076
+ box-sizing: border-box;
1077
+ margin: 0;
1078
+ padding: 0;
1079
+ }
1080
+ body {
1081
+ font-family: 'Segoe UI', Arial, sans-serif;
1082
+ background-color: #f4f7fa;
1083
+ overflow-x: hidden;
1084
+ line-height: 1.5;
1085
+ }
1086
+ .chat-container {
1087
+ width: 100%;
1088
+ max-width: 800px;
1089
+ height: 100vh;
1090
+ margin: 0 auto;
1091
+ background-color: #ffffff;
1092
+ border-radius: 12px;
1093
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
1094
+ display: flex;
1095
+ flex-direction: column;
1096
+ overflow: hidden;
1097
+ }
1098
+ .chat-header {
1099
+ background-color: #0078d4;
1100
+ color: #ffffff;
1101
+ padding: 12px;
1102
+ text-align: center;
1103
+ font-size: 18px;
1104
+ font-weight: 600;
1105
+ flex-shrink: 0;
1106
+ }
1107
+ .chat-messages {
1108
+ flex: 1;
1109
+ overflow-y: auto;
1110
+ padding: 15px;
1111
+ scroll-behavior: smooth;
1112
+ }
1113
+ .bot-message, .user-message {
1114
+ padding: 10px 15px;
1115
+ margin: 8px 0;
1116
+ border-radius: 12px;
1117
+ max-width: 80%;
1118
+ font-size: 14px;
1119
+ line-height: 1.4;
1120
+ }
1121
+ .bot-message {
1122
+ background-color: #e8f0fe;
1123
+ color: #333;
1124
+ }
1125
+ .user-message {
1126
+ background-color: #0078d4;
1127
+ color: #ffffff;
1128
+ margin-left: auto;
1129
+ }
1130
+ .chat-input {
1131
+ display: flex;
1132
+ padding: 10px;
1133
+ border-top: 1px solid #e0e0e0;
1134
+ background-color: #f9f9f9;
1135
+ flex-shrink: 0;
1136
+ }
1137
+ .chat-input input {
1138
+ flex: 1;
1139
+ padding: 10px;
1140
+ border: 1px solid #ccc;
1141
+ border-radius: 8px;
1142
+ font-size: 14px;
1143
+ outline: none;
1144
+ }
1145
+ .chat-input button {
1146
+ padding: 10px 20px;
1147
+ margin-left: 10px;
1148
+ background-color: #0078d4;
1149
+ color: #ffffff;
1150
+ border: none;
1151
+ border-radius: 8px;
1152
+ cursor: pointer;
1153
+ font-size: 14px;
1154
+ transition: background-color 0.2s;
1155
+ }
1156
+ .chat-input button:hover {
1157
+ background-color: #005ea2;
1158
+ }
1159
+ .ingredients-list, .menu-items-list, .customization-ingredients-list {
1160
+ display: flex;
1161
+ flex-wrap: nowrap;
1162
+ overflow-x: auto;
1163
+ padding: 10px;
1164
+ margin: 10px 0;
1165
+ background-color: #f5f7fa;
1166
+ border-radius: 10px;
1167
+ gap: 15px;
1168
+ scroll-behavior: smooth;
1169
+ }
1170
+ .ingredient-item, .menu-item {
1171
+ flex: 0 0 200px;
1172
+ background-color: #ffffff;
1173
+ border: 1px solid #e0e0e0;
1174
+ border-radius: 10px;
1175
+ padding: 10px;
1176
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
1177
+ transition: transform 0.2s;
1178
+ text-align: center;
1179
+ }
1180
+ .ingredient-item:hover, .menu-item:hover {
1181
+ transform: translateY(-2px);
1182
+ }
1183
+ .ingredient-item img, .menu-item img {
1184
+ width: 100%;
1185
+ height: 120px;
1186
+ object-fit: cover;
1187
+ border-radius: 8px;
1188
+ margin-bottom: 8px;
1189
+ }
1190
+ .ingredient-item div, .menu-item div {
1191
+ font-size: 14px;
1192
+ font-weight: 600;
1193
+ color: #333;
1194
+ margin-bottom: 5px;
1195
+ }
1196
+ .ingredient-item button, .menu-item button {
1197
+ padding: 8px;
1198
+ background-color: #28a745;
1199
+ color: #ffffff;
1200
+ border: none;
1201
+ border-radius: 6px;
1202
+ cursor: pointer;
1203
+ font-size: 12px;
1204
+ width: 100%;
1205
+ }
1206
+ .ingredient-item button:hover, .menu-item button:hover {
1207
+ background-color: #218838;
1208
+ }
1209
+ .selected-ingredients, .selected-customization-ingredients {
1210
+ background-color: #f1f8ff;
1211
+ padding: 15px;
1212
+ border: 1px solid #b3d7ff;
1213
+ border-radius: 10px;
1214
+ margin: 10px 0;
1215
+ font-size: 14px;
1216
+ display: flex;
1217
+ flex-wrap: wrap;
1218
+ gap: 10px;
1219
+ }
1220
+ .selected-ingredients div, .selected-customization-ingredients div {
1221
+ background-color: #d6e9ff;
1222
+ padding: 5px 10px;
1223
+ border-radius: 6px;
1224
+ font-size: 13px;
1225
+ }
1226
+ .customization-input {
1227
+ margin: 10px 0;
1228
+ }
1229
+ .customization-input textarea, .selected-customization-ingredients textarea {
1230
+ width: 100%;
1231
+ padding: 8px;
1232
+ border: 1px solid #b3d7ff;
1233
+ border-radius: 6px;
1234
+ font-size: 14px;
1235
+ outline: none;
1236
+ margin-bottom: 10px;
1237
+ }
1238
+ .customization-input button, .submit-button, .submit-customization-button, .submit-cart-button {
1239
+ padding: 10px 20px;
1240
+ background-color: #0078d4;
1241
+ color: #ffffff;
1242
+ border: none;
1243
+ border-radius: 8px;
1244
+ cursor: pointer;
1245
+ font-size: 14px;
1246
+ transition: background-color 0.2s;
1247
+ }
1248
+ .customization-input button:hover, .submit-button:hover, .submit-customization-button:hover, .submit-cart-button:hover {
1249
+ background-color: #005ea2;
1250
+ }
1251
+ .option-button {
1252
+ padding: 10px 20px;
1253
+ color: #ffffff;
1254
+ border: none;
1255
+ border-radius: 8px;
1256
+ cursor: pointer;
1257
+ font-size: 14px;
1258
+ margin: 5px;
1259
+ transition: background-color 0.2s;
1260
+ }
1261
+ .option-button.green {
1262
+ background-color: #28a745;
1263
+ }
1264
+ .option-button.green:hover {
1265
+ background-color: #218838;
1266
+ }
1267
+ .option-button.red {
1268
+ background-color: #dc3545;
1269
+ }
1270
+ .option-button.red:hover {
1271
+ background-color: #c82333;
1272
+ }
1273
+ .cart-items {
1274
+ background-color: #f1f8ff;
1275
+ padding: 15px;
1276
+ border: 1px solid #b3d7ff;
1277
+ border-radius: 10px;
1278
+ margin: 10px 0;
1279
+ font-size: 14px;
1280
+ }
1281
+ .cart-item {
1282
+ display: flex;
1283
+ align-items: center;
1284
+ background-color: #d6e9ff;
1285
+ padding: 5px 10px;
1286
+ border-radius: 6px;
1287
+ font-size: 13px;
1288
+ margin: 5px 0;
1289
+ }
1290
+ .cart-item img {
1291
+ width: 30px;
1292
+ height: 30px;
1293
+ object-fit: cover;
1294
+ border-radius: 6px;
1295
+ margin-right: 8px;
1296
+ }
1297
+ .cart-item .remove-button {
1298
+ padding: 5px 10px;
1299
+ margin-left: 8px;
1300
+ background-color: #dc3545;
1301
+ color: #ffffff;
1302
+ border: none;
1303
+ border-radius: 6px;
1304
+ cursor: pointer;
1305
+ font-size: 12px;
1306
+ }
1307
+ .cart-item .remove-button:hover {
1308
+ background-color: #c82333;
1309
+ }
1310
+ /* Responsive Design */
1311
+ @media (max-width: 480px) {
1312
+ .chat-container {
1313
+ border-radius: 0;
1314
+ box-shadow: none;
1315
+ }
1316
+ .chat-header {
1317
+ font-size: 16px;
1318
+ padding: 10px;
1319
+ }
1320
+ .chat-messages {
1321
+ padding: 10px;
1322
+ }
1323
+ .bot-message, .user-message {
1324
+ font-size: 13px;
1325
+ padding: 8px 12px;
1326
+ margin: 5px 0;
1327
+ }
1328
+ .chat-input input {
1329
+ font-size: 13px;
1330
+ padding: 8px;
1331
+ }
1332
+ .chat-input button {
1333
+ font-size: 13px;
1334
+ padding: 8px 15px;
1335
+ }
1336
+ .ingredients-list, .menu-items-list, .customization-ingredients-list {
1337
+ flex-direction: column;
1338
+ gap: 10px;
1339
+ padding: 8px;
1340
+ }
1341
+ .ingredient-item, .menu-item {
1342
+ flex: 0 0 auto;
1343
+ width: 100%;
1344
+ max-width: 250px;
1345
+ }
1346
+ .ingredient-item img, .menu-item img {
1347
+ height: 100px;
1348
+ }
1349
+ .ingredient-item div, .menu-item div {
1350
+ font-size: 13px;
1351
+ }
1352
+ .ingredient-item button, .menu-item button {
1353
+ font-size: 11px;
1354
+ padding: 6px;
1355
+ }
1356
+ .option-button {
1357
+ font-size: 13px;
1358
+ padding: 8px 15px;
1359
+ }
1360
+ .selected-ingredients, .selected-customization-ingredients, .cart-items {
1361
+ padding: 10px;
1362
+ gap: 8px;
1363
+ }
1364
+ .cart-item {
1365
+ font-size: 12px;
1366
+ padding: 4px 8px;
1367
+ }
1368
+ .cart-item img {
1369
+ width: 25px;
1370
+ height: 25px;
1371
+ }
1372
+ }
1373
+ @media (min-width: 481px) and (max-width: 768px) {
1374
+ .chat-container {
1375
+ max-width: 600px;
1376
+ }
1377
+ .chat-header {
1378
+ font-size: 17px;
1379
+ padding: 11px;
1380
+ }
1381
+ .chat-messages {
1382
+ padding: 12px;
1383
+ }
1384
+ .ingredient-item, .menu-item {
1385
+ flex: 0 0 180px;
1386
+ }
1387
+ .ingredient-item img, .menu-item img {
1388
+ height: 110px;
1389
+ }
1390
+ }
1391
  </style>
1392
  </head>
1393
  <body>
 
1435
  <div class="container mt-4">
1436
  {% if selected_category == "Customized Dish" %}
1437
  <div id="custom-dish-form" class="mt-4">
1438
+ <div class="chat-container">
1439
+ <div class="chat-header">🍳 Chef Bot</div>
1440
+ <div class="chat-messages" id="chatMessages">
1441
+ <!-- Initial message will be set by JavaScript based on session -->
1442
+ </div>
1443
+ <div class="chat-input">
1444
+ <input type="text" id="userInput" placeholder="Type your name or message...">
1445
+ <button onclick="sendMessage()">Send</button>
1446
+ </div>
1447
+ </div>
 
 
 
1448
  </div>
1449
  {% else %}
1450
  {% if ordered_menu.items()|length == 0 %}
 
2162
  quantityInput.value = quantity;
2163
  });
2164
  });
2165
+ let currentStep = 'greeting'; // other possible values: 'food_type', 'select_ingredients', 'menu_display', 'customization', 'post_cart'
2166
+ let conversation = [];
2167
+ let selectedIngredients = [];
2168
+ let selectedMenuItem = null;
2169
+ let cart = [];
2170
+ // Get the user name passed from Flask (via Jinja)
2171
+ const userName = "{{ user_name }}"; // Jinja syntax to inject user_name from Flask session
2172
+ window.onload = function() {
2173
+ if (userName) {
2174
+ // If user_name exists, greet the user directly and proceed to food preference
2175
+ conversation.push({ role: 'bot', message: `Nice to meet you, ${userName}! 😊 Let's create your perfect meal! What type of food would you prefer?` });
2176
+ displayConversation(); // Display the current conversation
2177
+ displayOptions([
2178
+ { text: 'Vegetarian', class: 'green' },
2179
+ { text: 'Non-Vegetarian', class: 'red' }
2180
+ ]);
2181
+ } else {
2182
+ // Ask for the name if it's not found
2183
+ conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
2184
+ displayConversation(); // Display the conversation
2185
+ }
2186
+ };
2187
+ // Function to add messages to the chat
2188
+ function addMessage(role, message) {
2189
+ const chatMessages = document.getElementById('chatMessages');
2190
+ if (!chatMessages) {
2191
+ console.error('Chat messages container not found!');
2192
+ return;
2193
+ }
2194
+ const messageDiv = document.createElement('div');
2195
+ messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message';
2196
+ messageDiv.textContent = message;
2197
+ chatMessages.appendChild(messageDiv);
2198
+ chatMessages.scrollTop = chatMessages.scrollHeight;
2199
+ }
2200
+ // Function to display all conversation messages
2201
+ function displayConversation() {
2202
+ const chatMessages = document.getElementById('chatMessages');
2203
+ chatMessages.innerHTML = ''; // Clear previous messages
2204
+ conversation.forEach(msg => {
2205
+ const messageDiv = document.createElement('div');
2206
+ messageDiv.className = msg.role === 'bot' ? 'bot-message' : 'user-message';
2207
+ messageDiv.textContent = msg.message;
2208
+ chatMessages.appendChild(messageDiv);
2209
+ });
2210
+ chatMessages.scrollTop = chatMessages.scrollHeight; // Scroll to bottom
2211
+ }
2212
+ // Function to handle user input
2213
+ function sendMessage() {
2214
+ const userInput = document.getElementById('userInput').value.trim();
2215
+ if (userInput) {
2216
+ addMessage('user', userInput);
2217
+ conversation.push({ role: 'user', message: userInput });
2218
+ document.getElementById('userInput').value = ''; // Clear input field
2219
+ setTimeout(() => handleResponse(userInput), 500);
2220
+ } else {
2221
+ console.warn('Empty message!');
2222
+ }
2223
+ }
2224
+ function handleResponse(userInput) {
2225
+ const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
2226
+ let botResponse = '';
2227
+ let options = [];
2228
+ // If user has already selected food type, proceed without repeating the question
2229
+ if (lastMessage.includes('non-vegetarian')) {
2230
+ conversation.push({ role: 'user', message: 'Non-Vegetarian' });
2231
+ console.log("Food preference selected: Non-Vegetarian");
2232
+ botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
2233
+ fetchIngredients('non-vegetarian');
2234
+ return;
2235
+ } else if (lastMessage.includes('vegetarian')) {
2236
+ conversation.push({ role: 'user', message: 'Vegetarian' });
2237
+ console.log("Food preference selected: Vegetarian");
2238
+ botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
2239
+ fetchIngredients('vegetarian');
2240
+ return;
2241
+ } else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
2242
+ conversation.push({ role: 'user', message: lastMessage });
2243
+ console.log(`Non-veg option selected: ${lastMessage}`);
2244
+ botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
2245
+ fetchIngredients(lastMessage.toLowerCase());
2246
+ return;
2247
+ } else if (lastMessage.includes('yes') && selectedMenuItem) {
2248
+ botResponse = 'Here are some ingredients to customize your dish:';
2249
+ handleYesResponse();
2250
+ return;
2251
+ } else if (lastMessage.includes('no') && selectedMenuItem) {
2252
+ // Submit the dish without customization
2253
+ submitCustomizationIngredients();
2254
+ return;
2255
+ } else if (lastMessage.includes('yes') && currentStep === 'post_cart') {
2256
+ // After user says 'yes', ask again for food preference (veg or non-veg)
2257
+ botResponse = `Let's get started again! What type of food would you prefer this time?`;
2258
+ options = [
2259
+ { text: 'Vegetarian', class: 'green' },
2260
+ { text: 'Non-Vegetarian', class: 'red' }
2261
+ ];
2262
+ currentStep = 'food_type';
2263
+ addMessage('bot', botResponse);
2264
+ displayOptions(options);
2265
+ return;
2266
+ } else if (lastMessage.includes('non-vegetarian') && currentStep === 'food_type') {
2267
+ // Handle non-vegetarian selection
2268
+ conversation.push({ role: 'user', message: 'Non-Vegetarian' });
2269
+ console.log("Food preference selected: Non-Vegetarian");
2270
+ botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
2271
+ fetchIngredients('non-vegetarian');
2272
+ return;
2273
+ } else if (lastMessage.includes('vegetarian') && currentStep === 'food_type') {
2274
+ // Handle vegetarian selection
2275
+ conversation.push({ role: 'user', message: 'Vegetarian' });
2276
+ console.log("Food preference selected: Vegetarian");
2277
+ botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
2278
+ fetchIngredients('vegetarian');
2279
+ return;
2280
+ } else if (lastMessage.includes('no') && currentStep === 'post_cart') {
2281
+ addMessage('bot', 'Awesome! 🧾 Here’s your final cart:');
2282
+ displayCart(); // Optional: show final cart again
2283
+ addMessage('bot', 'Thank you for your order! 👨‍🍳🍲');
2284
+ currentStep = 'end';
2285
+ return;
2286
+ }
2287
+ addMessage('bot', botResponse);
2288
+ if (options.length > 0) {
2289
+ displayOptions(options);
2290
+ }
2291
+ displayCart();
2292
+ }
2293
+ function handleYesResponse() {
2294
+ if (!selectedMenuItem) {
2295
+ addMessage('bot', 'No dish selected. Please choose a dish first.');
2296
+ return;
2297
+ }
2298
+ const botResponse = `Here is your selected dish: ${selectedMenuItem.name}`;
2299
+ addMessage('bot', botResponse);
2300
+ // Display selected menu item
2301
+ const chatMessages = document.getElementById('chatMessages');
2302
+ const menuItemDiv = document.createElement('div');
2303
+ menuItemDiv.className = 'menu-item';
2304
+ const img = document.createElement('img');
2305
+ img.src = selectedMenuItem.image_url || 'https://via.placeholder.com/120';
2306
+ img.alt = selectedMenuItem.name;
2307
+ const name = document.createElement('div');
2308
+ name.textContent = selectedMenuItem.name;
2309
+ menuItemDiv.appendChild(img);
2310
+ menuItemDiv.appendChild(name);
2311
+ chatMessages.appendChild(menuItemDiv);
2312
+ // Fetch ingredients for customization
2313
+ fetchIngredientsForCustomization('both');
2314
+ }
2315
+ function fetchIngredientsForCustomization(foodPreference) {
2316
+ fetch('/get_ingredients', { // Reuse existing endpoint
2317
+ method: 'POST',
2318
+ headers: { 'Content-Type': 'application/json' },
2319
+ body: JSON.stringify({ dietary_preference: foodPreference })
2320
+ })
2321
+ .then(response => response.json())
2322
+ .then(data => {
2323
+ if (data.error) {
2324
+ addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
2325
+ } else {
2326
+ const ingredients = data.ingredients || [];
2327
+ addMessage('bot', 'Please select ingredients to customize:');
2328
+ displayCustomizationIngredients(ingredients);
2329
+ }
2330
+ })
2331
+ .catch(error => {
2332
+ addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
2333
+ });
2334
+ }
2335
+ function displayCustomizationIngredients(ingredients) {
2336
+ const chatMessages = document.getElementById('chatMessages');
2337
+ if (!chatMessages) {
2338
+ console.error('Chat messages container not found for customization ingredients!');
2339
+ return;
2340
+ }
2341
+ let ingredientsList = document.querySelector('.customization-ingredients-list');
2342
+ if (!ingredientsList) {
2343
+ ingredientsList = document.createElement('div');
2344
+ ingredientsList.className = 'customization-ingredients-list';
2345
+ chatMessages.appendChild(ingredientsList);
2346
+ } else {
2347
+ ingredientsList.innerHTML = '';
2348
+ }
2349
+ ingredients.forEach(ingredient => {
2350
+ const item = document.createElement('div');
2351
+ item.className = 'ingredient-item';
2352
+ const img = document.createElement('img');
2353
+ img.src = ingredient.image_url || 'https://via.placeholder.com/120';
2354
+ img.alt = ingredient.name;
2355
+ const name = document.createElement('div');
2356
+ name.textContent = ingredient.name;
2357
+ const button = document.createElement('button');
2358
+ button.textContent = 'Add';
2359
+ button.onclick = () => {
2360
+ if (!selectedIngredients.some(item => item.name === ingredient.name)) {
2361
+ selectedIngredients.push({ name: ingredient.name, image_url: ingredient.image_url });
2362
+ displaySelectedCustomizationIngredients();
2363
+ }
2364
+ };
2365
+ item.appendChild(img);
2366
+ item.appendChild(name);
2367
+ item.appendChild(button);
2368
+ ingredientsList.appendChild(item);
2369
+ });
2370
+ displaySelectedCustomizationIngredients();
2371
+ }
2372
+ function displaySelectedCustomizationIngredients() {
2373
+ const chatMessages = document.getElementById('chatMessages');
2374
+ if (!chatMessages) {
2375
+ console.error('Chat messages container not found for selected customization ingredients!');
2376
+ return;
2377
+ }
2378
+ let selectedArea = document.querySelector('.selected-customization-ingredients');
2379
+ if (!selectedArea) {
2380
+ selectedArea = document.createElement('div');
2381
+ selectedArea.className = 'selected-customization-ingredients';
2382
+ chatMessages.appendChild(selectedArea);
2383
+ } else {
2384
+ selectedArea.innerHTML = '';
2385
+ }
2386
+ const selectedIngredientsText = selectedIngredients.length > 0
2387
+ ? `${selectedMenuItem.name} with ${selectedIngredients.map(ingredient => ingredient.name).join(', ')}`
2388
+ : selectedMenuItem.name;
2389
+ const ingredientsDiv = document.createElement('div');
2390
+ ingredientsDiv.textContent = selectedIngredientsText;
2391
+ selectedArea.appendChild(ingredientsDiv);
2392
+ selectedIngredients.forEach(ingredient => {
2393
+ const div = document.createElement('div');
2394
+ div.textContent = ingredient.name;
2395
+ const removeButton = document.createElement('button');
2396
+ removeButton.textContent = 'X';
2397
+ removeButton.style.marginLeft = '5px';
2398
+ removeButton.style.padding = '2px 5px';
2399
+ removeButton.style.backgroundColor = '#dc3545';
2400
+ removeButton.style.color = '#ffffff';
2401
+ removeButton.style.border = 'none';
2402
+ removeButton.style.borderRadius = '4px';
2403
+ removeButton.style.cursor = 'pointer';
2404
+ removeButton.onclick = () => {
2405
+ selectedIngredients = selectedIngredients.filter(item => item.name !== ingredient.name);
2406
+ displaySelectedCustomizationIngredients();
2407
+ };
2408
+ div.appendChild(removeButton);
2409
+ selectedArea.appendChild(div);
2410
+ });
2411
+ if (!document.querySelector('.submit-customization-button')) {
2412
+ const textarea = document.createElement('textarea');
2413
+ textarea.placeholder = 'Enter any special instructions...';
2414
+ selectedArea.appendChild(textarea);
2415
+ const submitButton = document.createElement('button');
2416
+ submitButton.className = 'submit-customization-button';
2417
+ submitButton.textContent = 'Submit Customization';
2418
+ submitButton.onclick = submitCustomizationIngredients;
2419
+ selectedArea.appendChild(submitButton);
2420
+ }
2421
+ }
2422
+ function submitCustomizationIngredients() {
2423
+ if (!selectedMenuItem) {
2424
+ addMessage('bot', 'No dish selected. Please choose a dish first.');
2425
+ return;
2426
+ }
2427
+
2428
+ const textarea = document.querySelector('.selected-customization-ingredients textarea');
2429
+ const instructions = textarea ? textarea.value.trim() : '';
2430
+
2431
+ fetch('/submit_customization_ingredients', {
2432
+ method: 'POST',
2433
+ headers: { 'Content-Type': 'application/json' },
2434
+ body: JSON.stringify({
2435
+ menu_item: selectedMenuItem,
2436
+ ingredients: selectedIngredients,
2437
+ instructions: instructions
2438
+ })
2439
+ })
2440
+ .then(response => response.json())
2441
+ .then(data => {
2442
+ if (data.success) {
2443
+ addToCart({ ...selectedMenuItem, instructions, ingredients: selectedIngredients });
2444
+ currentStep = 'post_cart';
2445
+ addMessage('bot', 'Customization submitted successfully! Item added to cart.');
2446
+
2447
+ // Redirect to the cart page
2448
+ window.location.href = '/cart/cart'; // This will redirect the user to the cart page
2449
+ } else {
2450
+ addMessage('bot', `Error: ${data.error}`);
2451
+ }
2452
+ })
2453
+ .catch(error => {
2454
+ addMessage('bot', `Error submitting customization: ${error.message}`);
2455
+ });
2456
+ }
2457
+ function fetchIngredients(foodPreference) {
2458
+ fetch('/get_ingredients', {
2459
+ method: 'POST',
2460
+ headers: { 'Content-Type': 'application/json' },
2461
+ body: JSON.stringify({ dietary_preference: foodPreference })
2462
+ })
2463
+ .then(response => response.json())
2464
+ .then(data => {
2465
+ if (data.error) {
2466
+ addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
2467
+ } else {
2468
+ const ingredients = data.ingredients || [];
2469
+ addMessage('bot', 'Please select ingredients:');
2470
+ displayIngredientsList(ingredients);
2471
+ displaySelectedIngredients();
2472
+ }
2473
+ })
2474
+ .catch(error => {
2475
+ addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
2476
+ });
2477
+ }
2478
+ function fetchMenuItems(params) {
2479
+ fetch('/get_menu_items', {
2480
+ method: 'POST',
2481
+ headers: { 'Content-Type': 'application/json' },
2482
+ body: JSON.stringify(params)
2483
+ })
2484
+ .then(response => response.json())
2485
+ .then(data => {
2486
+ if (data.error) {
2487
+ addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
2488
+ } else {
2489
+ const menuItems = data.menu_items || [];
2490
+ addMessage('bot', 'Here are some dishes based on your selection:');
2491
+ displayMenuItems(menuItems);
2492
+ }
2493
+ })
2494
+ .catch(error => {
2495
+ addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
2496
+ });
2497
+ }
2498
+ function displayIngredientsList(ingredients) {
2499
+ const chatMessages = document.getElementById('chatMessages');
2500
+ if (!chatMessages) {
2501
+ console.error('Chat messages container not found for ingredients!');
2502
+ return;
2503
+ }
2504
+ let ingredientsList = document.querySelector('.ingredients-list');
2505
+ if (!ingredientsList) {
2506
+ ingredientsList = document.createElement('div');
2507
+ ingredientsList.className = 'ingredients-list';
2508
+ chatMessages.appendChild(ingredientsList);
2509
+ } else {
2510
+ ingredientsList.innerHTML = '';
2511
+ }
2512
+ ingredients.forEach(ingredient => {
2513
+ const item = document.createElement('div');
2514
+ item.className = 'ingredient-item';
2515
+ const img = document.createElement('img');
2516
+ img.src = ingredient.image_url || 'https://via.placeholder.com/120';
2517
+ img.alt = ingredient.name;
2518
+ const name = document.createElement('div');
2519
+ name.textContent = ingredient.name;
2520
+ const button = document.createElement('button');
2521
+ button.textContent = 'Add';
2522
+ button.onclick = () => {
2523
+ if (!selectedIngredients.some(item => item.name === ingredient.name)) {
2524
+ selectedIngredients.push(ingredient);
2525
+ displaySelectedIngredients();
2526
+ }
2527
+ };
2528
+ item.appendChild(img);
2529
+ item.appendChild(name);
2530
+ item.appendChild(button);
2531
+ ingredientsList.appendChild(item);
2532
+ });
2533
+ }
2534
+ function displayMenuItems(menuItems) {
2535
+ const chatMessages = document.getElementById('chatMessages');
2536
+ if (!chatMessages) {
2537
+ console.error('Chat messages container not found for menu items!');
2538
+ return;
2539
+ }
2540
+ let menuItemsList = document.querySelector('.menu-items-list');
2541
+ if (!menuItemsList) {
2542
+ menuItemsList = document.createElement('div');
2543
+ menuItemsList.className = 'menu-items-list';
2544
+ chatMessages.appendChild(menuItemsList);
2545
+ } else {
2546
+ menuItemsList.innerHTML = '';
2547
+ }
2548
+ menuItems.forEach(item => {
2549
+ const menuItem = document.createElement('div');
2550
+ menuItem.className = 'menu-item';
2551
+ const img = document.createElement('img');
2552
+ img.src = item.image_url || 'https://via.placeholder.com/120';
2553
+ img.alt = item.name;
2554
+ const name = document.createElement('div');
2555
+ name.textContent = item.name;
2556
+ const button = document.createElement('button');
2557
+ button.textContent = 'Add to Cart';
2558
+ button.onclick = () => {
2559
+ selectedMenuItem = item;
2560
+ addMessage('bot', `World-class selection! Would you like to customize your dish further?`);
2561
+ const options = [
2562
+ { text: 'Yes', class: 'green' },
2563
+ { text: 'No', class: 'red' }
2564
+ ];
2565
+ displayOptions(options);
2566
+ };
2567
+ menuItem.appendChild(img);
2568
+ menuItem.appendChild(name);
2569
+ menuItem.appendChild(button);
2570
+ menuItemsList.appendChild(menuItem);
2571
+ });
2572
+ }
2573
+ function displaySelectedIngredients() {
2574
+ const chatMessages = document.getElementById('chatMessages');
2575
+ if (!chatMessages) {
2576
+ console.error('Chat messages container not found for selected ingredients!');
2577
+ return;
2578
+ }
2579
+ let selectedArea = document.querySelector('.selected-ingredients');
2580
+ if (!selectedArea) {
2581
+ selectedArea = document.createElement('div');
2582
+ selectedArea.className = 'selected-ingredients';
2583
+ chatMessages.appendChild(selectedArea);
2584
+ } else {
2585
+ selectedArea.innerHTML = '';
2586
+ }
2587
+ selectedIngredients.forEach(ingredient => {
2588
+ const div = document.createElement('div');
2589
+ div.textContent = ingredient.name;
2590
+ const removeButton = document.createElement('button');
2591
+ removeButton.textContent = 'X';
2592
+ removeButton.style.marginLeft = '5px';
2593
+ removeButton.style.padding = '2px 5px';
2594
+ removeButton.style.backgroundColor = '#dc3545';
2595
+ removeButton.style.color = '#ffffff';
2596
+ removeButton.style.border = 'none';
2597
+ removeButton.style.borderRadius = '4px';
2598
+ removeButton.style.cursor = 'pointer';
2599
+ removeButton.onclick = () => {
2600
+ selectedIngredients = selectedIngredients.filter(item => item.name !== ingredient.name);
2601
+ displaySelectedIngredients();
2602
+ };
2603
+ div.appendChild(removeButton);
2604
+ selectedArea.appendChild(div);
2605
+ });
2606
+ if (selectedIngredients.length > 0) {
2607
+ let submitButton = document.querySelector('.submit-button');
2608
+ if (!submitButton) {
2609
+ submitButton = document.createElement('button');
2610
+ submitButton.className = 'submit-button';
2611
+ submitButton.textContent = 'Submit Ingredients';
2612
+ submitButton.onclick = submitIngredients;
2613
+ chatMessages.appendChild(submitButton);
2614
+ }
2615
+ }
2616
+ }
2617
+ function submitIngredients() {
2618
+ if (selectedIngredients.length === 0) {
2619
+ addMessage('bot', 'No ingredients selected. Please choose some ingredients.');
2620
+ return;
2621
+ }
2622
+ const ingredientNames = selectedIngredients.map(ingredient => ingredient.name.toLowerCase()).join(' ');
2623
+ fetchMenuItems({ ingredient_names: ingredientNames });
2624
+ }
2625
+ function addToCart(item) {
2626
+ cart.push(item);
2627
+ console.log('Cart:', cart);
2628
+ displayCart();
2629
+ }
2630
+ function displayCart() {
2631
+ const chatMessages = document.getElementById('chatMessages');
2632
+ if (!chatMessages) {
2633
+ console.error('Chat messages container not found for cart!');
2634
+ return;
2635
+ }
2636
+ let cartArea = document.querySelector('.cart-items');
2637
+ if (!cartArea) {
2638
+ cartArea = document.createElement('div');
2639
+ cartArea.className = 'cart-items';
2640
+ chatMessages.appendChild(cartArea);
2641
+ } else {
2642
+ cartArea.innerHTML = '';
2643
+ }
2644
+ if (cart.length > 0) {
2645
+ const label = document.createElement('div');
2646
+ label.textContent = 'Cart:';
2647
+ cartArea.appendChild(label);
2648
+ cart.forEach((item, index) => {
2649
+ const itemDiv = document.createElement('div');
2650
+ itemDiv.className = 'cart-item';
2651
+ const img = document.createElement('img');
2652
+ img.src = item.image_url || 'https://via.placeholder.com/30';
2653
+ img.alt = item.name;
2654
+ const name = document.createElement('div');
2655
+ const text = item.instructions
2656
+ ? `${item.name} (${item.instructions})`
2657
+ : item.name;
2658
+ name.textContent = item.ingredients.length > 0
2659
+ ? `${text} with ${item.ingredients.map(i => i.name).join(', ')}`
2660
+ : text;
2661
+ const removeButton = document.createElement('button');
2662
+ removeButton.className = 'remove-button';
2663
+ removeButton.textContent = 'X';
2664
+ removeButton.onclick = () => {
2665
+ cart.splice(index, 1);
2666
+ displayCart();
2667
+ };
2668
+ itemDiv.appendChild(img);
2669
+ itemDiv.appendChild(name);
2670
+ itemDiv.appendChild(removeButton);
2671
+ cartArea.appendChild(itemDiv);
2672
+ });
2673
+ let submitCartButton = document.querySelector('.submit-cart-button');
2674
+ if (!submitCartButton) {
2675
+ submitCartButton = document.createElement('button');
2676
+ submitCartButton.className = 'submit-cart-button';
2677
+ submitCartButton.textContent = 'Submit Cart';
2678
+ submitCartButton.onclick = submitCart;
2679
+ cartArea.appendChild(submitCartButton);
2680
+ }
2681
+ }
2682
+ }
2683
+ function submitCart() {
2684
+ if (cart.length === 0) {
2685
+ addMessage('bot', 'Your cart is empty!');
2686
+ return;
2687
+ }
2688
+ fetch('/submit_customization_ingredients', {
2689
+ method: 'POST',
2690
+ headers: { 'Content-Type': 'application/json' },
2691
+ body: JSON.stringify({ items: cart })
2692
+ })
2693
+ .then(response => response.json())
2694
+ .then(data => {
2695
+ if (data.success) {
2696
+ addMessage('bot', 'Cart submitted successfully!');
2697
+ cart = [];
2698
+ displayCart();
2699
+ } else {
2700
+ addMessage('bot', `Error submitting cart: ${data.error}`);
2701
+ }
2702
+ })
2703
+ .catch(error => {
2704
+ addMessage('bot', `Error submitting cart: ${error.message}`);
2705
+ });
2706
+ }
2707
+ function displayOptions(options) {
2708
+ const chatMessages = document.getElementById('chatMessages');
2709
+ if (!chatMessages) {
2710
+ console.error('Chat messages container not found for options!');
2711
+ return;
2712
+ }
2713
+ options.forEach(opt => {
2714
+ const button = document.createElement('button');
2715
+ button.textContent = opt.text;
2716
+ button.className = `option-button ${opt.class}`;
2717
+ button.onclick = () => {
2718
+ addMessage('user', opt.text);
2719
+ conversation.push({ role: 'user', message: opt.text });
2720
+ setTimeout(() => handleResponse(opt.text), 500);
2721
+ };
2722
+ chatMessages.appendChild(button);
2723
+ });
2724
+ chatMessages.appendChild(document.createElement('br'));
2725
+ const backButton = document.createElement('button');
2726
+ backButton.textContent = 'Go Back';
2727
+ backButton.className = 'option-button';
2728
+ backButton.onclick = () => {
2729
+ conversation.pop();
2730
+ selectedIngredients = [];
2731
+ selectedMenuItem = null;
2732
+ setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
2733
+ };
2734
+ chatMessages.appendChild(backButton);
2735
+ chatMessages.scrollTop = chatMessages.scrollHeight;
2736
+ }
2737
+ document.getElementById('userInput').addEventListener('keypress', function(e) {
2738
+ if (e.key === 'Enter') {
2739
+ sendMessage();
2740
+ }
2741
+ });
2742
+ console.log('Script loaded successfully');
2743
  </script>
2744
  </body>
2745
  </html>