lokesh341 commited on
Commit
b246a92
·
verified ·
1 Parent(s): 51e9210

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +768 -210
templates/index.html CHANGED
@@ -6,36 +6,33 @@
6
  <title>Chef Bot</title>
7
  <style>
8
  body {
9
- font-family: 'Segoe UI', Arial, sans-serif;
10
  margin: 0;
11
  padding: 0;
12
- background-color: #f4f6f8;
13
  overflow-x: hidden;
14
  }
15
 
16
  .chat-container {
17
  width: 100%;
18
- max-width: 800px;
19
  height: 100vh;
20
  margin: 0 auto;
21
- border: 1px solid #ddd;
22
- border-radius: 10px;
23
- background-color: #fff;
24
  display: flex;
25
  flex-direction: column;
26
  box-sizing: border-box;
27
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
28
  }
29
 
30
  .chat-header {
31
- background-color: #0288d1;
32
  color: white;
33
  padding: 12px;
34
  text-align: center;
35
- font-size: 20px;
36
- font-weight: bold;
37
  flex-shrink: 0;
38
- border-radius: 10px 10px 0 0;
39
  }
40
 
41
  .chat-messages {
@@ -52,13 +49,12 @@
52
  border-radius: 8px;
53
  max-width: 80%;
54
  word-wrap: break-word;
55
- font-size: 14px;
56
- line-height: 1.4;
57
  }
58
 
59
  .bot-message {
60
  background-color: #e3f2fd;
61
- margin-right: 10%;
62
  }
63
 
64
  .user-message {
@@ -67,36 +63,41 @@
67
  text-align: right;
68
  }
69
 
 
 
 
 
 
70
  .chat-input {
71
  display: flex;
72
  padding: 10px;
73
- border-top: 1px solid #ddd;
74
  flex-shrink: 0;
75
- background-color: #fff;
76
  box-sizing: border-box;
77
  }
78
 
79
  .chat-input input {
80
  flex: 1;
81
- padding: 10px;
82
  border: 1px solid #ccc;
83
  border-radius: 8px;
84
- font-size: 14px;
85
  min-height: 40px;
86
  box-sizing: border-box;
87
  }
88
 
89
  .chat-input button {
90
- padding: 10px 16px;
91
- margin-left: 10px;
92
  background-color: #ff8f00;
93
  color: white;
94
  border: none;
95
  border-radius: 8px;
96
  cursor: pointer;
97
- font-size: 14px;
98
  min-height: 40px;
99
- min-width: 80px;
100
  }
101
 
102
  .chat-input button:hover {
@@ -105,10 +106,10 @@
105
 
106
  .items-grid {
107
  display: grid;
108
- grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
109
  gap: 12px;
110
- padding: 10px;
111
- margin: 10px 0;
112
  background-color: #f9f9f9;
113
  border-radius: 8px;
114
  }
@@ -117,33 +118,39 @@
117
  background-color: white;
118
  border: 1px solid #ddd;
119
  border-radius: 8px;
120
- padding: 10px;
121
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
122
- transition: transform 0.2s;
123
  }
124
 
125
  .item-card:hover {
126
- transform: translateY(-3px);
 
127
  }
128
 
129
  .item-image {
130
  width: 100%;
131
  height: 120px;
132
  object-fit: cover;
133
- border-radius: 6px;
134
  margin-bottom: 8px;
 
 
 
 
 
135
  }
136
 
137
  .item-name {
138
- font-size: 16px;
139
  font-weight: bold;
140
  color: #333;
141
- margin-bottom: 6px;
142
  }
143
 
144
  .item-field {
145
- font-size: 12px;
146
- margin: 4px 0;
147
  color: #555;
148
  }
149
 
@@ -151,134 +158,242 @@
151
  color: #0288d1;
152
  }
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  .add-button {
155
- width: 100%;
156
- padding: 8px;
157
  background-color: #4caf50;
158
  color: white;
159
- border: none;
160
- border-radius: 6px;
161
- cursor: pointer;
162
- font-size: 14px;
163
- margin-top: 8px;
164
  }
165
 
166
  .add-button:hover {
167
  background-color: #45a049;
168
  }
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  .selection-box {
171
  background-color: #e1f5fe;
172
- padding: 10px;
173
  border: 1px solid #0288d1;
174
  border-radius: 8px;
175
- margin: 10px 0;
176
- font-size: 14px;
177
  display: flex;
178
  flex-wrap: wrap;
179
- gap: 8px;
180
  align-items: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  }
182
 
183
  .selected-item {
184
  display: flex;
185
  align-items: center;
186
  background-color: #bbdefb;
187
- padding: 6px 10px;
188
- border-radius: 6px;
189
- font-size: 13px;
190
  }
191
 
192
  .selected-item-image {
193
  width: 30px;
194
  height: 30px;
195
  object-fit: cover;
196
- border-radius: 6px;
197
  margin-right: 8px;
 
198
  }
199
 
200
- .remove-button {
201
- padding: 4px 8px;
202
- margin-left: 8px;
203
- background-color: #d32f2f;
204
  color: white;
205
  border: none;
206
- border-radius: 6px;
207
  cursor: pointer;
208
- font-size: 12px;
 
209
  }
210
 
211
- .remove-button:hover {
212
- background-color: #b71c1c;
213
  }
214
 
215
- .submit-button {
216
- padding: 10px 16px;
217
- background-color: #0288d1;
 
218
  color: white;
219
  border: none;
220
  border-radius: 8px;
221
  cursor: pointer;
222
- font-size: 14px;
223
- min-width: 80px;
224
  }
225
 
226
- .submit-button:hover {
227
- background-color: #0277bd;
228
  }
229
 
230
  .manual-input, .order-name-input {
231
- padding: 8px;
232
  border: 1px solid #0288d1;
233
- border-radius: 6px;
234
- font-size: 14px;
235
  width: 120px;
236
  }
237
 
238
  .quantity-input {
239
- padding: 8px;
240
  border: 1px solid #0288d1;
241
- border-radius: 6px;
242
- font-size: 14px;
243
  width: 60px;
244
  }
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  @media (max-width: 480px) {
247
  .chat-container {
248
  border-radius: 0;
249
- box-shadow: none;
250
  }
251
 
252
  .chat-header {
253
- font-size: 16px;
254
- padding: 10px;
255
  }
256
 
257
  .chat-messages {
258
- padding: 8px;
259
  }
260
 
261
  .bot-message, .user-message {
262
- font-size: 12px;
263
  padding: 8px;
264
  margin: 6px 0;
265
  }
266
 
267
  .chat-input input {
268
- font-size: 12px;
269
  min-height: 36px;
 
270
  }
271
 
272
  .chat-input button {
273
- font-size: 12px;
274
  min-height: 36px;
275
- padding: 8px 12px;
276
- min-width: 70px;
277
  }
278
 
279
  .items-grid {
280
- grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
281
- gap: 10px;
 
 
 
 
 
282
  }
283
 
284
  .item-image {
@@ -286,16 +401,29 @@
286
  }
287
 
288
  .item-name {
289
- font-size: 14px;
290
  }
291
 
292
- .item-field {
293
- font-size: 11px;
294
  }
295
 
296
- .add-button {
297
- font-size: 12px;
298
- padding: 6px;
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  }
300
 
301
  .selection-box {
@@ -303,29 +431,164 @@
303
  gap: 6px;
304
  }
305
 
 
 
 
 
 
 
 
 
 
 
306
  .selected-item {
307
- font-size: 12px;
308
- padding: 4px 8px;
309
  }
310
 
311
  .selected-item-image {
312
- width: 25px;
313
- height: 25px;
 
 
 
 
 
 
314
  }
315
 
316
  .remove-button {
317
- font-size: 10px;
318
  padding: 3px 6px;
319
  }
320
 
321
  .manual-input, .order-name-input {
322
  width: 100px;
323
- font-size: 12px;
 
324
  }
325
 
326
  .quantity-input {
327
  width: 50px;
328
- font-size: 12px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  }
330
  }
331
  </style>
@@ -333,12 +596,14 @@
333
  <body>
334
  <div class="chat-container">
335
  <div class="chat-header">🍳 Chef Bot</div>
336
- <div class="chat-messages" id="chatMessages">
337
  <div class="bot-message">Hello! I’m Chef Bot, your culinary assistant! What’s your name?</div>
338
  </div>
 
 
339
  <div class="chat-input">
340
- <input type="text" id="userInput" placeholder="Type here (e.g., chicken, paneer)...">
341
- <button onclick="sendMessage()">Send</button>
342
  </div>
343
  </div>
344
  <script>
@@ -346,25 +611,46 @@
346
  { role: 'bot', message: 'Hello! I’m Chef Bot, your culinary assistant! What’s your name?' }
347
  ];
348
  let selectedItems = [];
 
349
 
350
  function addMessage(role, message) {
351
  const chatMessages = document.getElementById('chatMessages');
 
 
 
 
352
  const messageDiv = document.createElement('div');
353
  messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message';
354
  messageDiv.textContent = message;
355
  chatMessages.appendChild(messageDiv);
356
  chatMessages.scrollTop = chatMessages.scrollHeight;
 
 
 
 
 
 
 
 
 
357
  }
358
 
359
  function sendMessage() {
360
  const userInput = document.getElementById('userInput');
 
 
 
 
361
  const message = userInput.value.trim();
362
  if (message) {
363
  addMessage('user', message);
364
- conversation.push({ role: 'user', message });
 
365
  handleResponse(message);
 
366
  } else {
367
- addMessage('bot', 'Please type a dish or ingredient! 😄');
 
368
  }
369
  userInput.value = '';
370
  updateSelectionBox();
@@ -375,83 +661,271 @@
375
  let botResponse = '';
376
 
377
  if (conversation.length === 2) {
378
- botResponse = `Hi ${userInput}! 🍳 Search for a dish or ingredient (e.g., chicken)!`;
 
 
 
 
 
379
  addMessage('bot', botResponse);
 
 
 
 
380
  } else {
381
- botResponse = `Looking for "${userInput}" dishes...`;
382
  addMessage('bot', botResponse);
383
  fetchMenuItems(null, userInput);
384
  }
385
  }
386
 
387
- function fetchMenuItems(dietaryPreference = '', searchTerm = '') {
388
- // Mock API response for chicken
389
- const mockData = {
390
- menu_items: [
391
- {
392
- name: 'Chicken Curry',
393
- image_url: 'https://example.com/chicken_curry.jpg',
394
- category: 'Main Course',
395
- description: 'Spicy chicken curry with rich flavors.',
396
- source: 'Menu',
397
- price: 12.99,
398
- veg_nonveg: 'Non-Vegetarian',
399
- spice_levels: 'Medium',
400
- ingredients: 'Chicken, spices, tomatoes',
401
- nutritional_info: '500 kcal',
402
- sector: 'Indian'
403
- },
404
- {
405
- name: 'Grilled Chicken',
406
- image_url: 'https://example.com/grilled_chicken.jpg',
407
- category: 'Main Course',
408
- description: 'Juicy grilled chicken breast.',
409
- source: 'Menu',
410
- price: 10.99,
411
- veg_nonveg: 'Non-Vegetarian',
412
- spice_levels: 'Low',
413
- ingredients: 'Chicken, herbs',
414
- nutritional_info: '400 kcal',
415
- sector: 'Western'
416
- }
417
- ]
418
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
 
420
- const data = mockData;
421
- if (data.menu_items.length > 0) {
422
- addMessage('bot', `--- Found ${data.menu_items.length} item${data.menu_items.length > 1 ? 's' : ''} ---`);
423
- displayItemsList(data.menu_items);
424
- if (searchTerm.toLowerCase() === 'chicken') {
425
- fetchSectorItemDetails(searchTerm);
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  }
427
- } else {
428
- addMessage('bot', `No matches for "${searchTerm}". Try "chicken"!`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
  }
431
 
432
  function fetchSectorItemDetails(itemName) {
433
- // Mock sector item details for chicken
434
- const mockSectorData = {
435
- item_details: {
436
- name: 'Chicken Masala Powder',
437
- image_url: 'https://example.com/masala.jpg',
438
- category: 'Spice',
439
- description: 'Perfect spice mix for chicken dishes.',
440
- source: 'Sector_Detail__c',
441
- quantity: 1
442
- }
443
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
 
445
- const details = mockSectorData.item_details;
446
- if (!selectedItems.some(item => item.name === details.name)) {
447
- selectedItems.push({ ...details, quantity: 1 });
448
- addMessage('bot', `Added complementary "${details.name}"!`);
449
- updateSelectionBox();
 
 
 
 
 
 
 
 
 
 
450
  }
451
  }
452
 
453
  function displayItemsList(items) {
454
  const chatMessages = document.getElementById('chatMessages');
 
 
 
 
 
 
 
455
  const itemsGrid = document.createElement('div');
456
  itemsGrid.className = 'items-grid';
457
 
@@ -465,40 +939,70 @@
465
  img.className = 'item-image';
466
  itemDiv.appendChild(img);
467
 
 
 
 
468
  const nameDiv = document.createElement('div');
469
  nameDiv.textContent = item.name;
470
  nameDiv.className = 'item-name';
471
- itemDiv.appendChild(nameDiv);
472
 
473
  const fields = [
474
  { label: 'Price', value: item.price ? `$${item.price.toFixed(2)}` : 'N/A' },
475
- { label: 'Category', value: item.category },
476
  { label: 'Spice', value: item.spice_levels },
477
- { label: 'Ingredients', value: item.ingredients }
 
 
 
 
478
  ];
479
  fields.forEach(field => {
480
  if (field.value) {
481
  const p = document.createElement('p');
482
  p.className = 'item-field';
483
  p.innerHTML = `<strong>${field.label}:</strong> ${field.value}`;
484
- itemDiv.appendChild(p);
485
  }
486
  });
487
 
 
 
 
 
 
488
  const addButton = document.createElement('button');
489
  addButton.textContent = 'Add';
490
  addButton.className = 'add-button';
491
  addButton.onclick = () => {
492
- if (!selectedItems.some(existing => existing.name === item.name)) {
493
- selectedItems.push({ ...item, quantity: 1 });
494
- addMessage('bot', `Added "${item.name}"!`);
495
- updateSelectionBox();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  } else {
497
- addMessage('bot', `"${item.name}" already selected!`);
 
 
 
498
  }
499
  };
500
- itemDiv.appendChild(addButton);
501
 
 
502
  itemsGrid.appendChild(itemDiv);
503
  });
504
 
@@ -506,62 +1010,116 @@
506
  chatMessages.scrollTop = chatMessages.scrollHeight;
507
  }
508
 
509
- function updateSelectionBox() {
510
  const chatMessages = document.getElementById('chatMessages');
511
- const existingBox = document.querySelector('.selection-box');
512
- if (existingBox) existingBox.remove();
513
-
514
- if (selectedItems.length === 0) return;
515
-
516
- const selectionBox = document.createElement('div');
517
- selectionBox.className = 'selection-box';
518
-
519
- selectedItems.forEach((item, index) => {
520
- const itemContainer = document.createElement('div');
521
- itemContainer.className = 'selected-item';
 
 
 
 
 
 
 
 
 
 
522
 
523
- const img = document.createElement('img');
524
- img.src = item.image_url || 'https://via.placeholder.com/30';
525
- img.alt = item.name;
526
- img.className = 'selected-item-image';
527
- itemContainer.appendChild(img);
528
 
529
- const itemSpan = document.createElement('span');
530
- itemSpan.textContent = `${item.name} (Qty: ${item.quantity})`;
531
- itemContainer.appendChild(itemSpan);
532
 
533
- const removeButton = document.createElement('button');
534
- removeButton.textContent = 'X';
535
- removeButton.className = 'remove-button';
536
- removeButton.onclick = () => {
537
- selectedItems.splice(index, 1);
538
- addMessage('bot', `Removed "${item.name}".`);
539
- updateSelectionBox();
540
- };
541
- itemContainer.appendChild(removeButton);
 
 
542
 
543
- selectionBox.appendChild(itemContainer);
544
- });
 
 
 
 
545
 
546
- const submitButton = document.createElement('button');
547
- submitButton.textContent = 'Submit Order';
548
- submitButton.className = 'submit-button';
549
- submitButton.onclick = () => {
550
- if (selectedItems.length > 0) {
551
- addMessage('bot', `Order submitted with ${selectedItems.length} items!`);
552
- selectedItems = [];
553
- updateSelectionBox();
554
- }
555
- };
556
- selectionBox.appendChild(submitButton);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
 
558
- chatMessages.appendChild(selectionBox);
559
- chatMessages.scrollTop = chatMessages.scrollHeight;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560
  }
561
 
562
  document.getElementById('userInput').addEventListener('keypress', (e) => {
563
  if (e.key === 'Enter') sendMessage();
564
  });
 
 
565
  </script>
566
  </body>
567
  </html>
 
6
  <title>Chef Bot</title>
7
  <style>
8
  body {
9
+ font-family: 'Arial', sans-serif;
10
  margin: 0;
11
  padding: 0;
12
+ background-color: #f0f2f5;
13
  overflow-x: hidden;
14
  }
15
 
16
  .chat-container {
17
  width: 100%;
18
+ max-width: 1200px;
19
  height: 100vh;
20
  margin: 0 auto;
21
+ border: 1px solid #ccc;
22
+ border-radius: 8px;
23
+ background-color: white;
24
  display: flex;
25
  flex-direction: column;
26
  box-sizing: border-box;
 
27
  }
28
 
29
  .chat-header {
30
+ background: linear-gradient(45deg, #0288d1, #03a9f4);
31
  color: white;
32
  padding: 12px;
33
  text-align: center;
34
+ font-size: 1.25rem;
 
35
  flex-shrink: 0;
 
36
  }
37
 
38
  .chat-messages {
 
49
  border-radius: 8px;
50
  max-width: 80%;
51
  word-wrap: break-word;
52
+ font-size: 0.875rem;
53
+ animation: slideIn 0.3s ease;
54
  }
55
 
56
  .bot-message {
57
  background-color: #e3f2fd;
 
58
  }
59
 
60
  .user-message {
 
63
  text-align: right;
64
  }
65
 
66
+ @keyframes slideIn {
67
+ from { transform: translateY(20px); opacity: 0; }
68
+ to { transform: translateY(0); opacity: 1; }
69
+ }
70
+
71
  .chat-input {
72
  display: flex;
73
  padding: 10px;
74
+ border-top: 1px solid #ccc;
75
  flex-shrink: 0;
76
+ background-color: white;
77
  box-sizing: border-box;
78
  }
79
 
80
  .chat-input input {
81
  flex: 1;
82
+ padding: 8px;
83
  border: 1px solid #ccc;
84
  border-radius: 8px;
85
+ font-size: 0.875rem;
86
  min-height: 40px;
87
  box-sizing: border-box;
88
  }
89
 
90
  .chat-input button {
91
+ padding: 8px 12px;
92
+ margin-left: 8px;
93
  background-color: #ff8f00;
94
  color: white;
95
  border: none;
96
  border-radius: 8px;
97
  cursor: pointer;
98
+ font-size: 0.875rem;
99
  min-height: 40px;
100
+ min-width: 70px;
101
  }
102
 
103
  .chat-input button:hover {
 
106
 
107
  .items-grid {
108
  display: grid;
109
+ grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
110
  gap: 12px;
111
+ padding: 12px;
112
+ margin: 8px 0;
113
  background-color: #f9f9f9;
114
  border-radius: 8px;
115
  }
 
118
  background-color: white;
119
  border: 1px solid #ddd;
120
  border-radius: 8px;
121
+ padding: 12px;
122
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
123
+ transition: transform 0.2s ease, box-shadow 0.2s ease;
124
  }
125
 
126
  .item-card:hover {
127
+ transform: scale(1.05);
128
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
129
  }
130
 
131
  .item-image {
132
  width: 100%;
133
  height: 120px;
134
  object-fit: cover;
135
+ border-radius: 8px;
136
  margin-bottom: 8px;
137
+ loading: lazy;
138
+ }
139
+
140
+ .item-content {
141
+ width: 100%;
142
  }
143
 
144
  .item-name {
145
+ font-size: 0.875rem;
146
  font-weight: bold;
147
  color: #333;
148
+ margin-bottom: 5px;
149
  }
150
 
151
  .item-field {
152
+ font-size: 0.75rem;
153
+ margin: 3px 0;
154
  color: #555;
155
  }
156
 
 
158
  color: #0288d1;
159
  }
160
 
161
+ .item-description {
162
+ font-size: 0.75rem;
163
+ margin: 5px 0;
164
+ color: #555;
165
+ }
166
+
167
+ .button-container {
168
+ display: flex;
169
+ gap: 8px;
170
+ margin-top: 8px;
171
+ }
172
+
173
+ .show-button, .add-button {
174
+ padding: 6px;
175
+ border: none;
176
+ border-radius: 8px;
177
+ cursor: pointer;
178
+ font-size: 0.75rem;
179
+ flex: 1;
180
+ min-width: 50px;
181
+ }
182
+
183
+ .show-button {
184
+ background-color: #0288d1;
185
+ color: white;
186
+ }
187
+
188
+ .show-button:hover {
189
+ background-color: #0277bd;
190
+ }
191
+
192
  .add-button {
 
 
193
  background-color: #4caf50;
194
  color: white;
 
 
 
 
 
195
  }
196
 
197
  .add-button:hover {
198
  background-color: #45a049;
199
  }
200
 
201
+ .options-container {
202
+ display: flex;
203
+ flex-wrap: wrap;
204
+ gap: 8px;
205
+ margin: 8px 0;
206
+ }
207
+
208
+ .option-button {
209
+ padding: 8px 12px;
210
+ background-color: #7b1fa2;
211
+ color: white;
212
+ border: none;
213
+ border-radius: 8px;
214
+ cursor: pointer;
215
+ font-size: 0.875rem;
216
+ min-width: 70px;
217
+ }
218
+
219
+ .option-button.green { background-color: #4caf50; }
220
+ .option-button.red { background-color: #d32f2f; }
221
+ .option-button.gray { background-color: #616161; }
222
+ .option-button:hover { opacity: 0.9; }
223
+
224
  .selection-box {
225
  background-color: #e1f5fe;
226
+ padding: 12px;
227
  border: 1px solid #0288d1;
228
  border-radius: 8px;
229
+ margin: 8px 0;
230
+ font-size: 0.875rem;
231
  display: flex;
232
  flex-wrap: wrap;
 
233
  align-items: center;
234
+ gap: 8px;
235
+ position: relative;
236
+ }
237
+
238
+ .selection-box::before {
239
+ content: "Selected Items";
240
+ position: sticky;
241
+ top: 0;
242
+ background: #0288d1;
243
+ color: white;
244
+ padding: 8px;
245
+ border-radius: 8px 8px 0 0;
246
+ font-size: 0.875rem;
247
+ width: 100%;
248
+ box-sizing: border-box;
249
+ }
250
+
251
+ .selection-box span {
252
+ background-color: #bbdefb;
253
+ padding: 4px 10px;
254
+ border-radius: 8px;
255
+ font-size: 0.875rem;
256
  }
257
 
258
  .selected-item {
259
  display: flex;
260
  align-items: center;
261
  background-color: #bbdefb;
262
+ padding: 4px 10px;
263
+ border-radius: 8px;
264
+ font-size: 0.75rem;
265
  }
266
 
267
  .selected-item-image {
268
  width: 30px;
269
  height: 30px;
270
  object-fit: cover;
271
+ border-radius: 8px;
272
  margin-right: 8px;
273
+ loading: lazy;
274
  }
275
 
276
+ .submit-button {
277
+ padding: 8px 12px;
278
+ background-color: #0288d1;
 
279
  color: white;
280
  border: none;
281
+ border-radius: 8px;
282
  cursor: pointer;
283
+ font-size: 0.875rem;
284
+ min-width: 70px;
285
  }
286
 
287
+ .submit-button:hover {
288
+ background-color: #0277bd;
289
  }
290
 
291
+ .remove-button {
292
+ padding: 4px 8px;
293
+ margin-left: 8px;
294
+ background-color: #d32f2f;
295
  color: white;
296
  border: none;
297
  border-radius: 8px;
298
  cursor: pointer;
299
+ font-size: 0.75rem;
 
300
  }
301
 
302
+ .remove-button:hover {
303
+ background-color: #b71c1c;
304
  }
305
 
306
  .manual-input, .order-name-input {
307
+ padding: 6px;
308
  border: 1px solid #0288d1;
309
+ border-radius: 8px;
310
+ font-size: 0.875rem;
311
  width: 120px;
312
  }
313
 
314
  .quantity-input {
315
+ padding: 6px;
316
  border: 1px solid #0288d1;
317
+ border-radius: 8px;
318
+ font-size: 0.875rem;
319
  width: 60px;
320
  }
321
 
322
+ .spinner {
323
+ border: 4px solid #0288d1;
324
+ border-top: 4px solid transparent;
325
+ border-radius: 50%;
326
+ width: 24px;
327
+ height: 24px;
328
+ animation: spin 1s linear infinite;
329
+ margin: 10px auto;
330
+ }
331
+
332
+ @keyframes spin {
333
+ to { transform: rotate(360deg); }
334
+ }
335
+
336
+ .toast {
337
+ position: fixed;
338
+ bottom: 20px;
339
+ right: 20px;
340
+ background: #4caf50;
341
+ color: white;
342
+ padding: 10px;
343
+ border-radius: 8px;
344
+ font-size: 0.875rem;
345
+ animation: fadeInOut 3s ease forwards;
346
+ z-index: 1000;
347
+ }
348
+
349
+ @keyframes fadeInOut {
350
+ 0% { opacity: 0; transform: translateY(20px); }
351
+ 10%, 90% { opacity: 1; transform: translateY(0); }
352
+ 100% { opacity: 0; transform: translateY(20px); }
353
+ }
354
+
355
  @media (max-width: 480px) {
356
  .chat-container {
357
  border-radius: 0;
358
+ height: calc(100vh - env(safe-area-inset-bottom));
359
  }
360
 
361
  .chat-header {
362
+ font-size: 1rem;
363
+ padding: 8px;
364
  }
365
 
366
  .chat-messages {
367
+ padding: 6px;
368
  }
369
 
370
  .bot-message, .user-message {
371
+ font-size: 0.75rem;
372
  padding: 8px;
373
  margin: 6px 0;
374
  }
375
 
376
  .chat-input input {
377
+ font-size: 0.75rem;
378
  min-height: 36px;
379
+ padding: 6px;
380
  }
381
 
382
  .chat-input button {
383
+ font-size: 0.75rem;
384
  min-height: 36px;
385
+ padding: 6px 10px;
386
+ min-width: 60px;
387
  }
388
 
389
  .items-grid {
390
+ grid-template-columns: 1fr;
391
+ gap: 8px;
392
+ padding: 8px;
393
+ }
394
+
395
+ .item-card {
396
+ max-width: 100%;
397
  }
398
 
399
  .item-image {
 
401
  }
402
 
403
  .item-name {
404
+ font-size: 0.75rem;
405
  }
406
 
407
+ .item-field, .item-description {
408
+ font-size: 0.625rem;
409
  }
410
 
411
+ .show-button, .add-button {
412
+ font-size: 0.625rem;
413
+ padding: 4px;
414
+ min-width: 40px;
415
+ }
416
+
417
+ .options-container {
418
+ flex-direction: column;
419
+ align-items: stretch;
420
+ gap: 6px;
421
+ }
422
+
423
+ .option-button {
424
+ font-size: 0.75rem;
425
+ padding: 6px 10px;
426
+ min-width: 100%;
427
  }
428
 
429
  .selection-box {
 
431
  gap: 6px;
432
  }
433
 
434
+ .selection-box::before {
435
+ font-size: 0.75rem;
436
+ padding: 6px;
437
+ }
438
+
439
+ .selection-box span {
440
+ font-size: 0.75rem;
441
+ padding: 3px 8px;
442
+ }
443
+
444
  .selected-item {
445
+ font-size: 0.625rem;
446
+ padding: 3px 8px;
447
  }
448
 
449
  .selected-item-image {
450
+ width: 24px;
451
+ height: 24px;
452
+ }
453
+
454
+ .submit-button {
455
+ font-size: 0.75rem;
456
+ padding: 6px 10px;
457
+ min-width: 60px;
458
  }
459
 
460
  .remove-button {
461
+ font-size: 0.625rem;
462
  padding: 3px 6px;
463
  }
464
 
465
  .manual-input, .order-name-input {
466
  width: 100px;
467
+ font-size: 0.75rem;
468
+ padding: 4px;
469
  }
470
 
471
  .quantity-input {
472
  width: 50px;
473
+ font-size: 0.75rem;
474
+ padding: 4px;
475
+ }
476
+ }
477
+
478
+ @media (min-width: 481px) and (max-width: 768px) {
479
+ .chat-container {
480
+ max-width: 100%;
481
+ }
482
+
483
+ .chat-header {
484
+ font-size: 1.125rem;
485
+ }
486
+
487
+ .chat-messages {
488
+ padding: 8px;
489
+ }
490
+
491
+ .bot-message, .user-message {
492
+ font-size: 0.875rem;
493
+ padding: 9px;
494
+ }
495
+
496
+ .chat-input input {
497
+ font-size: 0.875rem;
498
+ min-height: 38px;
499
+ }
500
+
501
+ .chat-input button {
502
+ font-size: 0.875rem;
503
+ min-height: 38px;
504
+ padding: 7px 11px;
505
+ }
506
+
507
+ .items-grid {
508
+ grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
509
+ gap: 10px;
510
+ }
511
+
512
+ .item-image {
513
+ height: 110px;
514
+ }
515
+
516
+ .item-name {
517
+ font-size: 0.875rem;
518
+ }
519
+
520
+ .item-field, .item-description {
521
+ font-size: 0.75rem;
522
+ }
523
+
524
+ .show-button, .add-button {
525
+ font-size: 0.75rem;
526
+ padding: 5px;
527
+ min-width: 45px;
528
+ }
529
+
530
+ .option-button {
531
+ font-size: 0.875rem;
532
+ padding: 7px 11px;
533
+ }
534
+
535
+ .selection-box {
536
+ padding: 10px;
537
+ gap: 7px;
538
+ }
539
+
540
+ .selection-box span {
541
+ font-size: 0.875rem;
542
+ }
543
+
544
+ .selected-item {
545
+ font-size: 0.75rem;
546
+ }
547
+
548
+ .selected-item-image {
549
+ width: 28px;
550
+ height: 28px;
551
+ }
552
+
553
+ .submit-button {
554
+ font-size: 0.875rem;
555
+ padding: 7px 11px;
556
+ }
557
+
558
+ .remove-button {
559
+ font-size: 0.75rem;
560
+ padding: 4px 7px;
561
+ }
562
+
563
+ .manual-input, .order-name-input {
564
+ width: 110px;
565
+ font-size: 0.875rem;
566
+ }
567
+
568
+ .quantity-input {
569
+ width: 55px;
570
+ font-size: 0.875rem;
571
+ }
572
+ }
573
+
574
+ @media (min-width: 769px) {
575
+ .chat-container {
576
+ display: grid;
577
+ grid-template-columns: 1fr 1fr;
578
+ gap: 10px;
579
+ }
580
+
581
+ .chat-messages, .chat-input {
582
+ grid-column: 1 / 2;
583
+ }
584
+
585
+ .suggestions-list, .ingredients-list {
586
+ grid-column: 2 / 3;
587
+ }
588
+
589
+ .selection-box {
590
+ grid-column: 2 / 3;
591
+ grid-row: 1 / 3;
592
  }
593
  }
594
  </style>
 
596
  <body>
597
  <div class="chat-container">
598
  <div class="chat-header">🍳 Chef Bot</div>
599
+ <div class="chat-messages" id="chatMessages" role="log" aria-live="polite">
600
  <div class="bot-message">Hello! I’m Chef Bot, your culinary assistant! What’s your name?</div>
601
  </div>
602
+ <div class="suggestions-list" id="suggestionsList"></div>
603
+ <div class="ingredients-list" id="menuItemsList"></div>
604
  <div class="chat-input">
605
+ <input type="text" id="userInput" placeholder="Type here (e.g., paneer, chicken)..." aria-label="Enter dish or preference">
606
+ <button onclick="sendMessage()" aria-label="Send message">Send</button>
607
  </div>
608
  </div>
609
  <script>
 
611
  { role: 'bot', message: 'Hello! I’m Chef Bot, your culinary assistant! What’s your name?' }
612
  ];
613
  let selectedItems = [];
614
+ let selectionBoxVisible = false;
615
 
616
  function addMessage(role, message) {
617
  const chatMessages = document.getElementById('chatMessages');
618
+ if (!chatMessages) {
619
+ console.error('Chat messages container not found!');
620
+ return;
621
+ }
622
  const messageDiv = document.createElement('div');
623
  messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message';
624
  messageDiv.textContent = message;
625
  chatMessages.appendChild(messageDiv);
626
  chatMessages.scrollTop = chatMessages.scrollHeight;
627
+ console.log(`Added ${role} message: ${message}`);
628
+ }
629
+
630
+ function showToast(message) {
631
+ const toast = document.createElement('div');
632
+ toast.className = 'toast';
633
+ toast.textContent = message;
634
+ document.body.appendChild(toast);
635
+ setTimeout(() => toast.remove(), 3000);
636
  }
637
 
638
  function sendMessage() {
639
  const userInput = document.getElementById('userInput');
640
+ if (!userInput) {
641
+ console.error('User input field not found!');
642
+ return;
643
+ }
644
  const message = userInput.value.trim();
645
  if (message) {
646
  addMessage('user', message);
647
+ conversation.push({ role: 'user', message: message });
648
+ selectionBoxVisible = true;
649
  handleResponse(message);
650
+ showToast(`Sent: "${message}"`);
651
  } else {
652
+ addMessage('bot', 'Please type a dish or preference! 😄');
653
+ showToast('Input is empty!');
654
  }
655
  userInput.value = '';
656
  updateSelectionBox();
 
661
  let botResponse = '';
662
 
663
  if (conversation.length === 2) {
664
+ botResponse = `Hi ${userInput}! 🍳 Search for a dish or choose a preference below!`;
665
+ displayOptions([
666
+ { text: 'Vegetarian', class: 'green' },
667
+ { text: 'Non-Vegetarian', class: 'red' },
668
+ { text: 'Both', class: 'gray' }
669
+ ]);
670
  addMessage('bot', botResponse);
671
+ } else if (lowerInput === 'vegetarian' || lowerInput === 'non-vegetarian' || lowerInput === 'both') {
672
+ botResponse = `Fetching ${lowerInput} dishes...`;
673
+ addMessage('bot', botResponse);
674
+ fetchMenuItems(lowerInput);
675
  } else {
676
+ botResponse = `Looking for "${userInput}"...`;
677
  addMessage('bot', botResponse);
678
  fetchMenuItems(null, userInput);
679
  }
680
  }
681
 
682
+ function debounce(func, wait) {
683
+ let timeout;
684
+ return function (...args) {
685
+ clearTimeout(timeout);
686
+ timeout = setTimeout(() => func.apply(this, args), wait);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
687
  };
688
+ }
689
+
690
+ function updateSelectionBox() {
691
+ const chatMessages = document.getElementById('chatMessages');
692
+ if (!chatMessages) return;
693
+
694
+ const existingBox = document.querySelector('.selection-box');
695
+ if (existingBox) existingBox.remove();
696
+
697
+ if (!selectionBoxVisible && selectedItems.length === 0) return;
698
+
699
+ const selectionBox = document.createElement('div');
700
+ selectionBox.className = 'selection-box';
701
+
702
+ const clearAllButton = document.createElement('button');
703
+ clearAllButton.textContent = 'Clear All';
704
+ clearAllButton.className = 'remove-button';
705
+ clearAllButton.onclick = () => {
706
+ selectedItems = [];
707
+ addMessage('bot', 'Cleared all items.');
708
+ showToast('All items cleared!');
709
+ updateSelectionBox();
710
+ };
711
+ selectionBox.appendChild(clearAllButton);
712
+
713
+ const vegButton = document.createElement('button');
714
+ vegButton.textContent = 'Veg';
715
+ vegButton.className = 'option-button green';
716
+ vegButton.onclick = () => {
717
+ addMessage('user', 'Vegetarian');
718
+ conversation.push({ role: 'user', message: 'Vegetarian' });
719
+ handleResponse('vegetarian');
720
+ showToast('Selected Vegetarian');
721
+ };
722
+ selectionBox.appendChild(vegButton);
723
+
724
+ const nonVegButton = document.createElement('button');
725
+ nonVegButton.textContent = 'Non-Veg';
726
+ nonVegButton.className = 'option-button red';
727
+ nonVegButton.onclick = () => {
728
+ addMessage('user', 'Non-Vegetarian');
729
+ conversation.push({ role: 'user', message: 'Non-Vegetarian' });
730
+ handleResponse('non-vegetarian');
731
+ showToast('Selected Non-Vegetarian');
732
+ };
733
+ selectionBox.appendChild(nonVegButton);
734
+
735
+ const bothButton = document.createElement('button');
736
+ bothButton.textContent = 'Both';
737
+ bothButton.className = 'option-button gray';
738
+ bothButton.onclick = () => {
739
+ addMessage('user', 'Both');
740
+ conversation.push({ role: 'user', message: 'Both' });
741
+ handleResponse('both');
742
+ showToast('Selected Both');
743
+ };
744
+ selectionBox.appendChild(bothButton);
745
+
746
+ const label = document.createElement('span');
747
+ label.textContent = 'Selected:';
748
+ selectionBox.appendChild(label);
749
+
750
+ selectedItems.forEach((item, index) => {
751
+ const itemContainer = document.createElement('div');
752
+ itemContainer.className = 'selected-item';
753
+ itemContainer.dataset.hidden = item.source === 'Sector_Detail__c' ? 'true' : 'false';
754
 
755
+ const img = document.createElement('img');
756
+ img.src = item.image_url || 'https://via.placeholder.com/30';
757
+ img.alt = item.name;
758
+ img.className = 'selected-item-image';
759
+ itemContainer.appendChild(img);
760
+
761
+ const contentDiv = document.createElement('div');
762
+ contentDiv.className = 'selected-item-content';
763
+
764
+ const itemSpan = document.createElement('span');
765
+ itemSpan.textContent = `${item.name} (Qty: ${item.quantity || 1})`;
766
+ contentDiv.appendChild(itemSpan);
767
+
768
+ if (item.source === 'Sector_Detail__c') {
769
+ const showButton = document.createElement('button');
770
+ showButton.textContent = 'Show';
771
+ showButton.className = 'show-button';
772
+ showButton.onclick = () => toggleDescription(itemContainer, item.description, item.name);
773
+ contentDiv.appendChild(showButton);
774
  }
775
+
776
+ itemContainer.appendChild(contentDiv);
777
+
778
+ const removeButton = document.createElement('button');
779
+ removeButton.textContent = 'X';
780
+ removeButton.className = 'remove-button';
781
+ removeButton.onclick = () => {
782
+ selectedItems.splice(index, 1);
783
+ addMessage('bot', `Removed "${item.name}".`);
784
+ showToast(`Removed "${item.name}"`);
785
+ updateSelectionBox();
786
+ };
787
+ itemContainer.appendChild(removeButton);
788
+
789
+ selectionBox.appendChild(itemContainer);
790
+ });
791
+
792
+ const textInput = document.createElement('input');
793
+ textInput.type = 'text';
794
+ textInput.placeholder = 'Add item...';
795
+ textInput.className = 'manual-input';
796
+ textInput.addEventListener('keypress', debounce((e) => {
797
+ if (e.key === 'Enter' && textInput.value.trim()) {
798
+ const itemName = textInput.value.trim();
799
+ fetchSectorItemDetails(itemName);
800
+ textInput.value = '';
801
+ showToast(`Searching for "${itemName}"...`);
802
+ }
803
+ }, 300));
804
+ selectionBox.appendChild(textInput);
805
+
806
+ if (selectedItems.length > 0) {
807
+ const quantityInput = document.createElement('input');
808
+ quantityInput.type = 'number';
809
+ quantityInput.min = '1';
810
+ quantityInput.value = '1';
811
+ quantityInput.placeholder = 'Qty';
812
+ quantityInput.className = 'quantity-input';
813
+ selectionBox.appendChild(quantityInput);
814
+
815
+ const submitButton = document.createElement('button');
816
+ submitButton.textContent = 'Submit';
817
+ submitButton.className = 'submit-button';
818
+ submitButton.onclick = () => promptAndSubmit(quantityInput.value);
819
+ selectionBox.appendChild(submitButton);
820
+
821
+ const orderNameInput = document.createElement('input');
822
+ orderNameInput.type = 'text';
823
+ orderNameInput.placeholder = 'Order Name';
824
+ orderNameInput.className = 'order-name-input';
825
+ selectionBox.appendChild(orderNameInput);
826
  }
827
+
828
+ chatMessages.appendChild(selectionBox);
829
+ chatMessages.scrollTop = chatMessages.scrollHeight;
830
+ console.log('Updated selection box:', selectedItems.map(item => ({ name: item.name, category: item.category })));
831
+ }
832
+
833
+ function fetchMenuItems(dietaryPreference = '', searchTerm = '') {
834
+ const payload = {};
835
+ if (dietaryPreference) payload.dietary_preference = dietaryPreference;
836
+ if (searchTerm) payload.search_term = searchTerm;
837
+
838
+ const chatMessages = document.getElementById('chatMessages');
839
+ const spinner = document.createElement('div');
840
+ spinner.className = 'spinner';
841
+ chatMessages.appendChild(spinner);
842
+
843
+ fetch('/get_menu_items', {
844
+ method: 'POST',
845
+ headers: { 'Content-Type': 'application/json' },
846
+ body: JSON.stringify(payload)
847
+ })
848
+ .then(response => response.json())
849
+ .then(data => {
850
+ spinner.remove();
851
+ if (data.error) {
852
+ addMessage('bot', `Error: ${data.error}. Try again!`);
853
+ showToast(`Error: ${data.error}`);
854
+ } else if (data.menu_items.length > 0) {
855
+ addMessage('bot', `--- Found ${data.menu_items.length} item${data.menu_items.length > 1 ? 's' : ''} ---`);
856
+ displayItemsList(data.menu_items);
857
+ } else {
858
+ addMessage('bot', `No matches for "${searchTerm || dietaryPreference}". Try "paneer" or "chicken curry"!`);
859
+ showToast('No items found!');
860
+ }
861
+ console.log(`Fetched items for ${searchTerm || dietaryPreference}:`, data.menu_items);
862
+ })
863
+ .catch(error => {
864
+ spinner.remove();
865
+ addMessage('bot', `Connection issue: ${error.message}. Retrying...`);
866
+ showToast('Connection issue!');
867
+ setTimeout(() => fetchMenuItems(dietaryPreference, searchTerm), 2000);
868
+ });
869
  }
870
 
871
  function fetchSectorItemDetails(itemName) {
872
+ fetch('/get_sector_item_details', {
873
+ method: 'POST',
874
+ headers: { 'Content-Type': 'application/json' },
875
+ body: JSON.stringify({ item_name: itemName })
876
+ })
877
+ .then(response => response.json())
878
+ .then(data => {
879
+ if (data.error) {
880
+ addMessage('bot', `No "${itemName}" found. Try another!`);
881
+ showToast(`No "${itemName}" found`);
882
+ } else {
883
+ const details = data.item_details;
884
+ if (selectedItems.some(item => item.name === details.name)) {
885
+ addMessage('bot', `"${details.name}" already selected!`);
886
+ showToast(`"${details.name}" already selected`);
887
+ } else {
888
+ selectedItems.push({ ...details, quantity: 1 });
889
+ addMessage('bot', `Added "${details.name}"!`);
890
+ showToast(`Added "${details.name}"`);
891
+ updateSelectionBox();
892
+ }
893
+ }
894
+ })
895
+ .catch(error => {
896
+ addMessage('bot', `Error for "${itemName}". Retrying...`);
897
+ showToast(`Error fetching "${itemName}"`);
898
+ setTimeout(() => fetchSectorItemDetails(itemName), 2000);
899
+ });
900
+ }
901
 
902
+ function toggleDescription(itemContainer, description, itemName) {
903
+ let descElement = itemContainer.querySelector('.item-description');
904
+ if (!descElement) {
905
+ descElement = document.createElement('p');
906
+ descElement.className = 'item-description';
907
+ descElement.textContent = description;
908
+ itemContainer.querySelector('.selected-item-content').appendChild(descElement);
909
+ itemContainer.dataset.hidden = 'false';
910
+ console.log(`Showed description for ${itemName}`);
911
+ showToast(`Showing details for ${itemName}`);
912
+ } else {
913
+ descElement.remove();
914
+ itemContainer.dataset.hidden = 'true';
915
+ console.log(`Hid description for ${itemName}`);
916
+ showToast(`Hid details for ${itemName}`);
917
  }
918
  }
919
 
920
  function displayItemsList(items) {
921
  const chatMessages = document.getElementById('chatMessages');
922
+ if (!chatMessages) {
923
+ console.error('Chat messages container not found!');
924
+ addMessage('bot', 'Display issue. Try again?');
925
+ showToast('Display issue!');
926
+ return;
927
+ }
928
+
929
  const itemsGrid = document.createElement('div');
930
  itemsGrid.className = 'items-grid';
931
 
 
939
  img.className = 'item-image';
940
  itemDiv.appendChild(img);
941
 
942
+ const contentDiv = document.createElement('div');
943
+ contentDiv.className = 'item-content';
944
+
945
  const nameDiv = document.createElement('div');
946
  nameDiv.textContent = item.name;
947
  nameDiv.className = 'item-name';
948
+ contentDiv.appendChild(nameDiv);
949
 
950
  const fields = [
951
  { label: 'Price', value: item.price ? `$${item.price.toFixed(2)}` : 'N/A' },
952
+ { label: 'Veg/Non-Veg', value: item.veg_nonveg },
953
  { label: 'Spice', value: item.spice_levels },
954
+ { label: 'Category', value: item.category },
955
+ { label: 'Ingredients', value: item.ingredients },
956
+ { label: 'Nutrition', value: item.nutritional_info },
957
+ { label: 'Sector', value: item.sector },
958
+ { label: 'Dynamic', value: item.dynamic_dish ? 'Yes' : 'No' }
959
  ];
960
  fields.forEach(field => {
961
  if (field.value) {
962
  const p = document.createElement('p');
963
  p.className = 'item-field';
964
  p.innerHTML = `<strong>${field.label}:</strong> ${field.value}`;
965
+ contentDiv.appendChild(p);
966
  }
967
  });
968
 
969
+ itemDiv.appendChild(contentDiv);
970
+
971
+ const buttonContainer = document.createElement('div');
972
+ buttonContainer.className = 'button-container';
973
+
974
  const addButton = document.createElement('button');
975
  addButton.textContent = 'Add';
976
  addButton.className = 'add-button';
977
  addButton.onclick = () => {
978
+ const selectedItem = {
979
+ name: item.name,
980
+ image_url: item.image_url || '',
981
+ category: item.category || 'Not specified',
982
+ description: item.description || 'No description available',
983
+ source: item.source,
984
+ quantity: 1,
985
+ ingredients: item.ingredients,
986
+ nutritional_info: item.nutritional_info,
987
+ price: item.price,
988
+ sector: item.sector,
989
+ spice_levels: item.spice_levels,
990
+ veg_nonveg: item.veg_nonveg,
991
+ dynamic_dish: item.dynamic_dish
992
+ };
993
+ if (selectedItems.some(existing => existing.name === selectedItem.name)) {
994
+ addMessage('bot', `"${selectedItem.name}" already selected!`);
995
+ showToast(`"${selectedItem.name}" already selected`);
996
  } else {
997
+ selectedItems.push(selectedItem);
998
+ addMessage('bot', `Added "${selectedItem.name}"!`);
999
+ showToast(`Added "${selectedItem.name}"`);
1000
+ updateSelectionBox();
1001
  }
1002
  };
1003
+ buttonContainer.appendChild(addButton);
1004
 
1005
+ itemDiv.appendChild(buttonContainer);
1006
  itemsGrid.appendChild(itemDiv);
1007
  });
1008
 
 
1010
  chatMessages.scrollTop = chatMessages.scrollHeight;
1011
  }
1012
 
1013
+ function displayOptions(options) {
1014
  const chatMessages = document.getElementById('chatMessages');
1015
+ if (!chatMessages) {
1016
+ console.error('Chat messages container not found!');
1017
+ return;
1018
+ }
1019
+ const optionsDiv = document.createElement('div');
1020
+ optionsDiv.className = 'options-container';
1021
+
1022
+ options.forEach(opt => {
1023
+ const button = document.createElement('button');
1024
+ button.textContent = opt.text;
1025
+ button.className = `option-button ${opt.class}`;
1026
+ button.onclick = () => {
1027
+ addMessage('user', opt.text);
1028
+ conversation.push({ role: 'user', message: opt.text });
1029
+ selectionBoxVisible = true;
1030
+ handleResponse(opt.text);
1031
+ updateSelectionBox();
1032
+ showToast(`Selected ${opt.text}`);
1033
+ };
1034
+ optionsDiv.appendChild(button);
1035
+ });
1036
 
1037
+ const backButton = document.createElement('button');
1038
+ backButton.textContent = 'Back';
1039
+ backButton.className = 'option-button';
1040
+ backButton.onclick = () => resetConversation();
1041
+ optionsDiv.appendChild(backButton);
1042
 
1043
+ chatMessages.appendChild(optionsDiv);
1044
+ }
 
1045
 
1046
+ function promptAndSubmit(quantity) {
1047
+ const orderNameInput = document.querySelector('.order-name-input');
1048
+ const customOrderName = orderNameInput ? orderNameInput.value.trim() : '';
1049
+ if (confirm(`Submit ${selectedItems.length} items (Qty: ${quantity})?`)) {
1050
+ submitToSalesforce(customOrderName, quantity);
1051
+ showToast('Submitting order...');
1052
+ } else {
1053
+ addMessage('bot', 'Cancelled. Add more items?');
1054
+ showToast('Order cancelled');
1055
+ }
1056
+ }
1057
 
1058
+ function submitToSalesforce(customOrderName, quantity) {
1059
+ if (selectedItems.length === 0) {
1060
+ addMessage('bot', 'No items selected! Add some dishes! 😊');
1061
+ showToast('No items selected');
1062
+ return;
1063
+ }
1064
 
1065
+ const itemsToSubmit = selectedItems.map(item => ({
1066
+ name: item.name,
1067
+ category: item.category || 'Not specified',
1068
+ description: item.description || 'No description available',
1069
+ image_url: item.image_url || '',
1070
+ quantity: parseInt(quantity) || 1
1071
+ }));
1072
+
1073
+ fetch('/submit_items', {
1074
+ method: 'POST',
1075
+ headers: { 'Content-Type': 'application/json' },
1076
+ body: JSON.stringify({ items: itemsToSubmit, custom_order_name: customOrderName })
1077
+ })
1078
+ .then(response => response.json())
1079
+ .then(data => {
1080
+ if (data.error) {
1081
+ addMessage('bot', `Submission failed: ${data.error}. Try again?`);
1082
+ showToast(`Submission failed: ${data.error}`);
1083
+ } else {
1084
+ addMessage('bot', `Submitted ${data.ingredient_name}! What's next?`);
1085
+ selectedItems = [];
1086
+ updateSelectionBox();
1087
+ showToast('Order submitted!');
1088
+ }
1089
+ })
1090
+ .catch(error => {
1091
+ addMessage('bot', `Submission error: ${error.message}. Retrying...`);
1092
+ showToast('Submission error!');
1093
+ setTimeout(() => submitToSalesforce(customOrderName, quantity), 2000);
1094
+ });
1095
+ }
1096
 
1097
+ function resetConversation() {
1098
+ const userName = conversation.length > 1 ? conversation[1].message : 'Friend';
1099
+ conversation = [
1100
+ { role: 'bot', message: `Hello! I’m Chef Bot, your culinary assistant! What’s your name?` },
1101
+ { role: 'user', message: userName },
1102
+ { role: 'bot', message: `Hi ${userName}! 🍳 Search for a dish or choose a preference below!` }
1103
+ ];
1104
+ selectedItems = [];
1105
+ selectionBoxVisible = true;
1106
+ const chatMessages = document.getElementById('chatMessages');
1107
+ chatMessages.innerHTML = '';
1108
+ conversation.forEach(msg => addMessage(msg.role, msg.message));
1109
+ displayOptions([
1110
+ { text: 'Vegetarian', class: 'green' },
1111
+ { text: 'Non-Vegetarian', class: 'red' },
1112
+ { text: 'Both', class: 'gray' }
1113
+ ]);
1114
+ updateSelectionBox();
1115
+ showToast('Conversation reset');
1116
  }
1117
 
1118
  document.getElementById('userInput').addEventListener('keypress', (e) => {
1119
  if (e.key === 'Enter') sendMessage();
1120
  });
1121
+
1122
+ console.log('Chef Bot script loaded!');
1123
  </script>
1124
  </body>
1125
  </html>