lokesh341 commited on
Commit
90e6c0c
·
verified ·
1 Parent(s): 8a4a66c

Update templates/chef-bot.html

Browse files
Files changed (1) hide show
  1. templates/chef-bot.html +484 -434
templates/chef-bot.html CHANGED
@@ -101,7 +101,7 @@
101
  background-color: #005ea2;
102
  }
103
 
104
- .items-grid {
105
  display: flex;
106
  flex-wrap: nowrap;
107
  overflow-x: auto;
@@ -113,7 +113,7 @@
113
  scroll-behavior: smooth;
114
  }
115
 
116
- .item-card {
117
  flex: 0 0 200px;
118
  background-color: #ffffff;
119
  border: 1px solid #e0e0e0;
@@ -121,13 +121,14 @@
121
  padding: 10px;
122
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
123
  transition: transform 0.2s;
 
124
  }
125
 
126
- .item-card:hover {
127
  transform: translateY(-2px);
128
  }
129
 
130
- .item-image {
131
  width: 100%;
132
  height: 120px;
133
  object-fit: cover;
@@ -135,36 +136,14 @@
135
  margin-bottom: 8px;
136
  }
137
 
138
- .item-name {
139
  font-size: 14px;
140
  font-weight: 600;
141
  color: #333;
142
  margin-bottom: 5px;
143
  }
144
 
145
- .item-field {
146
- font-size: 12px;
147
- color: #555;
148
- margin: 3px 0;
149
- }
150
-
151
- .item-field strong {
152
- color: #0078d4;
153
- }
154
-
155
- .item-description {
156
- font-size: 12px;
157
- color: #666;
158
- margin: 5px 0;
159
- }
160
-
161
- .button-container {
162
- display: flex;
163
- gap: 8px;
164
- margin-top: 8px;
165
- }
166
-
167
- .add-button {
168
  padding: 8px;
169
  background-color: #28a745;
170
  color: #ffffff;
@@ -172,20 +151,61 @@
172
  border-radius: 6px;
173
  cursor: pointer;
174
  font-size: 12px;
175
- flex: 1;
176
  }
177
 
178
- .add-button:hover {
179
  background-color: #218838;
180
  }
181
 
182
- .options-container {
 
 
 
 
 
 
183
  display: flex;
184
  flex-wrap: wrap;
185
  gap: 10px;
 
 
 
 
 
 
 
 
 
 
186
  margin: 10px 0;
187
  }
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  .option-button {
190
  padding: 10px 20px;
191
  color: #ffffff;
@@ -193,6 +213,7 @@
193
  border-radius: 8px;
194
  cursor: pointer;
195
  font-size: 14px;
 
196
  transition: background-color 0.2s;
197
  }
198
 
@@ -212,27 +233,16 @@
212
  background-color: #c82333;
213
  }
214
 
215
- .selection-box {
216
  background-color: #f1f8ff;
217
  padding: 15px;
218
  border: 1px solid #b3d7ff;
219
  border-radius: 10px;
220
  margin: 10px 0;
221
  font-size: 14px;
222
- display: flex;
223
- flex-wrap: wrap;
224
- align-items: center;
225
- gap: 10px;
226
  }
227
 
228
- .selection-box span {
229
- background-color: #d6e9ff;
230
- padding: 5px 10px;
231
- border-radius: 6px;
232
- font-size: 13px;
233
- }
234
-
235
- .selected-item {
236
  display: flex;
237
  align-items: center;
238
  background-color: #d6e9ff;
@@ -240,11 +250,9 @@
240
  border-radius: 6px;
241
  font-size: 13px;
242
  margin: 5px 0;
243
- width: 100%;
244
- flex-wrap: wrap;
245
  }
246
 
247
- .selected-item-image {
248
  width: 30px;
249
  height: 30px;
250
  object-fit: cover;
@@ -252,47 +260,7 @@
252
  margin-right: 8px;
253
  }
254
 
255
- .ingredient-info-input {
256
- padding: 8px;
257
- border: 1px solid #b3d7ff;
258
- border-radius: 6px;
259
- font-size: 13px;
260
- width: 150px;
261
- outline: none;
262
- margin: 5px;
263
- }
264
-
265
- .ingredient-button {
266
- padding: 8px 12px;
267
- background-color: #6c757d;
268
- color: #ffffff;
269
- border: none;
270
- border-radius: 6px;
271
- cursor: pointer;
272
- font-size: 13px;
273
- margin: 5px;
274
- }
275
-
276
- .ingredient-button:hover {
277
- background-color: #5a6268;
278
- }
279
-
280
- .submit-button {
281
- padding: 10px 20px;
282
- background-color: #0078d4;
283
- color: #ffffff;
284
- border: none;
285
- border-radius: 8px;
286
- cursor: pointer;
287
- font-size: 14px;
288
- transition: background-color 0.2s;
289
- }
290
-
291
- .submit-button:hover {
292
- background-color: #005ea2;
293
- }
294
-
295
- .remove-button {
296
  padding: 5px 10px;
297
  margin-left: 8px;
298
  background-color: #dc3545;
@@ -303,35 +271,34 @@
303
  font-size: 12px;
304
  }
305
 
306
- .remove-button:hover {
307
  background-color: #c82333;
308
  }
309
 
310
- .name-input, .ingredients-info-input {
311
  padding: 8px;
312
  border: 1px solid #b3d7ff;
313
  border-radius: 6px;
314
- font-size: 14px;
315
  width: 150px;
316
  outline: none;
 
317
  }
318
 
319
- .quantity-input {
320
- padding: 8px;
321
- border: 1px solid #b3d7ff;
322
- border-radius: 6px;
323
- font-size: 14px;
324
- width: 60px;
325
- outline: none;
326
  }
327
 
328
- .order-name-input {
329
  padding: 8px;
330
  border: 1px solid #b3d7ff;
331
  border-radius: 6px;
332
  font-size: 14px;
333
- width: 150px;
334
- outline: none;
 
 
 
335
  }
336
 
337
  /* Responsive Design */
@@ -366,31 +333,27 @@
366
  padding: 8px 15px;
367
  }
368
 
369
- .items-grid {
370
  flex-direction: column;
371
  gap: 10px;
372
  padding: 8px;
373
  }
374
 
375
- .item-card {
376
  flex: 0 0 auto;
377
  width: 100%;
378
  max-width: 250px;
379
  }
380
 
381
- .item-image {
382
  height: 100px;
383
  }
384
 
385
- .item-name {
386
  font-size: 13px;
387
  }
388
 
389
- .item-field, .item-description {
390
- font-size: 11px;
391
- }
392
-
393
- .add-button {
394
  font-size: 11px;
395
  padding: 6px;
396
  }
@@ -400,22 +363,27 @@
400
  padding: 8px 15px;
401
  }
402
 
403
- .selection-box {
404
  padding: 10px;
405
  gap: 8px;
406
  }
407
 
408
- .selected-item {
409
  font-size: 12px;
410
  padding: 4px 8px;
411
  }
412
 
413
- .selected-item-image {
414
  width: 25px;
415
  height: 25px;
416
  }
417
 
418
- .name-input, .order-name-input, .ingredients-info-input {
 
 
 
 
 
419
  width: 120px;
420
  font-size: 13px;
421
  padding: 6px;
@@ -423,8 +391,6 @@
423
 
424
  .quantity-input {
425
  width: 50px;
426
- font-size: 13px;
427
- padding: 6px;
428
  }
429
 
430
  .submit-button {
@@ -432,15 +398,10 @@
432
  padding: 8px 15px;
433
  }
434
 
435
- .remove-button {
436
  font-size: 11px;
437
  padding: 4px 8px;
438
  }
439
-
440
- .ingredient-info-input, .ingredient-button {
441
- width: 120px;
442
- font-size: 12px;
443
- }
444
  }
445
 
446
  @media (min-width: 481px) and (max-width: 768px) {
@@ -457,11 +418,11 @@
457
  padding: 12px;
458
  }
459
 
460
- .item-card {
461
  flex: 0 0 180px;
462
  }
463
 
464
- .item-image {
465
  height: 110px;
466
  }
467
  }
@@ -471,24 +432,23 @@
471
  <div class="chat-container">
472
  <div class="chat-header">🍳 Chef Bot</div>
473
  <div class="chat-messages" id="chatMessages">
474
- <div class="bot-message">Hello! What's your name?</div>
475
  </div>
476
  <div class="chat-input">
477
- <input type="text" id="userInput" placeholder="Type your name or dish...">
478
  <button onclick="sendMessage()">Send</button>
479
  </div>
480
  </div>
481
 
482
  <script>
483
  let conversation = [
484
- { role: 'bot', message: "Hello! What's your name?" }
485
  ];
486
  let userName = '';
487
  let selectedPreference = '';
 
 
488
  let cart = [];
489
- let selectionBoxVisible = false;
490
- let nameInputVisible = false;
491
- let ingredients = [];
492
 
493
  function addMessage(role, message) {
494
  const chatMessages = document.getElementById('chatMessages');
@@ -514,222 +474,106 @@
514
  if (message) {
515
  addMessage('user', message);
516
  conversation.push({ role: 'user', message: message });
517
- handleResponse(message);
 
518
  } else {
519
  addMessage('bot', 'Please type something! 😄');
 
520
  }
521
- userInput.value = '';
522
- updateSelectionBox();
523
  }
524
 
525
  function handleResponse(userInput) {
526
- if (!userName) {
 
 
 
 
527
  userName = userInput;
528
- addMessage('bot', `Nice to meet you, ${userName}! Choose your preference: Veg or Non-Veg.`);
529
- selectionBoxVisible = true;
530
- updateSelectionBox();
531
- } else if (!selectedPreference && (userInput.toLowerCase() === 'vegetarian' || userInput.toLowerCase() === 'non-vegetarian')) {
532
- selectedPreference = userInput.toLowerCase();
533
- addMessage('bot', `Fetching ${selectedPreference} dishes...`);
534
- fetchMenuItems(selectedPreference);
535
- nameInputVisible = true;
536
- updateSelectionBox();
537
- } else if (nameInputVisible) {
538
- addMessage('bot', `Searching for "${userInput}"...`);
539
- fetchMenuItems(selectedPreference, userInput);
 
 
 
 
 
 
 
 
 
 
 
 
 
540
  } else {
541
- addMessage('bot', 'Please select Veg or Non-Veg first!');
 
 
542
  }
543
- }
544
 
545
- function updateSelectionBox() {
546
- const chatMessages = document.getElementById('chatMessages');
547
- if (!chatMessages) return;
 
 
 
548
 
549
- const existingBox = document.querySelector('.selection-box');
550
- if (existingBox) existingBox.remove();
551
-
552
- // Selection Box
553
- if (selectionBoxVisible && !userName) {
554
- const selectionBox = document.createElement('div');
555
- selectionBox.className = 'selection-box';
556
-
557
- const nameInput = document.createElement('input');
558
- nameInput.type = 'text';
559
- nameInput.placeholder = 'Enter your name...';
560
- nameInput.className = 'name-input';
561
- nameInput.addEventListener('keypress', (e) => {
562
- if (e.key === 'Enter' && nameInput.value.trim()) {
563
- const name = nameInput.value.trim();
564
- addMessage('user', name);
565
- conversation.push({ role: 'user', message: name });
566
- handleResponse(name);
567
- nameInput.value = '';
568
  }
 
 
 
569
  });
570
- selectionBox.appendChild(nameInput);
571
-
572
- chatMessages.appendChild(selectionBox);
573
- } else if (selectionBoxVisible && userName && !selectedPreference) {
574
- const selectionBox = document.createElement('div');
575
- selectionBox.className = 'selection-box';
576
-
577
- const vegButton = document.createElement('button');
578
- vegButton.textContent = 'Veg';
579
- vegButton.className = 'option-button green';
580
- vegButton.onclick = () => {
581
- addMessage('user', 'Vegetarian');
582
- conversation.push({ role: 'user', message: 'Vegetarian' });
583
- handleResponse('vegetarian');
584
- };
585
- selectionBox.appendChild(vegButton);
586
-
587
- const nonVegButton = document.createElement('button');
588
- nonVegButton.textContent = 'Non-Veg';
589
- nonVegButton.className = 'option-button red';
590
- nonVegButton.onclick = () => {
591
- addMessage('user', 'Non-Vegetarian');
592
- conversation.push({ role: 'user', message: 'Non-Vegetarian' });
593
- handleResponse('non-vegetarian');
594
- };
595
- selectionBox.appendChild(nonVegButton);
596
-
597
- chatMessages.appendChild(selectionBox);
598
- } else if (nameInputVisible && selectedPreference) {
599
- const selectionBox = document.createElement('div');
600
- selectionBox.className = 'selection-box';
601
-
602
- const nameInput = document.createElement('input');
603
- nameInput.type = 'text';
604
- nameInput.placeholder = 'Enter dish name...';
605
- nameInput.className = 'name-input';
606
- nameInput.addEventListener('keypress', (e) => {
607
- if (e.key === 'Enter' && nameInput.value.trim()) {
608
- const itemName = nameInput.value.trim();
609
- addMessage('user', itemName);
610
- conversation.push({ role: 'user', message: itemName });
611
- handleResponse(itemName);
612
- nameInput.value = '';
613
  }
 
 
 
614
  });
615
- selectionBox.appendChild(nameInput);
616
-
617
- // Cart Items
618
- if (cart.length > 0) {
619
- const itemsLabel = document.createElement('span');
620
- itemsLabel.textContent = 'Selected Items:';
621
- selectionBox.appendChild(itemsLabel);
622
-
623
- cart.forEach((item, index) => {
624
- const itemContainer = document.createElement('div');
625
- itemContainer.className = 'selected-item';
626
-
627
- const img = document.createElement('img');
628
- img.src = item.image_url || 'https://via.placeholder.com/30';
629
- img.alt = item.name;
630
- img.className = 'selected-item-image';
631
- itemContainer.appendChild(img);
632
-
633
- const contentDiv = document.createElement('div');
634
- contentDiv.className = 'selected-item-content';
635
-
636
- const itemSpan = document.createElement('span');
637
- itemSpan.textContent = `${item.name} (Qty: ${item.quantity || 1})`;
638
- contentDiv.appendChild(itemSpan);
639
-
640
- // Ingredient Buttons
641
- const ingredientButtonsDiv = document.createElement('div');
642
- ingredientButtonsDiv.style.display = 'flex';
643
- ingredientButtonsDiv.style.flexWrap = 'wrap';
644
- ingredientButtonsDiv.style.gap = '5px';
645
- ingredients.forEach(ingredient => {
646
- const ingredientButton = document.createElement('button');
647
- ingredientButton.textContent = ingredient.name;
648
- ingredientButton.className = 'ingredient-button';
649
- ingredientButton.onclick = () => {
650
- addMessage('bot', `Finding dishes with "${ingredient.name}"...`);
651
- fetchRelatedMenuItems(ingredient.name);
652
- };
653
- ingredientButtonsDiv.appendChild(ingredientButton);
654
- });
655
- contentDiv.appendChild(ingredientButtonsDiv);
656
-
657
- // Ingredientsinfo Input
658
- const ingredientInfoInput = document.createElement('input');
659
- ingredientInfoInput.type = 'text';
660
- ingredientInfoInput.placeholder = 'Add ingredient details...';
661
- ingredientInfoInput.className = 'ingredient-info-input';
662
- ingredientInfoInput.value = item.ingredientsInfo || '';
663
- ingredientInfoInput.addEventListener('input', (e) => {
664
- cart[index].ingredientsInfo = e.target.value;
665
- });
666
- contentDiv.appendChild(ingredientInfoInput);
667
-
668
- itemContainer.appendChild(contentDiv);
669
-
670
- const removeButton = document.createElement('button');
671
- removeButton.textContent = 'X';
672
- removeButton.className = 'remove-button';
673
- removeButton.onclick = () => {
674
- cart.splice(index, 1);
675
- addMessage('bot', `Removed "${item.name}".`);
676
- updateSelectionBox();
677
- };
678
- itemContainer.appendChild(removeButton);
679
-
680
- selectionBox.appendChild(itemContainer);
681
- });
682
-
683
- // Submit Order
684
- const submitLabel = document.createElement('span');
685
- submitLabel.textContent = 'Submit Order:';
686
- selectionBox.appendChild(submitLabel);
687
-
688
- const quantityInput = document.createElement('input');
689
- quantityInput.type = 'number';
690
- quantityInput.min = '1';
691
- quantityInput.value = '1';
692
- quantityInput.placeholder = 'Qty';
693
- quantityInput.className = 'quantity-input';
694
- selectionBox.appendChild(quantityInput);
695
-
696
- const orderNameInput = document.createElement('input');
697
- orderNameInput.type = 'text';
698
- orderNameInput.placeholder = 'Order Name';
699
- orderNameInput.className = 'order-name-input';
700
- selectionBox.appendChild(orderNameInput);
701
-
702
- const ingredientsInfoInput = document.createElement('input');
703
- ingredientsInfoInput.type = 'text';
704
- ingredientsInfoInput.placeholder = 'Order Ingredients Info...';
705
- ingredientsInfoInput.className = 'ingredients-info-input';
706
- ingredientsInfoInput.id = 'orderIngredientsInfo';
707
- selectionBox.appendChild(ingredientsInfoInput);
708
-
709
- const submitButton = document.createElement('button');
710
- submitButton.textContent = 'Submit';
711
- submitButton.className = 'submit-button';
712
- submitButton.onclick = () => promptAndSubmit(
713
- quantityInput.value,
714
- orderNameInput.value,
715
- ingredientsInfoInput.value
716
- );
717
- selectionBox.appendChild(submitButton);
718
- }
719
-
720
- chatMessages.appendChild(selectionBox);
721
- }
722
-
723
- chatMessages.scrollTop = chatMessages.scrollHeight;
724
- console.log('Updated selection box:', cart.map(item => ({
725
- name: item.name,
726
- ingredientsInfo: item.ingredientsInfo
727
- })));
728
  }
729
 
730
- function fetchMenuItems(dietaryPreference = '', searchTerm = '') {
731
- const payload = { source: 'Menu_Item__c' };
732
- if (dietaryPreference) payload.dietary_preference = dietaryPreference;
733
  if (searchTerm) payload.search_term = searchTerm;
734
  fetch('/get_menu_items', {
735
  method: 'POST',
@@ -739,37 +583,17 @@
739
  .then(response => response.json())
740
  .then(data => {
741
  if (data.error) {
742
- addMessage('bot', `Error: ${data.error}. Try again!`);
743
  } else if (data.menu_items.length > 0) {
744
  addMessage('bot', `--- Found ${data.menu_items.length} item${data.menu_items.length > 1 ? 's' : ''} ---`);
745
  displayMenuItems(data.menu_items);
746
  } else {
747
  addMessage('bot', `No matches for "${searchTerm || dietaryPreference}". Try "paneer"!`);
748
  }
749
- console.log(`Fetched items for ${searchTerm || dietaryPreference}:`, data.menu_items);
750
  })
751
  .catch(error => {
752
- addMessage('bot', `Connection issue: ${error.message}. Retrying...`);
753
- setTimeout(() => fetchMenuItems(dietaryPreference, searchTerm), 2000);
754
  });
755
-
756
- // Fetch ingredients
757
- if (!ingredients.length) {
758
- fetch('/get_ingredients', {
759
- method: 'POST',
760
- headers: { 'Content-Type': 'application/json' },
761
- body: JSON.stringify({ dietary_preference: 'both' })
762
- })
763
- .then(response => response.json())
764
- .then(data => {
765
- if (!data.error) {
766
- ingredients = data.ingredients;
767
- console.log('Fetched Sector_Detail__c ingredients:', ingredients);
768
- updateSelectionBox();
769
- }
770
- })
771
- .catch(error => console.error('Error fetching ingredients:', error));
772
- }
773
  }
774
 
775
  function fetchRelatedMenuItems(ingredientName) {
@@ -788,114 +612,307 @@
788
  } else {
789
  addMessage('bot', `No dishes found with "${ingredientName}". Try another!`);
790
  }
791
- console.log(`Fetched related items for ${ingredientName}:`, data.menu_items);
792
  })
793
  .catch(error => {
794
- addMessage('bot', `Connection issue: ${error.message}. Retrying...`);
795
- setTimeout(() => fetchRelatedMenuItems(ingredientName), 2000);
796
  });
797
  }
798
 
799
- function displayMenuItems(items) {
800
  const chatMessages = document.getElementById('chatMessages');
801
  if (!chatMessages) {
802
- console.error('Chat messages container not found!');
803
- addMessage('bot', 'Display issue. Try again?');
804
  return;
805
  }
806
 
807
- const itemsGrid = document.createElement('div');
808
- itemsGrid.className = 'items-grid';
809
-
810
- items.forEach(item => {
811
- const itemDiv = document.createElement('div');
812
- itemDiv.className = 'item-card';
 
 
813
 
 
 
 
814
  const img = document.createElement('img');
815
- img.src = item.image_url || 'https://via.placeholder.com/60';
816
- img.alt = item.name;
817
- img.className = 'item-image';
818
- itemDiv.appendChild(img);
819
-
820
- const contentDiv = document.createElement('div');
821
- contentDiv.className = 'item-content';
 
 
 
 
 
 
 
 
 
822
 
823
- const nameDiv = document.createElement('div');
824
- nameDiv.textContent = item.name;
825
- nameDiv.className = 'item-name';
826
- contentDiv.appendChild(nameDiv);
 
 
827
 
828
- const fields = [
829
- { label: 'Price', value: item.price ? `$${item.price.toFixed(2)}` : 'N/A' },
830
- { label: 'Veg/Non-Veg', value: item.veg_nonveg || item.category },
831
- { label: 'Description', value: item.description },
832
- ];
833
- fields.forEach(field => {
834
- if (field.value) {
835
- const p = document.createElement('p');
836
- p.className = 'item-field';
837
- p.innerHTML = `<strong>${field.label}:</strong> ${field.value}`;
838
- contentDiv.appendChild(p);
839
- }
840
- });
841
 
842
- itemDiv.appendChild(contentDiv);
843
-
844
- const buttonContainer = document.createElement('div');
845
- buttonContainer.className = 'button-container';
846
-
847
- const addButton = document.createElement('button');
848
- addButton.textContent = 'Add';
849
- addButton.className = 'add-button';
850
- addButton.onclick = () => {
851
- const cartItem = {
852
- name: item.name,
853
- image_url: item.image_url || '',
854
- category: item.category || item.veg_nonveg || 'Not specified',
855
- description: item.description || 'No description available',
856
- source: item.source,
857
- quantity: 1,
858
- ingredientsInfo: ''
859
- };
860
- if (cart.some(existing => existing.name === cartItem.name && !existing.ingredientsInfo)) {
861
- addMessage('bot', `"${cartItem.name}" already in cart!`);
862
- } else {
863
- cart.push(cartItem);
864
- addMessage('bot', `Added "${cartItem.name}" to cart!`);
865
- updateSelectionBox();
866
  }
867
  };
868
- buttonContainer.appendChild(addButton);
 
 
 
 
 
869
 
870
- itemDiv.appendChild(buttonContainer);
871
- itemsGrid.appendChild(itemDiv);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
872
  });
 
873
 
874
- chatMessages.appendChild(itemsGrid);
875
- chatMessages.scrollTop = chatMessages.scrollHeight;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876
  }
877
 
878
- function promptAndSubmit(quantity, orderName, ingredientsInfo) {
879
- if (confirm(`Submit ${cart.length} items (Qty: ${quantity}) as "${orderName || 'Order'}"?`)) {
880
- submitToSalesforce(orderName, quantity, ingredientsInfo);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
881
  } else {
882
- addMessage('bot', 'Cancelled. Add more items?');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
883
  }
 
 
884
  }
885
 
886
- function submitToSalesforce(customOrderName, quantity, ingredientsInfo) {
887
  if (cart.length === 0) {
888
  addMessage('bot', 'No items in cart! Add some dishes! 😊');
889
  return;
890
  }
891
 
892
- const itemsToSubmit = cart.map(item => ({
893
  name: item.name,
894
- category: item.category || 'Not specified',
895
- description: item.description || 'No description available',
896
- image_url: item.image_url || '',
897
  quantity: parseInt(quantity) || 1,
898
- ingredientsInfo: item.ingredientsInfo || ''
 
 
899
  }));
900
 
901
  fetch('/submit_ingredients', {
@@ -904,7 +921,7 @@
904
  body: JSON.stringify({
905
  items: itemsToSubmit,
906
  custom_order_name: customOrderName,
907
- ingredients_info: ingredientsInfo
908
  })
909
  })
910
  .then(response => response.json())
@@ -914,22 +931,55 @@
914
  } else {
915
  addMessage('bot', `Submitted ${data.ingredient_name}! What's next?`);
916
  cart = [];
917
- updateSelectionBox();
 
 
918
  }
919
  })
920
  .catch(error => {
921
  addMessage('bot', `Submission error: ${error.message}. Retrying...`);
922
- setTimeout(() => submitToSalesforce(customOrderName, quantity, ingredientsInfo), 2000);
923
  });
924
  }
925
 
926
- document.getElementById('userInput').addEventListener('keypress', (e) => {
927
- if (e.key === 'Enter') sendMessage();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
928
  });
929
 
930
- // Initial setup
931
- updateSelectionBox();
932
- console.log('Chef Bot script loaded!');
933
  </script>
934
  </body>
935
  </html>
 
101
  background-color: #005ea2;
102
  }
103
 
104
+ .ingredients-list, .menu-items-list, .customization-ingredients-list {
105
  display: flex;
106
  flex-wrap: nowrap;
107
  overflow-x: auto;
 
113
  scroll-behavior: smooth;
114
  }
115
 
116
+ .ingredient-item, .menu-item {
117
  flex: 0 0 200px;
118
  background-color: #ffffff;
119
  border: 1px solid #e0e0e0;
 
121
  padding: 10px;
122
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
123
  transition: transform 0.2s;
124
+ text-align: center;
125
  }
126
 
127
+ .ingredient-item:hover, .menu-item:hover {
128
  transform: translateY(-2px);
129
  }
130
 
131
+ .ingredient-item img, .menu-item img {
132
  width: 100%;
133
  height: 120px;
134
  object-fit: cover;
 
136
  margin-bottom: 8px;
137
  }
138
 
139
+ .ingredient-item div, .menu-item div {
140
  font-size: 14px;
141
  font-weight: 600;
142
  color: #333;
143
  margin-bottom: 5px;
144
  }
145
 
146
+ .ingredient-item button, .menu-item button {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  padding: 8px;
148
  background-color: #28a745;
149
  color: #ffffff;
 
151
  border-radius: 6px;
152
  cursor: pointer;
153
  font-size: 12px;
154
+ width: 100%;
155
  }
156
 
157
+ .ingredient-item button:hover, .menu-item button:hover {
158
  background-color: #218838;
159
  }
160
 
161
+ .selected-ingredients {
162
+ background-color: #f1f8ff;
163
+ padding: 15px;
164
+ border: 1px solid #b3d7ff;
165
+ border-radius: 10px;
166
+ margin: 10px 0;
167
+ font-size: 14px;
168
  display: flex;
169
  flex-wrap: wrap;
170
  gap: 10px;
171
+ }
172
+
173
+ .selected-ingredients div {
174
+ background-color: #d6e9ff;
175
+ padding: 5px 10px;
176
+ border-radius: 6px;
177
+ font-size: 13px;
178
+ }
179
+
180
+ .customization-input {
181
  margin: 10px 0;
182
  }
183
 
184
+ .customization-input textarea {
185
+ width: 100%;
186
+ padding: 8px;
187
+ border: 1px solid #b3d7ff;
188
+ border-radius: 6px;
189
+ font-size: 14px;
190
+ outline: none;
191
+ margin-bottom: 10px;
192
+ }
193
+
194
+ .customization-input button, .submit-button {
195
+ padding: 10px 20px;
196
+ background-color: #0078d4;
197
+ color: #ffffff;
198
+ border: none;
199
+ border-radius: 8px;
200
+ cursor: pointer;
201
+ font-size: 14px;
202
+ transition: background-color 0.2s;
203
+ }
204
+
205
+ .customization-input button:hover, .submit-button:hover {
206
+ background-color: #005ea2;
207
+ }
208
+
209
  .option-button {
210
  padding: 10px 20px;
211
  color: #ffffff;
 
213
  border-radius: 8px;
214
  cursor: pointer;
215
  font-size: 14px;
216
+ margin: 5px;
217
  transition: background-color 0.2s;
218
  }
219
 
 
233
  background-color: #c82333;
234
  }
235
 
236
+ .cart-items {
237
  background-color: #f1f8ff;
238
  padding: 15px;
239
  border: 1px solid #b3d7ff;
240
  border-radius: 10px;
241
  margin: 10px 0;
242
  font-size: 14px;
 
 
 
 
243
  }
244
 
245
+ .cart-item {
 
 
 
 
 
 
 
246
  display: flex;
247
  align-items: center;
248
  background-color: #d6e9ff;
 
250
  border-radius: 6px;
251
  font-size: 13px;
252
  margin: 5px 0;
 
 
253
  }
254
 
255
+ .cart-item img {
256
  width: 30px;
257
  height: 30px;
258
  object-fit: cover;
 
260
  margin-right: 8px;
261
  }
262
 
263
+ .cart-item .remove-button {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  padding: 5px 10px;
265
  margin-left: 8px;
266
  background-color: #dc3545;
 
271
  font-size: 12px;
272
  }
273
 
274
+ .cart-item .remove-button:hover {
275
  background-color: #c82333;
276
  }
277
 
278
+ .cart-item .ingredient-info-input {
279
  padding: 8px;
280
  border: 1px solid #b3d7ff;
281
  border-radius: 6px;
282
+ font-size: 13px;
283
  width: 150px;
284
  outline: none;
285
+ margin: 5px;
286
  }
287
 
288
+ .submit-cart {
289
+ margin: 10px 0;
 
 
 
 
 
290
  }
291
 
292
+ .submit-cart input {
293
  padding: 8px;
294
  border: 1px solid #b3d7ff;
295
  border-radius: 6px;
296
  font-size: 14px;
297
+ margin-right: 10px;
298
+ }
299
+
300
+ .quantity-input {
301
+ width: 60px;
302
  }
303
 
304
  /* Responsive Design */
 
333
  padding: 8px 15px;
334
  }
335
 
336
+ .ingredients-list, .menu-items-list, .customization-ingredients-list {
337
  flex-direction: column;
338
  gap: 10px;
339
  padding: 8px;
340
  }
341
 
342
+ .ingredient-item, .menu-item {
343
  flex: 0 0 auto;
344
  width: 100%;
345
  max-width: 250px;
346
  }
347
 
348
+ .ingredient-item img, .menu-item img {
349
  height: 100px;
350
  }
351
 
352
+ .ingredient-item div, .menu-item div {
353
  font-size: 13px;
354
  }
355
 
356
+ .ingredient-item button, .menu-item button {
 
 
 
 
357
  font-size: 11px;
358
  padding: 6px;
359
  }
 
363
  padding: 8px 15px;
364
  }
365
 
366
+ .selected-ingredients, .cart-items {
367
  padding: 10px;
368
  gap: 8px;
369
  }
370
 
371
+ .cart-item {
372
  font-size: 12px;
373
  padding: 4px 8px;
374
  }
375
 
376
+ .cart-item img {
377
  width: 25px;
378
  height: 25px;
379
  }
380
 
381
+ .cart-item .ingredient-info-input {
382
+ width: 120px;
383
+ font-size: 12px;
384
+ }
385
+
386
+ .submit-cart input {
387
  width: 120px;
388
  font-size: 13px;
389
  padding: 6px;
 
391
 
392
  .quantity-input {
393
  width: 50px;
 
 
394
  }
395
 
396
  .submit-button {
 
398
  padding: 8px 15px;
399
  }
400
 
401
+ .cart-item .remove-button {
402
  font-size: 11px;
403
  padding: 4px 8px;
404
  }
 
 
 
 
 
405
  }
406
 
407
  @media (min-width: 481px) and (max-width: 768px) {
 
418
  padding: 12px;
419
  }
420
 
421
+ .ingredient-item, .menu-item {
422
  flex: 0 0 180px;
423
  }
424
 
425
+ .ingredient-item img, .menu-item img {
426
  height: 110px;
427
  }
428
  }
 
432
  <div class="chat-container">
433
  <div class="chat-header">🍳 Chef Bot</div>
434
  <div class="chat-messages" id="chatMessages">
435
+ <div class="bot-message">Hi there! I'm Chef Bot! May I know your name?</div>
436
  </div>
437
  <div class="chat-input">
438
+ <input type="text" id="userInput" placeholder="Type your name or message...">
439
  <button onclick="sendMessage()">Send</button>
440
  </div>
441
  </div>
442
 
443
  <script>
444
  let conversation = [
445
+ { role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" }
446
  ];
447
  let userName = '';
448
  let selectedPreference = '';
449
+ let selectedIngredients = [];
450
+ let selectedMenuItem = null;
451
  let cart = [];
 
 
 
452
 
453
  function addMessage(role, message) {
454
  const chatMessages = document.getElementById('chatMessages');
 
474
  if (message) {
475
  addMessage('user', message);
476
  conversation.push({ role: 'user', message: message });
477
+ userInput.value = '';
478
+ setTimeout(() => handleResponse(message), 500);
479
  } else {
480
  addMessage('bot', 'Please type something! 😄');
481
+ console.warn('Empty message!');
482
  }
483
+ updateCartDisplay();
 
484
  }
485
 
486
  function handleResponse(userInput) {
487
+ const lastMessage = userInput.toLowerCase();
488
+ let botResponse = '';
489
+ let options = [];
490
+
491
+ if (!userName) { // Name input
492
  userName = userInput;
493
+ botResponse = `Nice to meet you, ${userName}! 😊 Let's create your perfect meal! What type of food would you prefer?`;
494
+ options = [
495
+ { text: 'Vegetarian', class: 'green' },
496
+ { text: 'Non-Vegetarian', class: 'red' }
497
+ ];
498
+ } else if (!selectedPreference && (lastMessage.includes('vegetarian') || lastMessage.includes('non-vegetarian'))) {
499
+ selectedPreference = lastMessage.includes('vegetarian') ? 'vegetarian' : 'non-vegetarian';
500
+ conversation.push({ role: 'user', message: selectedPreference.charAt(0).toUpperCase() + selectedPreference.slice(1) });
501
+ console.log(`Food preference selected: ${selectedPreference}`);
502
+ botResponse = `Great choice! 🍽️ Here are some ingredients:`;
503
+ fetchIngredients();
504
+ return;
505
+ } else if (lastMessage.includes('yes') && selectedMenuItem) {
506
+ botResponse = 'Awesome! Let’s customize your dish. Here are some ingredients you can add:';
507
+ fetchCustomizationIngredients('both');
508
+ return;
509
+ } else if (lastMessage.includes('no') && selectedMenuItem) {
510
+ addToCart(selectedMenuItem);
511
+ botResponse = 'Item added to cart! Would you like to order more?';
512
+ options = [
513
+ { text: 'Yes', class: 'green' },
514
+ { text: 'No', class: 'red' }
515
+ ];
516
+ selectedMenuItem = null;
517
+ selectedIngredients = [];
518
  } else {
519
+ botResponse = `Searching for "${userInput}"...`;
520
+ fetchMenuItems(selectedPreference, userInput);
521
+ return;
522
  }
 
523
 
524
+ addMessage('bot', botResponse);
525
+ if (options.length > 0) {
526
+ displayOptions(options);
527
+ }
528
+ updateCartDisplay();
529
+ }
530
 
531
+ function fetchIngredients() {
532
+ fetch('/get_ingredients', {
533
+ method: 'POST',
534
+ headers: { 'Content-Type': 'application/json' },
535
+ body: JSON.stringify({ dietary_preference: 'both' })
536
+ })
537
+ .then(response => response.json())
538
+ .then(data => {
539
+ if (data.error) {
540
+ addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
541
+ } else {
542
+ const ingredients = data.ingredients || [];
543
+ addMessage('bot', 'Please select ingredients:');
544
+ displayIngredientsList(ingredients);
 
 
 
 
 
545
  }
546
+ })
547
+ .catch(error => {
548
+ addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
549
  });
550
+ }
551
+
552
+ function fetchCustomizationIngredients(foodPreference) {
553
+ fetch('/get_ingredients', {
554
+ method: 'POST',
555
+ headers: { 'Content-Type': 'application/json' },
556
+ body: JSON.stringify({ dietary_preference: foodPreference })
557
+ })
558
+ .then(response => response.json())
559
+ .then(data => {
560
+ if (data.error) {
561
+ addMessage('bot', `Sorry, there was an error fetching customization ingredients: ${data.error}`);
562
+ } else {
563
+ const ingredients = data.ingredients || [];
564
+ addMessage('bot', 'Select ingredients to customize your dish:');
565
+ displayCustomizationIngredients(ingredients);
566
+ displaySelectedIngredientsForCustomization();
567
+ displayCustomizationInput();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  }
569
+ })
570
+ .catch(error => {
571
+ addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
572
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
573
  }
574
 
575
+ function fetchMenuItems(dietaryPreference, searchTerm = '') {
576
+ const payload = { dietary_preference: dietaryPreference };
 
577
  if (searchTerm) payload.search_term = searchTerm;
578
  fetch('/get_menu_items', {
579
  method: 'POST',
 
583
  .then(response => response.json())
584
  .then(data => {
585
  if (data.error) {
586
+ addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
587
  } else if (data.menu_items.length > 0) {
588
  addMessage('bot', `--- Found ${data.menu_items.length} item${data.menu_items.length > 1 ? 's' : ''} ---`);
589
  displayMenuItems(data.menu_items);
590
  } else {
591
  addMessage('bot', `No matches for "${searchTerm || dietaryPreference}". Try "paneer"!`);
592
  }
 
593
  })
594
  .catch(error => {
595
+ addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
 
596
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
  }
598
 
599
  function fetchRelatedMenuItems(ingredientName) {
 
612
  } else {
613
  addMessage('bot', `No dishes found with "${ingredientName}". Try another!`);
614
  }
 
615
  })
616
  .catch(error => {
617
+ addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
 
618
  });
619
  }
620
 
621
+ function displayIngredientsList(ingredients) {
622
  const chatMessages = document.getElementById('chatMessages');
623
  if (!chatMessages) {
624
+ console.error('Chat messages container not found for ingredients!');
 
625
  return;
626
  }
627
 
628
+ let ingredientsList = document.querySelector('.ingredients-list');
629
+ if (!ingredientsList) {
630
+ ingredientsList = document.createElement('div');
631
+ ingredientsList.className = 'ingredients-list';
632
+ chatMessages.appendChild(ingredientsList);
633
+ } else {
634
+ ingredientsList.innerHTML = '';
635
+ }
636
 
637
+ ingredients.forEach(ingredient => {
638
+ const item = document.createElement('div');
639
+ item.className = 'ingredient-item';
640
  const img = document.createElement('img');
641
+ img.src = ingredient.image_url || 'https://via.placeholder.com/120';
642
+ img.alt = ingredient.name;
643
+ const name = document.createElement('div');
644
+ name.textContent = ingredient.name;
645
+ const button = document.createElement('button');
646
+ button.textContent = 'Select';
647
+ button.onclick = () => {
648
+ addMessage('bot', `Finding dishes with "${ingredient.name}"...`);
649
+ fetchRelatedMenuItems(ingredient.name);
650
+ };
651
+ item.appendChild(img);
652
+ item.appendChild(name);
653
+ item.appendChild(button);
654
+ ingredientsList.appendChild(item);
655
+ });
656
+ }
657
 
658
+ function displayCustomizationIngredients(ingredients) {
659
+ const chatMessages = document.getElementById('chatMessages');
660
+ if (!chatMessages) {
661
+ console.error('Chat messages container not found for customization ingredients!');
662
+ return;
663
+ }
664
 
665
+ let ingredientsList = document.querySelector('.customization-ingredients-list');
666
+ if (!ingredientsList) {
667
+ ingredientsList = document.createElement('div');
668
+ ingredientsList.className = 'customization-ingredients-list';
669
+ chatMessages.appendChild(ingredientsList);
670
+ } else {
671
+ ingredientsList.innerHTML = '';
672
+ }
 
 
 
 
 
673
 
674
+ ingredients.forEach(ingredient => {
675
+ const item = document.createElement('div');
676
+ item.className = 'ingredient-item';
677
+ const img = document.createElement('img');
678
+ img.src = ingredient.image_url || 'https://via.placeholder.com/120';
679
+ img.alt = ingredient.name;
680
+ const name = document.createElement('div');
681
+ name.textContent = ingredient.name;
682
+ const button = document.createElement('button');
683
+ button.textContent = 'Add';
684
+ button.onclick = () => {
685
+ if (!selectedIngredients.some(item => item.name === ingredient.name)) {
686
+ selectedIngredients.push(ingredient);
687
+ displaySelectedIngredientsForCustomization();
 
 
 
 
 
 
 
 
 
 
688
  }
689
  };
690
+ item.appendChild(img);
691
+ item.appendChild(name);
692
+ item.appendChild(button);
693
+ ingredientsList.appendChild(item);
694
+ });
695
+ }
696
 
697
+ function displaySelectedIngredientsForCustomization() {
698
+ const chatMessages = document.getElementById('chatMessages');
699
+ if (!chatMessages) {
700
+ console.error('Chat messages container not found for selected ingredients!');
701
+ return;
702
+ }
703
+
704
+ let selectedArea = document.querySelector('.selected-ingredients');
705
+ if (!selectedArea) {
706
+ selectedArea = document.createElement('div');
707
+ selectedArea.className = 'selected-ingredients';
708
+ chatMessages.appendChild(selectedArea);
709
+ } else {
710
+ selectedArea.innerHTML = '';
711
+ }
712
+
713
+ selectedIngredients.forEach(ingredient => {
714
+ const div = document.createElement('div');
715
+ div.textContent = ingredient.name;
716
+ selectedArea.appendChild(div);
717
  });
718
+ }
719
 
720
+ function displayMenuItems(menuItems) {
721
+ const chatMessages = document.getElementById('chatMessages');
722
+ if (!chatMessages) {
723
+ console.error('Chat messages container not found for menu items!');
724
+ return;
725
+ }
726
+
727
+ let menuItemsList = document.querySelector('.menu-items-list');
728
+ if (!menuItemsList) {
729
+ menuItemsList = document.createElement('div');
730
+ menuItemsList.className = 'menu-items-list';
731
+ chatMessages.appendChild(menuItemsList);
732
+ } else {
733
+ menuItemsList.innerHTML = '';
734
+ }
735
+
736
+ menuItems.forEach(item => {
737
+ const menuItem = document.createElement('div');
738
+ menuItem.className = 'menu-item';
739
+ const img = document.createElement('img');
740
+ img.src = item.image_url || 'https://via.placeholder.com/120';
741
+ img.alt = item.name;
742
+ const name = document.createElement('div');
743
+ name.textContent = item.name;
744
+ const button = document.createElement('button');
745
+ button.textContent = 'Add to Cart';
746
+ button.onclick = () => {
747
+ selectedMenuItem = item;
748
+ addMessage('bot', `World-class selection! Would you like to customize your dish further?`);
749
+ const options = [
750
+ { text: 'Yes', class: 'green' },
751
+ { text: 'No', class: 'red' }
752
+ ];
753
+ displayOptions(options);
754
+ };
755
+ menuItem.appendChild(img);
756
+ menuItem.appendChild(name);
757
+ menuItem.appendChild(button);
758
+ menuItemsList.appendChild(menuItem);
759
+ });
760
  }
761
 
762
+ function displayCustomizationInput() {
763
+ const chatMessages = document.getElementById('chatMessages');
764
+ if (!chatMessages) {
765
+ console.error('Chat messages container not found for customization input!');
766
+ return;
767
+ }
768
+
769
+ let customizationArea = document.querySelector('.customization-input');
770
+ if (!customizationArea) {
771
+ customizationArea = document.createElement('div');
772
+ customizationArea.className = 'customization-input';
773
+ const textarea = document.createElement('textarea');
774
+ textarea.placeholder = 'Enter any special instructions...';
775
+ const submitButton = document.createElement('button');
776
+ submitButton.textContent = 'Submit Instructions';
777
+ submitButton.onclick = () => {
778
+ const instructions = textarea.value.trim();
779
+ addToCart({ ...selectedMenuItem, instructions, ingredients: selectedIngredients });
780
+ addMessage('bot', 'Item added to cart! Would you like to order more?');
781
+ const options = [
782
+ { text: 'Yes', class: 'green' },
783
+ { text: 'No', class: 'red' }
784
+ ];
785
+ displayOptions(options);
786
+ selectedMenuItem = null;
787
+ selectedIngredients = [];
788
+ updateCartDisplay();
789
+ };
790
+ customizationArea.appendChild(textarea);
791
+ customizationArea.appendChild(submitButton);
792
+ chatMessages.appendChild(customizationArea);
793
+ }
794
+ }
795
+
796
+ function addToCart(item) {
797
+ const cartItem = {
798
+ name: item.name,
799
+ image_url: item.image_url || '',
800
+ category: item.veg_nonveg || 'Not specified',
801
+ description: item.description || 'No description available',
802
+ instructions: item.instructions || '',
803
+ ingredients: item.ingredients || [],
804
+ quantity: 1,
805
+ ingredientsInfo: ''
806
+ };
807
+ cart.push(cartItem);
808
+ console.log('Cart:', cart);
809
+ updateCartDisplay();
810
+ }
811
+
812
+ function updateCartDisplay() {
813
+ const chatMessages = document.getElementById('chatMessages');
814
+ if (!chatMessages) return;
815
+
816
+ let cartArea = document.querySelector('.cart-items');
817
+ if (!cartArea) {
818
+ cartArea = document.createElement('div');
819
+ cartArea.className = 'cart-items';
820
+ chatMessages.appendChild(cartArea);
821
  } else {
822
+ cartArea.innerHTML = '';
823
+ }
824
+
825
+ if (cart.length > 0) {
826
+ const label = document.createElement('div');
827
+ label.textContent = 'Cart:';
828
+ cartArea.appendChild(label);
829
+
830
+ cart.forEach((item, index) => {
831
+ const itemDiv = document.createElement('div');
832
+ itemDiv.className = 'cart-item';
833
+
834
+ const img = document.createElement('img');
835
+ img.src = item.image_url || 'https://via.placeholder.com/30';
836
+ img.alt = item.name;
837
+ itemDiv.appendChild(img);
838
+
839
+ const contentDiv = document.createElement('div');
840
+ const itemText = item.instructions
841
+ ? `${item.name} (${item.instructions})`
842
+ : item.name;
843
+ contentDiv.textContent = `${itemText} (Qty: ${item.quantity})`;
844
+ if (item.ingredients.length > 0) {
845
+ contentDiv.textContent += ` with ${item.ingredients.map(i => i.name).join(', ')}`;
846
+ }
847
+ itemDiv.appendChild(contentDiv);
848
+
849
+ const infoInput = document.createElement('input');
850
+ infoInput.type = 'text';
851
+ infoInput.placeholder = 'Add ingredient details...';
852
+ infoInput.className = 'ingredient-info-input';
853
+ infoInput.value = item.ingredientsInfo || '';
854
+ infoInput.addEventListener('input', (e) => {
855
+ cart[index].ingredientsInfo = e.target.value;
856
+ });
857
+ itemDiv.appendChild(infoInput);
858
+
859
+ const removeButton = document.createElement('button');
860
+ removeButton.textContent = 'X';
861
+ removeButton.className = 'remove-button';
862
+ removeButton.onclick = () => {
863
+ cart.splice(index, 1);
864
+ addMessage('bot', `Removed "${item.name}" from cart.`);
865
+ updateCartDisplay();
866
+ };
867
+ itemDiv.appendChild(removeButton);
868
+
869
+ cartArea.appendChild(itemDiv);
870
+ });
871
+
872
+ let submitArea = document.querySelector('.submit-cart');
873
+ if (!submitArea) {
874
+ submitArea = document.createElement('div');
875
+ submitArea.className = 'submit-cart';
876
+ const orderNameInput = document.createElement('input');
877
+ orderNameInput.type = 'text';
878
+ orderNameInput.placeholder = 'Order Name';
879
+ orderNameInput.className = 'order-name-input';
880
+ const quantityInput = document.createElement('input');
881
+ quantityInput.type = 'number';
882
+ quantityInput.min = '1';
883
+ quantityInput.value = '1';
884
+ quantityInput.className = 'quantity-input';
885
+ const submitButton = document.createElement('button');
886
+ submitButton.textContent = 'Submit Cart';
887
+ submitButton.className = 'submit-button';
888
+ submitButton.onclick = () => {
889
+ submitCart(orderNameInput.value, quantityInput.value);
890
+ };
891
+ submitArea.appendChild(orderNameInput);
892
+ submitArea.appendChild(quantityInput);
893
+ submitArea.appendChild(submitButton);
894
+ chatMessages.appendChild(submitArea);
895
+ }
896
  }
897
+
898
+ chatMessages.scrollTop = chatMessages.scrollHeight;
899
  }
900
 
901
+ function submitCart(customOrderName, quantity) {
902
  if (cart.length === 0) {
903
  addMessage('bot', 'No items in cart! Add some dishes! 😊');
904
  return;
905
  }
906
 
907
+ if (confirm(`Submit ${cart.length} items (Qty: ${quantity}) as- const itemsToSubmit = cart.map(item => ({
908
  name: item.name,
909
+ category: item.category,
910
+ description: item.description,
911
+ image_url: item.image_url,
912
  quantity: parseInt(quantity) || 1,
913
+ instructions: item.instructions,
914
+ ingredients: item.ingredients,
915
+ ingredientsInfo: item.ingredientsInfo
916
  }));
917
 
918
  fetch('/submit_ingredients', {
 
921
  body: JSON.stringify({
922
  items: itemsToSubmit,
923
  custom_order_name: customOrderName,
924
+ ingredients_info: ''
925
  })
926
  })
927
  .then(response => response.json())
 
931
  } else {
932
  addMessage('bot', `Submitted ${data.ingredient_name}! What's next?`);
933
  cart = [];
934
+ selectedIngredients = [];
935
+ selectedMenuItem = null;
936
+ updateCartDisplay();
937
  }
938
  })
939
  .catch(error => {
940
  addMessage('bot', `Submission error: ${error.message}. Retrying...`);
941
+ setTimeout(() => submitCart(customOrderName, quantity), 2000);
942
  });
943
  }
944
 
945
+ function displayOptions(options) {
946
+ const chatMessages = document.getElementById('chatMessages');
947
+ if (!chatMessages) {
948
+ console.error('Chat messages container not found for options!');
949
+ return;
950
+ }
951
+ options.forEach(opt => {
952
+ const button = document.createElement('button');
953
+ button.textContent = opt.text;
954
+ button.className = `option-button ${opt.class}`;
955
+ button.onclick = () => {
956
+ addMessage('user', opt.text);
957
+ conversation.push({ role: 'user', message: opt.text });
958
+ setTimeout(() => handleResponse(opt.text), 500);
959
+ };
960
+ chatMessages.appendChild(button);
961
+ });
962
+ chatMessages.appendChild(document.createElement('br'));
963
+ const backButton = document.createElement('button');
964
+ backButton.textContent = 'Go Back';
965
+ backButton.className = 'option-button';
966
+ backButton.onclick = () => {
967
+ conversation.pop();
968
+ selectedIngredients = [];
969
+ selectedMenuItem = null;
970
+ setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
971
+ };
972
+ chatMessages.appendChild(backButton);
973
+ chatMessages.scrollTop = chatMessages.scrollHeight;
974
+ }
975
+
976
+ document.getElementById('userInput').addEventListener('keypress', function(e) {
977
+ if (e.key === 'Enter') {
978
+ sendMessage();
979
+ }
980
  });
981
 
982
+ console.log('Script loaded successfully');
 
 
983
  </script>
984
  </body>
985
  </html>