nagasurendra commited on
Commit
f78f3a8
·
verified ·
1 Parent(s): 5b2f47a

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +944 -17
templates/menu.html CHANGED
@@ -1190,6 +1190,320 @@
1190
  font-size: 0.9rem;
1191
  }
1192
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1193
  </style>
1194
  </head>
1195
  <body>
@@ -1201,7 +1515,6 @@
1201
  <div class="dropdown-menu">
1202
  <a href="{{ url_for('user_details.customer_details') }}" class="dropdown-item">View Profile</a>
1203
  <a href="{{ url_for('orderhistory.order_history') }}" class="dropdown-item">Order History</a>
1204
- <a href="{{ url_for('combined_summary.combined_summary') }}" class="dropdown-item">MY Summary</a>
1205
  <a href="{{ url_for('logout') }}" class="dropdown-item">Logout</a>
1206
  </div>
1207
  </div>
@@ -1211,33 +1524,40 @@
1211
  <i class="bi bi-mic mic-icon" id="micIcon"></i>
1212
  </div>
1213
  </div>
1214
- <form method="get" action="/menu" class="text-center mb-4" id="filter-form">
1215
  <label class="form-label fw-bold">Filters:</label>
1216
  <div class="toggle-container">
1217
- <input type="checkbox" id="veg-toggle" name="veg" {% if selected_category == "Veg" %}checked{% endif %} class="custom-toggle" onchange="handleToggle('veg')" aria-label="Toggle Vegetarian filter">
 
 
 
 
1218
  <label for="veg-toggle">Veg</label>
1219
  </div>
1220
  <div class="toggle-container">
1221
- <input type="radio" id="category-CustomizedDish" name="category" value="Customized Dish" {% if selected_category == "Customized Dish" %}checked{% endif %} class="custom-toggle" onchange="handleToggle('custom')" aria-label="Toggle Customized Dish filter">
 
 
 
 
1222
  <label for="category-CustomizedDish">Customized Dish</label>
1223
  </div>
1224
  </form>
 
 
1225
  <div class="container mt-4">
1226
  {% if selected_category == "Customized Dish" %}
1227
  <div id="custom-dish-form" class="mt-4">
1228
- <h3>Create Your Custom Dish</h3>
1229
- <form method="POST" action="/customdish/generate_custom_dish">
1230
- <div class="mb-3">
1231
- <label for="custom-dish-name" class="form-label">Dish Name</label>
1232
- <input type="text" class="form-control" id="custom-dish-name" name="name" required>
1233
- </div>
1234
- <div class="mb-3 position-relative">
1235
- <label for="custom-dish-description" class="form-label">Dish Description</label>
1236
- <textarea class="form-control" id="custom-dish-description" name="description" required></textarea>
1237
- <div id="descriptionSuggestions" class="autocomplete-suggestions"></div>
1238
- </div>
1239
- <button type="submit" class="btn btn-primary">Submit Custom Dish</button>
1240
- </form>
1241
  </div>
1242
  {% else %}
1243
  {% if ordered_menu.items()|length == 0 %}
@@ -1542,6 +1862,7 @@
1542
  cartItemCount.style.display = totalQuantity > 0 ? 'inline-flex' : 'none';
1543
  }
1544
  }
 
1545
  function showItemDetails(name, price, image, description, section, selectedCategory) {
1546
  document.getElementById('modal-name').innerText = name;
1547
  baseItemPrice = parseFloat(price) || 0;
@@ -1616,6 +1937,41 @@
1616
  }
1617
  });
1618
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1619
  })
1620
  .catch(err => {
1621
  console.error('Error fetching add-ons:', err);
@@ -1984,6 +2340,577 @@
1984
  }
1985
  updateCartUI(getCartLocalStorage());
1986
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1987
  </script>
1988
  </body>
1989
  </html>
 
1190
  font-size: 0.9rem;
1191
  }
1192
  }
1193
+ .chat-container {
1194
+ box-sizing: border-box;
1195
+ margin: 0;
1196
+ padding: 0;
1197
+ }
1198
+ body {
1199
+ font-family: 'Segoe UI', Arial, sans-serif;
1200
+ background-color: #f4f7fa;
1201
+ overflow-x: hidden;
1202
+ line-height: 1.5;
1203
+ }
1204
+ .chat-container {
1205
+ width: 100%;
1206
+ max-width: 800px;
1207
+ height: 100vh;
1208
+ margin: 0 auto;
1209
+ background-color: #ffffff;
1210
+ border-radius: 12px;
1211
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
1212
+ display: flex;
1213
+ flex-direction: column;
1214
+ overflow: hidden;
1215
+ }
1216
+ .chat-header {
1217
+ background-color: #0078d4;
1218
+ color: #ffffff;
1219
+ padding: 12px;
1220
+ text-align: center;
1221
+ font-size: 18px;
1222
+ font-weight: 600;
1223
+ flex-shrink: 0;
1224
+ }
1225
+ .chat-messages {
1226
+ flex: 1;
1227
+ overflow-y: auto;
1228
+ padding: 15px;
1229
+ scroll-behavior: smooth;
1230
+ }
1231
+ .bot-message, .user-message {
1232
+ padding: 10px 15px;
1233
+ margin: 8px 0;
1234
+ border-radius: 12px;
1235
+ max-width: 80%;
1236
+ font-size: 14px;
1237
+ line-height: 1.4;
1238
+ }
1239
+ .bot-message {
1240
+ background-color: #e8f0fe;
1241
+ color: #333;
1242
+ }
1243
+ .user-message {
1244
+ background-color: #0078d4;
1245
+ color: #ffffff;
1246
+ margin-left: auto;
1247
+ }
1248
+ .chat-input {
1249
+ display: flex;
1250
+ padding: 10px;
1251
+ border-top: 1px solid #e0e0e0;
1252
+ background-color: #f9f9f9;
1253
+ flex-shrink: 0;
1254
+ }
1255
+ .chat-input input {
1256
+ flex: 1;
1257
+ padding: 10px;
1258
+ border: 1px solid #ccc;
1259
+ border-radius: 8px;
1260
+ font-size: 14px;
1261
+ outline: none;
1262
+ }
1263
+ .chat-input button {
1264
+ padding: 10px 20px;
1265
+ margin-left: 10px;
1266
+ background-color: #0078d4;
1267
+ color: #ffffff;
1268
+ border: none;
1269
+ border-radius: 8px;
1270
+ cursor: pointer;
1271
+ font-size: 14px;
1272
+ transition: background-color 0.2s;
1273
+ }
1274
+ .chat-input button:hover {
1275
+ background-color: #005ea2;
1276
+ }
1277
+ .ingredients-list, .menu-items-list, .customization-ingredients-list {
1278
+ display: flex;
1279
+ flex-wrap: nowrap; /* Ensure items stay in a single row */
1280
+ overflow-x: auto; /* Allow horizontal scrolling */
1281
+ padding: 10px;
1282
+ margin: 10px 0;
1283
+ background-color: #f5f7fa;
1284
+ border-radius: 10px;
1285
+ gap: 15px;
1286
+ scroll-behavior: smooth;
1287
+ }
1288
+ .ingredient-item, .menu-item {
1289
+ flex: 0 0 auto; /* Ensure items don't stretch */
1290
+ width: 200px; /* Set a fixed width for each item */
1291
+ background-color: #ffffff;
1292
+ border: 1px solid #e0e0e0;
1293
+ border-radius: 10px;
1294
+ padding: 10px;
1295
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
1296
+ transition: transform 0.2s;
1297
+ text-align: center;
1298
+ }
1299
+ .ingredient-item:hover, .menu-item:hover {
1300
+ transform: translateY(-2px);
1301
+ }
1302
+ .ingredient-item img, .menu-item img {
1303
+ width: 100%;
1304
+ height: 120px;
1305
+ object-fit: cover;
1306
+ border-radius: 8px;
1307
+ margin-bottom: 8px;
1308
+ }
1309
+ .ingredient-item div, .menu-item div {
1310
+ font-size: 14px;
1311
+ font-weight: 600;
1312
+ color: #333;
1313
+ margin-bottom: 5px;
1314
+ }
1315
+ .ingredient-item button, .menu-item button {
1316
+ padding: 8px;
1317
+ background-color: #28a745;
1318
+ color: #ffffff;
1319
+ border: none;
1320
+ border-radius: 6px;
1321
+ cursor: pointer;
1322
+ font-size: 12px;
1323
+ width: 100%;
1324
+ }
1325
+ .ingredient-item button:hover, .menu-item button:hover {
1326
+ background-color: #218838;
1327
+ }
1328
+ .selected-ingredients, .selected-customization-ingredients {
1329
+ background-color: #f1f8ff;
1330
+ padding: 15px;
1331
+ border: 1px solid #b3d7ff;
1332
+ border-radius: 10px;
1333
+ margin: 10px 0;
1334
+ font-size: 14px;
1335
+ display: flex;
1336
+ flex-wrap: wrap;
1337
+ gap: 10px;
1338
+ }
1339
+ .selected-ingredients div, .selected-customization-ingredients div {
1340
+ background-color: #d6e9ff;
1341
+ padding: 5px 10px;
1342
+ border-radius: 6px;
1343
+ font-size: 13px;
1344
+ }
1345
+ .customization-input {
1346
+ margin: 10px 0;
1347
+ }
1348
+ .customization-input textarea, .selected-customization-ingredients textarea {
1349
+ width: 100%;
1350
+ padding: 8px;
1351
+ border: 1px solid #b3d7ff;
1352
+ border-radius: 6px;
1353
+ font-size: 14px;
1354
+ outline: none;
1355
+ margin-bottom: 10px;
1356
+ }
1357
+ .customization-input button, .submit-button, .submit-customization-button, .submit-cart-button {
1358
+ padding: 10px 20px;
1359
+ background-color: #0078d4;
1360
+ color: #ffffff;
1361
+ border: none;
1362
+ border-radius: 8px;
1363
+ cursor: pointer;
1364
+ font-size: 14px;
1365
+ transition: background-color 0.2s;
1366
+ }
1367
+ .customization-input button:hover, .submit-button:hover, .submit-customization-button:hover, .submit-cart-button:hover {
1368
+ background-color: #005ea2;
1369
+ }
1370
+ .option-button {
1371
+ padding: 10px 20px;
1372
+ color: #ffffff;
1373
+ border: none;
1374
+ border-radius: 8px;
1375
+ cursor: pointer;
1376
+ font-size: 14px;
1377
+ margin: 5px;
1378
+ transition: background-color 0.2s;
1379
+ }
1380
+ .option-button.green {
1381
+ background-color: #28a745;
1382
+ }
1383
+ .option-button.green:hover {
1384
+ background-color: #218838;
1385
+ }
1386
+ .option-button.red {
1387
+ background-color: #dc3545;
1388
+ }
1389
+ .option-button.red:hover {
1390
+ background-color: #c82333;
1391
+ }
1392
+ .cart-items {
1393
+ background-color: #f1f8ff;
1394
+ padding: 15px;
1395
+ border: 1px solid #b3d7ff;
1396
+ border-radius: 10px;
1397
+ margin: 10px 0;
1398
+ font-size: 14px;
1399
+ }
1400
+ .cart-item {
1401
+ display: flex;
1402
+ align-items: center;
1403
+ background-color: #d6e9ff;
1404
+ padding: 5px 10px;
1405
+ border-radius: 6px;
1406
+ font-size: 13px;
1407
+ margin: 5px 0;
1408
+ }
1409
+ .cart-item img {
1410
+ width: 30px;
1411
+ height: 30px;
1412
+ object-fit: cover;
1413
+ border-radius: 6px;
1414
+ margin-right: 8px;
1415
+ }
1416
+ .cart-item .remove-button {
1417
+ padding: 5px 10px;
1418
+ margin-left: 8px;
1419
+ background-color: #dc3545;
1420
+ color: #ffffff;
1421
+ border: none;
1422
+ border-radius: 6px;
1423
+ cursor: pointer;
1424
+ font-size: 12px;
1425
+ }
1426
+ .cart-item .remove-button:hover {
1427
+ background-color: #c82333;
1428
+ }
1429
+ /* Responsive Design */
1430
+ @media (max-width: 480px) {
1431
+ .chat-container {
1432
+ border-radius: 0;
1433
+ box-shadow: none;
1434
+ }
1435
+ .chat-header {
1436
+ font-size: 16px;
1437
+ padding: 10px;
1438
+ }
1439
+ .chat-messages {
1440
+ padding: 10px;
1441
+ }
1442
+ .bot-message, .user-message {
1443
+ font-size: 13px;
1444
+ padding: 8px 12px;
1445
+ margin: 5px 0;
1446
+ }
1447
+ .chat-input input {
1448
+ font-size: 13px;
1449
+ padding: 8px;
1450
+ }
1451
+ .chat-input button {
1452
+ font-size: 13px;
1453
+ padding: 8px 15px;
1454
+ }
1455
+ .ingredients-list, .menu-items-list, .customization-ingredients-list {
1456
+ flex-direction: row; /* Keep the items in a row on mobile */
1457
+ gap: 10px;
1458
+ }
1459
+ .ingredient-item, .menu-item {
1460
+ flex: 0 0 150px; /* Adjust the item width to fit smaller screens */
1461
+ }
1462
+ .ingredient-item img, .menu-item img {
1463
+ height: 100px;
1464
+ }
1465
+ .ingredient-item div, .menu-item div {
1466
+ font-size: 13px;
1467
+ }
1468
+ .ingredient-item button, .menu-item button {
1469
+ font-size: 11px;
1470
+ padding: 6px;
1471
+ }
1472
+ .option-button {
1473
+ font-size: 13px;
1474
+ padding: 8px 15px;
1475
+ }
1476
+ .selected-ingredients, .selected-customization-ingredients, .cart-items {
1477
+ padding: 10px;
1478
+ gap: 8px;
1479
+ }
1480
+ .cart-item {
1481
+ font-size: 12px;
1482
+ padding: 4px 8px;
1483
+ }
1484
+ .cart-item img {
1485
+ width: 25px;
1486
+ height: 25px;
1487
+ }
1488
+ }
1489
+ @media (min-width: 481px) and (max-width: 768px) {
1490
+ .chat-container {
1491
+ max-width: 600px;
1492
+ }
1493
+ .chat-header {
1494
+ font-size: 17px;
1495
+ padding: 11px;
1496
+ }
1497
+ .chat-messages {
1498
+ padding: 12px;
1499
+ }
1500
+ .ingredient-item, .menu-item {
1501
+ flex: 0 0 180px;
1502
+ }
1503
+ .ingredient-item img, .menu-item img {
1504
+ height: 110px;
1505
+ }
1506
+ }
1507
  </style>
1508
  </head>
1509
  <body>
 
1515
  <div class="dropdown-menu">
1516
  <a href="{{ url_for('user_details.customer_details') }}" class="dropdown-item">View Profile</a>
1517
  <a href="{{ url_for('orderhistory.order_history') }}" class="dropdown-item">Order History</a>
 
1518
  <a href="{{ url_for('logout') }}" class="dropdown-item">Logout</a>
1519
  </div>
1520
  </div>
 
1524
  <i class="bi bi-mic mic-icon" id="micIcon"></i>
1525
  </div>
1526
  </div>
1527
+ <form method="get" action="/menu" class="text-center mb-4" id="filter-form">
1528
  <label class="form-label fw-bold">Filters:</label>
1529
  <div class="toggle-container">
1530
+ <!-- Veg Only Toggle -->
1531
+ <input type="checkbox" id="veg-toggle" name="veg"
1532
+ {% if selected_category == "Veg" %}checked{% endif %}
1533
+ class="custom-toggle" onchange="handleToggle('veg')"
1534
+ aria-label="Toggle Vegetarian filter">
1535
  <label for="veg-toggle">Veg</label>
1536
  </div>
1537
  <div class="toggle-container">
1538
+ <!-- Customized Dish Toggle -->
1539
+ <input type="radio" id="category-CustomizedDish" name="category" value="Customized Dish"
1540
+ {% if selected_category == "Customized Dish" %}checked{% endif %}
1541
+ class="custom-toggle" onchange="handleToggle('custom')"
1542
+ aria-label="Toggle Customized Dish filter">
1543
  <label for="category-CustomizedDish">Customized Dish</label>
1544
  </div>
1545
  </form>
1546
+
1547
+
1548
  <div class="container mt-4">
1549
  {% if selected_category == "Customized Dish" %}
1550
  <div id="custom-dish-form" class="mt-4">
1551
+ <div class="chat-container">
1552
+ <div class="chat-header">🍳 Chef Bot</div>
1553
+ <div class="chat-messages" id="chatMessages">
1554
+ <!-- Initial message will be set by JavaScript based on session -->
1555
+ </div>
1556
+ <div class="chat-input">
1557
+ <input type="text" id="userInput" placeholder="Type your name or message...">
1558
+ <button onclick="sendMessage()">Send</button>
1559
+ </div>
1560
+ </div>
 
 
 
1561
  </div>
1562
  {% else %}
1563
  {% if ordered_menu.items()|length == 0 %}
 
1862
  cartItemCount.style.display = totalQuantity > 0 ? 'inline-flex' : 'none';
1863
  }
1864
  }
1865
+ window.most_common_addons = {{ most_common_addons | tojson }};
1866
  function showItemDetails(name, price, image, description, section, selectedCategory) {
1867
  document.getElementById('modal-name').innerText = name;
1868
  baseItemPrice = parseFloat(price) || 0;
 
1937
  }
1938
  });
1939
  });
1940
+ if (window.most_common_addons && window.most_common_addons.length > 0) {
1941
+ const checkboxes = document.querySelectorAll('.addon-option');
1942
+ const categorySelection = {
1943
+ "Select Spice Level": null,
1944
+ "Choose Spice Level": null,
1945
+ "Raita/Sides": [],
1946
+ };
1947
+ // First pass: Find and select the highest-count spice level
1948
+ for (let spice of window.most_common_addons) {
1949
+ const isSpiceLevel = ["Mild", "Medium", "Spicy", "Extra Spicy"].includes(spice); // Define valid spice levels
1950
+ if (isSpiceLevel) {
1951
+ checkboxes.forEach(checkbox => {
1952
+ const checkboxName = checkbox.getAttribute('data-name').trim();
1953
+ const checkboxGroup = checkbox.getAttribute('data-group');
1954
+ if ((checkboxGroup === "Select Spice Level" || checkboxGroup === "Choose Spice Level") &&
1955
+ checkboxName === spice && categorySelection[checkboxGroup] === null) {
1956
+ console.log(`Pre-selecting highest-count spice level: ${checkboxName}`);
1957
+ checkbox.checked = true;
1958
+ categorySelection[checkboxGroup] = checkboxName;
1959
+ }
1960
+ });
1961
+ if (categorySelection["Select Spice Level"] || categorySelection["Choose Spice Level"]) break; // Stop after selecting the first spice
1962
+ }
1963
+ }
1964
+ // Second pass: Select other non-spice add-ons (e.g., Raita/Sides)
1965
+ checkboxes.forEach(checkbox => {
1966
+ const checkboxName = checkbox.getAttribute('data-name').trim();
1967
+ const checkboxGroup = checkbox.getAttribute('data-group');
1968
+ if (checkboxGroup === "Raita/Sides" && window.most_common_addons.includes(checkboxName)) {
1969
+ console.log(`Pre-selecting add-on: ${checkboxName}`);
1970
+ checkbox.checked = true;
1971
+ categorySelection["Raita/Sides"].push(checkboxName);
1972
+ }
1973
+ });
1974
+ }
1975
  })
1976
  .catch(err => {
1977
  console.error('Error fetching add-ons:', err);
 
2340
  }
2341
  updateCartUI(getCartLocalStorage());
2342
  });
2343
+ let currentStep = 'greeting'; // other possible values: 'food_type', 'select_ingredients', 'menu_display', 'customization', 'post_cart'
2344
+ let conversation = [];
2345
+ let selectedIngredients = [];
2346
+ let selectedMenuItem = null;
2347
+ let cart = [];
2348
+ // Get the user name passed from Flask (via Jinja)
2349
+ const userName = "{{ user_name }}"; // Jinja syntax to inject user_name from Flask session
2350
+ window.onload = function() {
2351
+ if (userName) {
2352
+ // If user_name exists, greet the user directly and proceed to food preference
2353
+ conversation.push({ role: 'bot', message: `Nice to meet you, ${userName}! 😊 Let's create your perfect meal! What type of food would you prefer?` });
2354
+ displayConversation(); // Display the current conversation
2355
+ displayOptions([
2356
+ { text: 'Vegetarian', class: 'green' },
2357
+ { text: 'Non-Vegetarian', class: 'red' }
2358
+ ]);
2359
+ } else {
2360
+ // Ask for the name if it's not found
2361
+ conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
2362
+ displayConversation(); // Display the conversation
2363
+ }
2364
+ };
2365
+ // Function to add messages to the chat
2366
+ function addMessage(role, message) {
2367
+ const chatMessages = document.getElementById('chatMessages');
2368
+ if (!chatMessages) {
2369
+ console.error('Chat messages container not found!');
2370
+ return;
2371
+ }
2372
+ const messageDiv = document.createElement('div');
2373
+ messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message';
2374
+ messageDiv.textContent = message;
2375
+ chatMessages.appendChild(messageDiv);
2376
+ chatMessages.scrollTop = chatMessages.scrollHeight;
2377
+ }
2378
+ // Function to display all conversation messages
2379
+ function displayConversation() {
2380
+ const chatMessages = document.getElementById('chatMessages');
2381
+ chatMessages.innerHTML = ''; // Clear previous messages
2382
+ conversation.forEach(msg => {
2383
+ const messageDiv = document.createElement('div');
2384
+ messageDiv.className = msg.role === 'bot' ? 'bot-message' : 'user-message';
2385
+ messageDiv.textContent = msg.message;
2386
+ chatMessages.appendChild(messageDiv);
2387
+ });
2388
+ chatMessages.scrollTop = chatMessages.scrollHeight; // Scroll to bottom
2389
+ }
2390
+ // Function to handle user input
2391
+ function sendMessage() {
2392
+ const userInput = document.getElementById('userInput').value.trim();
2393
+ if (userInput) {
2394
+ addMessage('user', userInput);
2395
+ conversation.push({ role: 'user', message: userInput });
2396
+ document.getElementById('userInput').value = ''; // Clear input field
2397
+ setTimeout(() => handleResponse(userInput), 500);
2398
+ } else {
2399
+ console.warn('Empty message!');
2400
+ }
2401
+ }
2402
+ function handleResponse(userInput) {
2403
+ const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
2404
+ let botResponse = '';
2405
+ let options = [];
2406
+ // If user has already selected food type, proceed without repeating the question
2407
+ if (lastMessage.includes('non-vegetarian')) {
2408
+ conversation.push({ role: 'user', message: 'Non-Vegetarian' });
2409
+ console.log("Food preference selected: Non-Vegetarian");
2410
+ botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
2411
+ fetchIngredients('non-vegetarian');
2412
+ return;
2413
+ } else if (lastMessage.includes('vegetarian')) {
2414
+ conversation.push({ role: 'user', message: 'Vegetarian' });
2415
+ console.log("Food preference selected: Vegetarian");
2416
+ botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
2417
+ fetchIngredients('vegetarian');
2418
+ return;
2419
+ } else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
2420
+ conversation.push({ role: 'user', message: lastMessage });
2421
+ console.log(`Non-veg option selected: ${lastMessage}`);
2422
+ botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
2423
+ fetchIngredients(lastMessage.toLowerCase());
2424
+ return;
2425
+ } else if (lastMessage.includes('yes') && selectedMenuItem) {
2426
+ botResponse = 'Here are some ingredients to customize your dish:';
2427
+ handleYesResponse();
2428
+ return;
2429
+ } else if (lastMessage.includes('no') && selectedMenuItem) {
2430
+ // Submit the dish without customization
2431
+ submitCustomizationIngredients();
2432
+ return;
2433
+ } else if (lastMessage.includes('yes') && currentStep === 'post_cart') {
2434
+ // After user says 'yes', ask again for food preference (veg or non-veg)
2435
+ botResponse = `Let's get started again! What type of food would you prefer this time?`;
2436
+ options = [
2437
+ { text: 'Vegetarian', class: 'green' },
2438
+ { text: 'Non-Vegetarian', class: 'red' }
2439
+ ];
2440
+ currentStep = 'food_type';
2441
+ addMessage('bot', botResponse);
2442
+ displayOptions(options);
2443
+ return;
2444
+ } else if (lastMessage.includes('non-vegetarian') && currentStep === 'food_type') {
2445
+ // Handle non-vegetarian selection
2446
+ conversation.push({ role: 'user', message: 'Non-Vegetarian' });
2447
+ console.log("Food preference selected: Non-Vegetarian");
2448
+ botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
2449
+ fetchIngredients('non-vegetarian');
2450
+ return;
2451
+ } else if (lastMessage.includes('vegetarian') && currentStep === 'food_type') {
2452
+ // Handle vegetarian selection
2453
+ conversation.push({ role: 'user', message: 'Vegetarian' });
2454
+ console.log("Food preference selected: Vegetarian");
2455
+ botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
2456
+ fetchIngredients('vegetarian');
2457
+ return;
2458
+ } else if (lastMessage.includes('no') && currentStep === 'post_cart') {
2459
+ addMessage('bot', 'Awesome! 🧾 Here’s your final cart:');
2460
+ displayCart(); // Optional: show final cart again
2461
+ addMessage('bot', 'Thank you for your order! 👨‍🍳🍲');
2462
+ currentStep = 'end';
2463
+ return;
2464
+ }
2465
+ addMessage('bot', botResponse);
2466
+ if (options.length > 0) {
2467
+ displayOptions(options);
2468
+ }
2469
+ displayCart();
2470
+ }
2471
+ function handleYesResponse() {
2472
+ if (!selectedMenuItem) {
2473
+ addMessage('bot', 'No dish selected. Please choose a dish first.');
2474
+ return;
2475
+ }
2476
+ const botResponse = `Here is your selected dish: ${selectedMenuItem.name}`;
2477
+ addMessage('bot', botResponse);
2478
+ // Display selected menu item
2479
+ const chatMessages = document.getElementById('chatMessages');
2480
+ const menuItemDiv = document.createElement('div');
2481
+ menuItemDiv.className = 'menu-item';
2482
+ const img = document.createElement('img');
2483
+ img.src = selectedMenuItem.image_url || 'https://via.placeholder.com/120';
2484
+ img.alt = selectedMenuItem.name;
2485
+ const name = document.createElement('div');
2486
+ name.textContent = selectedMenuItem.name;
2487
+ menuItemDiv.appendChild(img);
2488
+ menuItemDiv.appendChild(name);
2489
+ chatMessages.appendChild(menuItemDiv);
2490
+ // Fetch ingredients for customization
2491
+ fetchIngredientsForCustomization('both');
2492
+ }
2493
+ function fetchIngredientsForCustomization(foodPreference) {
2494
+ fetch('/get_ingredients', { // Reuse existing endpoint
2495
+ method: 'POST',
2496
+ headers: { 'Content-Type': 'application/json' },
2497
+ body: JSON.stringify({ dietary_preference: foodPreference })
2498
+ })
2499
+ .then(response => response.json())
2500
+ .then(data => {
2501
+ if (data.error) {
2502
+ addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
2503
+ } else {
2504
+ const ingredients = data.ingredients || [];
2505
+ addMessage('bot', 'Please select ingredients to customize:');
2506
+ displayCustomizationIngredients(ingredients);
2507
+ }
2508
+ })
2509
+ .catch(error => {
2510
+ addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
2511
+ });
2512
+ }
2513
+ function displayCustomizationIngredients(ingredients) {
2514
+ const chatMessages = document.getElementById('chatMessages');
2515
+ if (!chatMessages) {
2516
+ console.error('Chat messages container not found for customization ingredients!');
2517
+ return;
2518
+ }
2519
+ let ingredientsList = document.querySelector('.customization-ingredients-list');
2520
+ if (!ingredientsList) {
2521
+ ingredientsList = document.createElement('div');
2522
+ ingredientsList.className = 'customization-ingredients-list';
2523
+ chatMessages.appendChild(ingredientsList);
2524
+ } else {
2525
+ ingredientsList.innerHTML = '';
2526
+ }
2527
+ ingredients.forEach(ingredient => {
2528
+ const item = document.createElement('div');
2529
+ item.className = 'ingredient-item';
2530
+ const img = document.createElement('img');
2531
+ img.src = ingredient.image_url || 'https://via.placeholder.com/120';
2532
+ img.alt = ingredient.name;
2533
+ const name = document.createElement('div');
2534
+ name.textContent = ingredient.name;
2535
+ const button = document.createElement('button');
2536
+ button.textContent = 'Add';
2537
+ button.onclick = () => {
2538
+ if (!selectedIngredients.some(item => item.name === ingredient.name)) {
2539
+ selectedIngredients.push({ name: ingredient.name, image_url: ingredient.image_url });
2540
+ displaySelectedCustomizationIngredients();
2541
+ }
2542
+ };
2543
+ item.appendChild(img);
2544
+ item.appendChild(name);
2545
+ item.appendChild(button);
2546
+ ingredientsList.appendChild(item);
2547
+ });
2548
+ displaySelectedCustomizationIngredients();
2549
+ }
2550
+ function displaySelectedCustomizationIngredients() {
2551
+ const chatMessages = document.getElementById('chatMessages');
2552
+ if (!chatMessages) {
2553
+ console.error('Chat messages container not found for selected customization ingredients!');
2554
+ return;
2555
+ }
2556
+ let selectedArea = document.querySelector('.selected-customization-ingredients');
2557
+ if (!selectedArea) {
2558
+ selectedArea = document.createElement('div');
2559
+ selectedArea.className = 'selected-customization-ingredients';
2560
+ chatMessages.appendChild(selectedArea);
2561
+ } else {
2562
+ selectedArea.innerHTML = '';
2563
+ }
2564
+ const selectedIngredientsText = selectedIngredients.length > 0
2565
+ ? `${selectedMenuItem.name} with ${selectedIngredients.map(ingredient => ingredient.name).join(', ')}`
2566
+ : selectedMenuItem.name;
2567
+ const ingredientsDiv = document.createElement('div');
2568
+ ingredientsDiv.textContent = selectedIngredientsText;
2569
+ selectedArea.appendChild(ingredientsDiv);
2570
+ selectedIngredients.forEach(ingredient => {
2571
+ const div = document.createElement('div');
2572
+ div.textContent = ingredient.name;
2573
+ const removeButton = document.createElement('button');
2574
+ removeButton.textContent = 'X';
2575
+ removeButton.style.marginLeft = '5px';
2576
+ removeButton.style.padding = '2px 5px';
2577
+ removeButton.style.backgroundColor = '#dc3545';
2578
+ removeButton.style.color = '#ffffff';
2579
+ removeButton.style.border = 'none';
2580
+ removeButton.style.borderRadius = '4px';
2581
+ removeButton.style.cursor = 'pointer';
2582
+ removeButton.onclick = () => {
2583
+ selectedIngredients = selectedIngredients.filter(item => item.name !== ingredient.name);
2584
+ displaySelectedCustomizationIngredients();
2585
+ };
2586
+ div.appendChild(removeButton);
2587
+ selectedArea.appendChild(div);
2588
+ });
2589
+ if (!document.querySelector('.submit-customization-button')) {
2590
+ const textarea = document.createElement('textarea');
2591
+ textarea.placeholder = 'Enter any special instructions...';
2592
+ selectedArea.appendChild(textarea);
2593
+ const submitButton = document.createElement('button');
2594
+ submitButton.className = 'submit-customization-button';
2595
+ submitButton.textContent = 'Submit Customization';
2596
+ submitButton.onclick = submitCustomizationIngredients;
2597
+ selectedArea.appendChild(submitButton);
2598
+ }
2599
+ }
2600
+ function submitCustomizationIngredients() {
2601
+ if (!selectedMenuItem) {
2602
+ addMessage('bot', 'No dish selected. Please choose a dish first.');
2603
+ return;
2604
+ }
2605
+
2606
+ const textarea = document.querySelector('.selected-customization-ingredients textarea');
2607
+ const instructions = textarea ? textarea.value.trim() : '';
2608
+
2609
+ fetch('/submit_customization_ingredients', {
2610
+ method: 'POST',
2611
+ headers: { 'Content-Type': 'application/json' },
2612
+ body: JSON.stringify({
2613
+ menu_item: selectedMenuItem,
2614
+ ingredients: selectedIngredients,
2615
+ instructions: instructions
2616
+ })
2617
+ })
2618
+ .then(response => response.json())
2619
+ .then(data => {
2620
+ if (data.success) {
2621
+ addToCart({ ...selectedMenuItem, instructions, ingredients: selectedIngredients });
2622
+ currentStep = 'post_cart';
2623
+ addMessage('bot', 'Customization submitted successfully! Item added to cart.');
2624
+
2625
+ // Redirect to the cart page
2626
+ window.location.href = '/cart/cart'; // This will redirect the user to the cart page
2627
+ } else {
2628
+ addMessage('bot', `Error: ${data.error}`);
2629
+ }
2630
+ })
2631
+ .catch(error => {
2632
+ addMessage('bot', `Error submitting customization: ${error.message}`);
2633
+ });
2634
+ }
2635
+ function fetchIngredients(foodPreference) {
2636
+ fetch('/get_ingredients', {
2637
+ method: 'POST',
2638
+ headers: { 'Content-Type': 'application/json' },
2639
+ body: JSON.stringify({ dietary_preference: foodPreference })
2640
+ })
2641
+ .then(response => response.json())
2642
+ .then(data => {
2643
+ if (data.error) {
2644
+ addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
2645
+ } else {
2646
+ const ingredients = data.ingredients || [];
2647
+ addMessage('bot', 'Please select ingredients:');
2648
+ displayIngredientsList(ingredients);
2649
+ displaySelectedIngredients();
2650
+ }
2651
+ })
2652
+ .catch(error => {
2653
+ addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
2654
+ });
2655
+ }
2656
+ function fetchMenuItems(params) {
2657
+ fetch('/get_menu_items', {
2658
+ method: 'POST',
2659
+ headers: { 'Content-Type': 'application/json' },
2660
+ body: JSON.stringify(params)
2661
+ })
2662
+ .then(response => response.json())
2663
+ .then(data => {
2664
+ if (data.error) {
2665
+ addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
2666
+ } else {
2667
+ const menuItems = data.menu_items || [];
2668
+ addMessage('bot', 'Here are some dishes based on your selection:');
2669
+ displayMenuItems(menuItems);
2670
+ }
2671
+ })
2672
+ .catch(error => {
2673
+ addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
2674
+ });
2675
+ }
2676
+ function displayIngredientsList(ingredients) {
2677
+ const chatMessages = document.getElementById('chatMessages');
2678
+ if (!chatMessages) {
2679
+ console.error('Chat messages container not found for ingredients!');
2680
+ return;
2681
+ }
2682
+ let ingredientsList = document.querySelector('.ingredients-list');
2683
+ if (!ingredientsList) {
2684
+ ingredientsList = document.createElement('div');
2685
+ ingredientsList.className = 'ingredients-list';
2686
+ chatMessages.appendChild(ingredientsList);
2687
+ } else {
2688
+ ingredientsList.innerHTML = '';
2689
+ }
2690
+ ingredients.forEach(ingredient => {
2691
+ const item = document.createElement('div');
2692
+ item.className = 'ingredient-item';
2693
+ const img = document.createElement('img');
2694
+ img.src = ingredient.image_url || 'https://via.placeholder.com/120';
2695
+ img.alt = ingredient.name;
2696
+ const name = document.createElement('div');
2697
+ name.textContent = ingredient.name;
2698
+ const button = document.createElement('button');
2699
+ button.textContent = 'Add';
2700
+ button.onclick = () => {
2701
+ if (!selectedIngredients.some(item => item.name === ingredient.name)) {
2702
+ selectedIngredients.push(ingredient);
2703
+ displaySelectedIngredients();
2704
+ }
2705
+ };
2706
+ item.appendChild(img);
2707
+ item.appendChild(name);
2708
+ item.appendChild(button);
2709
+ ingredientsList.appendChild(item);
2710
+ });
2711
+ }
2712
+ function displayMenuItems(menuItems) {
2713
+ const chatMessages = document.getElementById('chatMessages');
2714
+ if (!chatMessages) {
2715
+ console.error('Chat messages container not found for menu items!');
2716
+ return;
2717
+ }
2718
+ let menuItemsList = document.querySelector('.menu-items-list');
2719
+ if (!menuItemsList) {
2720
+ menuItemsList = document.createElement('div');
2721
+ menuItemsList.className = 'menu-items-list';
2722
+ chatMessages.appendChild(menuItemsList);
2723
+ } else {
2724
+ menuItemsList.innerHTML = '';
2725
+ }
2726
+ menuItems.forEach(item => {
2727
+ const menuItem = document.createElement('div');
2728
+ menuItem.className = 'menu-item';
2729
+ const img = document.createElement('img');
2730
+ img.src = item.image_url || 'https://via.placeholder.com/120';
2731
+ img.alt = item.name;
2732
+ const name = document.createElement('div');
2733
+ name.textContent = item.name;
2734
+ const button = document.createElement('button');
2735
+ button.textContent = 'Add to Cart';
2736
+ button.onclick = () => {
2737
+ selectedMenuItem = item;
2738
+ addMessage('bot', `World-class selection! Would you like to customize your dish further?`);
2739
+ const options = [
2740
+ { text: 'Yes', class: 'green' },
2741
+ { text: 'No', class: 'red' }
2742
+ ];
2743
+ displayOptions(options);
2744
+ };
2745
+ menuItem.appendChild(img);
2746
+ menuItem.appendChild(name);
2747
+ menuItem.appendChild(button);
2748
+ menuItemsList.appendChild(menuItem);
2749
+ });
2750
+ }
2751
+ function displaySelectedIngredients() {
2752
+ const chatMessages = document.getElementById('chatMessages');
2753
+ if (!chatMessages) {
2754
+ console.error('Chat messages container not found for selected ingredients!');
2755
+ return;
2756
+ }
2757
+ let selectedArea = document.querySelector('.selected-ingredients');
2758
+ if (!selectedArea) {
2759
+ selectedArea = document.createElement('div');
2760
+ selectedArea.className = 'selected-ingredients';
2761
+ chatMessages.appendChild(selectedArea);
2762
+ } else {
2763
+ selectedArea.innerHTML = '';
2764
+ }
2765
+ selectedIngredients.forEach(ingredient => {
2766
+ const div = document.createElement('div');
2767
+ div.textContent = ingredient.name;
2768
+ const removeButton = document.createElement('button');
2769
+ removeButton.textContent = 'X';
2770
+ removeButton.style.marginLeft = '5px';
2771
+ removeButton.style.padding = '2px 5px';
2772
+ removeButton.style.backgroundColor = '#dc3545';
2773
+ removeButton.style.color = '#ffffff';
2774
+ removeButton.style.border = 'none';
2775
+ removeButton.style.borderRadius = '4px';
2776
+ removeButton.style.cursor = 'pointer';
2777
+ removeButton.onclick = () => {
2778
+ selectedIngredients = selectedIngredients.filter(item => item.name !== ingredient.name);
2779
+ displaySelectedIngredients();
2780
+ };
2781
+ div.appendChild(removeButton);
2782
+ selectedArea.appendChild(div);
2783
+ });
2784
+ if (selectedIngredients.length > 0) {
2785
+ let submitButton = document.querySelector('.submit-button');
2786
+ if (!submitButton) {
2787
+ submitButton = document.createElement('button');
2788
+ submitButton.className = 'submit-button';
2789
+ submitButton.textContent = 'Submit Ingredients';
2790
+ submitButton.onclick = submitIngredients;
2791
+ chatMessages.appendChild(submitButton);
2792
+ }
2793
+ }
2794
+ }
2795
+ function submitIngredients() {
2796
+ if (selectedIngredients.length === 0) {
2797
+ addMessage('bot', 'No ingredients selected. Please choose some ingredients.');
2798
+ return;
2799
+ }
2800
+ const ingredientNames = selectedIngredients.map(ingredient => ingredient.name.toLowerCase()).join(' ');
2801
+ fetchMenuItems({ ingredient_names: ingredientNames });
2802
+ }
2803
+ function addToCart(item) {
2804
+ cart.push(item);
2805
+ console.log('Cart:', cart);
2806
+ displayCart();
2807
+ }
2808
+ function displayCart() {
2809
+ const chatMessages = document.getElementById('chatMessages');
2810
+ if (!chatMessages) {
2811
+ console.error('Chat messages container not found for cart!');
2812
+ return;
2813
+ }
2814
+ let cartArea = document.querySelector('.cart-items');
2815
+ if (!cartArea) {
2816
+ cartArea = document.createElement('div');
2817
+ cartArea.className = 'cart-items';
2818
+ chatMessages.appendChild(cartArea);
2819
+ } else {
2820
+ cartArea.innerHTML = '';
2821
+ }
2822
+ if (cart.length > 0) {
2823
+ const label = document.createElement('div');
2824
+ label.textContent = 'Cart:';
2825
+ cartArea.appendChild(label);
2826
+ cart.forEach((item, index) => {
2827
+ const itemDiv = document.createElement('div');
2828
+ itemDiv.className = 'cart-item';
2829
+ const img = document.createElement('img');
2830
+ img.src = item.image_url || 'https://via.placeholder.com/30';
2831
+ img.alt = item.name;
2832
+ const name = document.createElement('div');
2833
+ const text = item.instructions
2834
+ ? `${item.name} (${item.instructions})`
2835
+ : item.name;
2836
+ name.textContent = item.ingredients.length > 0
2837
+ ? `${text} with ${item.ingredients.map(i => i.name).join(', ')}`
2838
+ : text;
2839
+ const removeButton = document.createElement('button');
2840
+ removeButton.className = 'remove-button';
2841
+ removeButton.textContent = 'X';
2842
+ removeButton.onclick = () => {
2843
+ cart.splice(index, 1);
2844
+ displayCart();
2845
+ };
2846
+ itemDiv.appendChild(img);
2847
+ itemDiv.appendChild(name);
2848
+ itemDiv.appendChild(removeButton);
2849
+ cartArea.appendChild(itemDiv);
2850
+ });
2851
+ let submitCartButton = document.querySelector('.submit-cart-button');
2852
+ if (!submitCartButton) {
2853
+ submitCartButton = document.createElement('button');
2854
+ submitCartButton.className = 'submit-cart-button';
2855
+ submitCartButton.textContent = 'Submit Cart';
2856
+ submitCartButton.onclick = submitCart;
2857
+ cartArea.appendChild(submitCartButton);
2858
+ }
2859
+ }
2860
+ }
2861
+ function submitCart() {
2862
+ if (cart.length === 0) {
2863
+ addMessage('bot', 'Your cart is empty!');
2864
+ return;
2865
+ }
2866
+ fetch('/submit_customization_ingredients', {
2867
+ method: 'POST',
2868
+ headers: { 'Content-Type': 'application/json' },
2869
+ body: JSON.stringify({ items: cart })
2870
+ })
2871
+ .then(response => response.json())
2872
+ .then(data => {
2873
+ if (data.success) {
2874
+ addMessage('bot', 'Cart submitted successfully!');
2875
+ cart = [];
2876
+ displayCart();
2877
+ } else {
2878
+ addMessage('bot', `Error submitting cart: ${data.error}`);
2879
+ }
2880
+ })
2881
+ .catch(error => {
2882
+ addMessage('bot', `Error submitting cart: ${error.message}`);
2883
+ });
2884
+ }
2885
+ function displayOptions(options) {
2886
+ const chatMessages = document.getElementById('chatMessages');
2887
+ if (!chatMessages) {
2888
+ console.error('Chat messages container not found for options!');
2889
+ return;
2890
+ }
2891
+ console.log('Displaying options:', options);
2892
+ options.forEach(opt => {
2893
+ const button = document.createElement('button');
2894
+ button.textContent = opt.text;
2895
+ button.className = `option-button ${opt.class}`;
2896
+ button.onclick = () => {
2897
+ addMessage('user', opt.text);
2898
+ conversation.push({ role: 'user', message: opt.text });
2899
+ console.log(`User selected option: ${opt.text}`);
2900
+ setTimeout(() => handleResponse(opt.text), 500);
2901
+ };
2902
+ chatMessages.appendChild(button);
2903
+ });
2904
+ chatMessages.appendChild(document.createElement('br'));
2905
+ chatMessages.scrollTop = chatMessages.scrollHeight;
2906
+ console.log('Options displayed');
2907
+ }
2908
+ document.getElementById('userInput').addEventListener('keypress', function(e) {
2909
+ if (e.key === 'Enter') {
2910
+ sendMessage();
2911
+ }
2912
+ });
2913
+ console.log('Script loaded successfully');
2914
  </script>
2915
  </body>
2916
  </html>