lokesh341 commited on
Commit
6507511
·
verified ·
1 Parent(s): 1f41c85

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +395 -89
templates/menu.html CHANGED
@@ -242,16 +242,15 @@
242
  }
243
  .addon-section h6 {
244
  margin-bottom: 10px;
245
- font-size: 1rem;
246
  font-weight: bold;
247
  color: #343a40;
248
  }
249
  .addon-section .form-check {
250
- display: flex;
251
  align-items: center;
252
  margin-left: 10px;
253
  color: #343a40;
254
- justify-content: space-between;
255
  }
256
  .addon-section .form-check-input {
257
  -webkit-appearance: none;
@@ -278,7 +277,7 @@
278
  color: white;
279
  }
280
  .addon-section .form-check-label {
281
- font-size: 0.9rem;
282
  margin-left: 5px;
283
  margin-right: 15px;
284
  cursor: pointer;
@@ -349,8 +348,8 @@
349
  }
350
  .item-details .nutritional-info {
351
  display: grid;
352
- grid-template-columns: 1fr 1fr;
353
- gap: 10px;
354
  background-color: #e9ecef;
355
  padding: 10px;
356
  border-radius: 5px;
@@ -420,29 +419,6 @@
420
  font-size: 12px;
421
  padding: 0 5px;
422
  }
423
- /* Portion and Spice Buttons */
424
- .portion-btn, .spice-btn {
425
- border: 1px solid #ccc;
426
- border-radius: 5px;
427
- padding: 8px 15px;
428
- font-size: 0.9rem;
429
- background-color: #fff;
430
- color: #333;
431
- transition: background-color 0.3s, color 0.3s;
432
- }
433
- .portion-btn.active, .spice-btn.active {
434
- background-color: #ff8c00;
435
- color: #fff;
436
- border-color: #ff8c00;
437
- }
438
- .portion-btn:hover, .spice-btn:hover {
439
- background-color: #f0f0f0;
440
- }
441
- /* Spice Level Indicator in Header */
442
- #spice-level-indicator {
443
- font-size: 1rem;
444
- }
445
- /* Modal Scrolling */
446
  .modal-body {
447
  max-height: 60vh;
448
  overflow-y: auto;
@@ -665,38 +641,15 @@
665
  <div class="modal-dialog modal-dialog-centered">
666
  <div class="modal-content">
667
  <div class="modal-header">
668
- <h5 class="modal-title" id="itemModalLabel">
669
- <span id="modal-name"></span>
670
- <span id="spice-level-indicator" class="ms-2"></span>
671
- </h5>
672
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
673
  </div>
674
  <div class="modal-body">
675
  <img id="modal-img" class="img-fluid rounded mb-3 d-block mx-auto" alt="Item Image" style="max-height: 200px; object-fit: cover;">
 
676
  <p id="modal-price" class="text-muted text-center"></p>
677
  <p id="modal-description" class="text-secondary"></p>
678
 
679
- <!-- Portion Size Selection -->
680
- <div class="mb-3">
681
- <h6>Choose Portion</h6>
682
- <div class="d-flex gap-2">
683
- <button type="button" class="btn portion-btn active" data-portion="Full" data-weight="400g">Full (400g)</button>
684
- <button type="button" class="btn portion-btn" data-portion="Half" data-weight="200g">Half (200g)</button>
685
- </div>
686
- </div>
687
-
688
- <!-- Spice Level Adjustment -->
689
- <div class="mb-3">
690
- <h6>Adjust Spice Level</h6>
691
- <div class="d-flex gap-2 flex-wrap">
692
- <button type="button" class="btn spice-btn" data-spice="Mild">Mild <span class="spice-icon">🌿</span></button>
693
- <button type="button" class="btn spice-btn active" data-spice="Medium">Medium <span class="spice-icon">🥵</span></button>
694
- <button type="button" class="btn spice-btn" data-spice="Hot">Hot <span class="spice-icon">🌶️🌶️</span></button>
695
- <button type="button" class="btn spice-btn" data-spice="Extra Hot">Extra Hot <span class="spice-icon">🌶️🌶️🌶️</span></button>
696
- </div>
697
- </div>
698
-
699
- <!-- Existing Add-ons Section -->
700
  <div id="first-row">
701
  <h6 id="first-row-title" style="display: none;">Customization Options</h6>
702
  <div class="addon-section">
@@ -987,36 +940,6 @@
987
 
988
  document.getElementById('quantityInput').value = 1;
989
 
990
- // Initialize Spice Level Indicator
991
- const spiceLevelIndicator = document.getElementById('spice-level-indicator');
992
- spiceLevelIndicator.innerText = '🥵'; // Default to Medium spice level
993
-
994
- // Handle Portion Buttons
995
- const portionButtons = document.querySelectorAll('.portion-btn');
996
- portionButtons.forEach(btn => {
997
- btn.addEventListener('click', function () {
998
- portionButtons.forEach(b => b.classList.remove('active'));
999
- this.classList.add('active');
1000
- });
1001
- });
1002
-
1003
- // Handle Spice Buttons
1004
- const spiceButtons = document.querySelectorAll('.spice-btn');
1005
- spiceButtons.forEach(btn => {
1006
- btn.addEventListener('click', function () {
1007
- spiceButtons.forEach(b => b.classList.remove('active'));
1008
- this.classList.add('active');
1009
- const spiceLevel = this.getAttribute('data-spice');
1010
- const spiceIcons = {
1011
- 'Mild': '🌿',
1012
- 'Medium': '🥵',
1013
- 'Hot': '🌶️🌶️',
1014
- 'Extra Hot': '🌶️🌶️🌶️'
1015
- };
1016
- spiceLevelIndicator.innerText = spiceIcons[spiceLevel];
1017
- });
1018
- });
1019
-
1020
  const prepStyleOptions = document.getElementById('prep-style-options');
1021
  const typeOptions = document.getElementById('type-options');
1022
  const spiceLevelOptions = document.getElementById('spice-level-options');
@@ -1042,9 +965,11 @@
1042
  addonsList.innerHTML = '';
1043
 
1044
  const dummySections = [
1045
- { name: "Beverages", options: ["Mango Lassi ($3.5)", "Sweet Lassi ($3)"] },
1046
- { name: "Desserts", options: ["Gulab Jamun ($4)", "Rasmalai ($4.5)"] },
1047
- { name: "ExtraSides", options: ["Naan ($2.5)", "Rice ($3)"] }
 
 
1048
  ];
1049
 
1050
  dummySections.forEach(addon => {
@@ -1217,7 +1142,7 @@
1217
 
1218
  function handleAddonClick(checkbox) {
1219
  const groupName = checkbox.getAttribute('data-group');
1220
- const isMultiSelectGroup = ["Extra Toppings", "Choose Raita/Sides", "Select Dip/Sauce", "Extra Add-ons", "Make it a Combo", "Beverages", "Desserts", "ExtraSides"].includes(groupName);
1221
 
1222
  if (groupName.toLowerCase() === "spice level") {
1223
  const allSpiceLevelCheckboxes = document.querySelectorAll('.spice-level-option');
@@ -1271,4 +1196,385 @@
1271
  document.getElementById('searchBar').addEventListener('keyup', debounce(filterMenu, 300));
1272
 
1273
  function addToCartFromModal() {
1274
- const itemName = document.getElementById('modal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
  .addon-section h6 {
244
  margin-bottom: 10px;
245
+ font-size: 1.1rem;
246
  font-weight: bold;
247
  color: #343a40;
248
  }
249
  .addon-section .form-check {
250
+ display: inline-flex;
251
  align-items: center;
252
  margin-left: 10px;
253
  color: #343a40;
 
254
  }
255
  .addon-section .form-check-input {
256
  -webkit-appearance: none;
 
277
  color: white;
278
  }
279
  .addon-section .form-check-label {
280
+ font-size: 16px;
281
  margin-left: 5px;
282
  margin-right: 15px;
283
  cursor: pointer;
 
348
  }
349
  .item-details .nutritional-info {
350
  display: grid;
351
+ grid-template-columns: 1fr 1fr; /* Two equal columns */
352
+ gap: 10px; /* Space between columns */
353
  background-color: #e9ecef;
354
  padding: 10px;
355
  border-radius: 5px;
 
419
  font-size: 12px;
420
  padding: 0 5px;
421
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
  .modal-body {
423
  max-height: 60vh;
424
  overflow-y: auto;
 
641
  <div class="modal-dialog modal-dialog-centered">
642
  <div class="modal-content">
643
  <div class="modal-header">
644
+ <h5 class="modal-title" id="itemModalLabel">Item Details</h5>
 
 
 
645
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
646
  </div>
647
  <div class="modal-body">
648
  <img id="modal-img" class="img-fluid rounded mb-3 d-block mx-auto" alt="Item Image" style="max-height: 200px; object-fit: cover;">
649
+ <h5 id="modal-name" class="fw-bold text-center"></h5>
650
  <p id="modal-price" class="text-muted text-center"></p>
651
  <p id="modal-description" class="text-secondary"></p>
652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
653
  <div id="first-row">
654
  <h6 id="first-row-title" style="display: none;">Customization Options</h6>
655
  <div class="addon-section">
 
940
 
941
  document.getElementById('quantityInput').value = 1;
942
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
943
  const prepStyleOptions = document.getElementById('prep-style-options');
944
  const typeOptions = document.getElementById('type-options');
945
  const spiceLevelOptions = document.getElementById('spice-level-options');
 
965
  addonsList.innerHTML = '';
966
 
967
  const dummySections = [
968
+ { name: "Beverages", options: ["Sprite ($3)", "Thums Up ($3)", "Virgin Mojito ($3)", "Lemonade ($3)", "Blue Lagoon Mocktail ($3)"] },
969
+ { name: "Sauces", options: ["Mint Chutney", "Tomato Sauce"] },
970
+ { name: "Extra Toppings", options: ["Cheese ($2)", "Olives ($1)", "Jalapenos ($1)", "Mushrooms ($2)", "Peppers ($1)"] },
971
+ { name: "Sides", options: ["Fries ($3)", "Salad ($2)", "Garlic Bread ($3)", "Onion Rings ($2)", "Coleslaw ($2)"] },
972
+ { name: "Desserts", options: ["Ice Cream ($3)", "Brownie ($3)", "Cheesecake ($4)", "Gulab Jamun ($3)", "Rasmalai ($4)"] }
973
  ];
974
 
975
  dummySections.forEach(addon => {
 
1142
 
1143
  function handleAddonClick(checkbox) {
1144
  const groupName = checkbox.getAttribute('data-group');
1145
+ const isMultiSelectGroup = ["Extra Toppings", "Choose Raita/Sides", "Select Dip/Sauce", "Extra Add-ons", "Make it a Combo", "Beverages", "Sauces"].includes(groupName);
1146
 
1147
  if (groupName.toLowerCase() === "spice level") {
1148
  const allSpiceLevelCheckboxes = document.querySelectorAll('.spice-level-option');
 
1196
  document.getElementById('searchBar').addEventListener('keyup', debounce(filterMenu, 300));
1197
 
1198
  function addToCartFromModal() {
1199
+ const itemName = document.getElementById('modal-name').innerText;
1200
+ let itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
1201
+
1202
+ if (isNaN(itemPrice)) {
1203
+ alert('Invalid price for the item. Please check the item details.');
1204
+ return;
1205
+ }
1206
+
1207
+ const itemImage = document.getElementById('modal-img').src;
1208
+ const modalSectionEl = document.getElementById('modal-section');
1209
+ const section = modalSectionEl.getAttribute('data-section');
1210
+ const selectedCategory = modalSectionEl.getAttribute('data-category');
1211
+ if (!itemName || !itemPrice || !section || !itemImage) {
1212
+ console.error('Missing data for cart item:', { itemName, itemPrice, section, itemImage});
1213
+ return;
1214
+ }
1215
+
1216
+ let selectedAddOns = [];
1217
+
1218
+ const addonsListOptions = document.querySelectorAll('#addons-list .addon-option');
1219
+ addonsListOptions.forEach(option => {
1220
+ if (option.checked) {
1221
+ selectedAddOns.push({
1222
+ name: option.getAttribute('data-name') || 'Default Name',
1223
+ price: parseFloat(option.getAttribute('data-price') || 0)
1224
+ });
1225
+ }
1226
+ });
1227
+
1228
+ if (section.toLowerCase() === 'starters') {
1229
+ const prepStyleOptions = Array.from(
1230
+ document.querySelectorAll('#prep-style-options input[type="checkbox"]:checked')
1231
+ ).map(option => ({
1232
+ name: option.getAttribute('data-name') || 'Default Prep Style',
1233
+ price: 0
1234
+ }));
1235
+ const typeOptions = Array.from(
1236
+ document.querySelectorAll('#type-options input[type="checkbox"]:checked')
1237
+ ).map(option => ({
1238
+ name: option.getAttribute('data-name') || 'Default Type',
1239
+ price: 0
1240
+ }));
1241
+ const spiceLevelOption = document.querySelector('#spice-level-options input[type="checkbox"].spice-level-option:checked');
1242
+ const spiceLevelOptions = spiceLevelOption ? [{
1243
+ name: spiceLevelOption.getAttribute('data-name') || 'Default Spice Level',
1244
+ price: 0
1245
+ }] : [];
1246
+ selectedAddOns = [...selectedAddOns, ...prepStyleOptions, ...typeOptions, ...spiceLevelOptions];
1247
+ }
1248
+
1249
+ const quantity = parseInt(document.getElementById('quantityInput').value) || 1;
1250
+ const instructions = document.getElementById('modal-instructions').value;
1251
+
1252
+ const cartPayload = {
1253
+ itemName: itemName,
1254
+ itemPrice: itemPrice,
1255
+ itemImage: itemImage,
1256
+ section: section,
1257
+ category: selectedCategory,
1258
+ addons: selectedAddOns,
1259
+ instructions: instructions,
1260
+ quantity: quantity
1261
+ };
1262
+
1263
+ fetch('/cart/add', {
1264
+ method: 'POST',
1265
+ headers: {
1266
+ 'Content-Type': 'application/json',
1267
+ },
1268
+ body: JSON.stringify(cartPayload)
1269
+ })
1270
+ .then(response => {
1271
+ if (!response.ok) {
1272
+ throw new Error(`HTTP error! Status: ${response.status}`);
1273
+ }
1274
+ return response.json();
1275
+ })
1276
+ .then(data => {
1277
+ if (data.success) {
1278
+ alert('Item added to cart successfully!');
1279
+ updateCartUI(data.cart);
1280
+ const modal = document.getElementById('itemModal');
1281
+ const modalInstance = bootstrap.Modal.getInstance(modal);
1282
+ modalInstance.hide();
1283
+ } else {
1284
+ console.error('Failed to add item to cart:', data.error);
1285
+ alert(data.error || 'Failed to add item to cart.');
1286
+ }
1287
+ })
1288
+ .catch(err => {
1289
+ console.error('Error adding item to cart:', err);
1290
+ alert('An error occurred while adding the item to the cart: ' + err.message);
1291
+ const cart = addToCartLocalStorage(cartPayload);
1292
+ updateCartUI(cart);
1293
+ const modal = document.getElementById('itemModal');
1294
+ const modalInstance = bootstrap.Modal.getInstance(modal);
1295
+ modalInstance.hide();
1296
+ });
1297
+ }
1298
+
1299
+ function handleSoftDrinkAdd(button) {
1300
+ const buttonContainer = button.closest('.button-container');
1301
+ const addButton = buttonContainer.querySelector('.add-to-cart-btn');
1302
+ const quantitySelector = buttonContainer.querySelector('.quantity-selector');
1303
+ const quantityDisplay = quantitySelector.querySelector('.quantity-display');
1304
+
1305
+ addButton.style.display = 'none';
1306
+ quantitySelector.style.display = 'flex';
1307
+
1308
+ const itemName = buttonContainer.getAttribute('data-item-name');
1309
+ const itemPrice = parseFloat(buttonContainer.getAttribute('data-item-price'));
1310
+ const itemImage = buttonContainer.getAttribute('data-item-image');
1311
+ const section = buttonContainer.getAttribute('data-item-section');
1312
+ const category = buttonContainer.getAttribute('data-item-category');
1313
+
1314
+ const cartPayload = {
1315
+ itemName: itemName,
1316
+ itemPrice: itemPrice,
1317
+ itemImage: itemImage,
1318
+ section: section,
1319
+ category: category,
1320
+ addons: [],
1321
+ instructions: '',
1322
+ quantity: 1
1323
+ };
1324
+
1325
+ fetch('/cart/add', {
1326
+ method: 'POST',
1327
+ headers: {
1328
+ 'Content-Type': 'application/json',
1329
+ },
1330
+ body: JSON.stringify(cartPayload)
1331
+ })
1332
+ .then(response => {
1333
+ if (!response.ok) {
1334
+ throw new Error(`HTTP error! Status: ${response.status}`);
1335
+ }
1336
+ return response.json();
1337
+ })
1338
+ .then(data => {
1339
+ if (data.success) {
1340
+ alert('Item added to cart successfully!');
1341
+ updateCartUI(data.cart);
1342
+ quantityDisplay.innerText = 1;
1343
+ } else {
1344
+ console.error('Failed to add item to cart:', data.error);
1345
+ alert(data.error || 'Failed to add item to cart.');
1346
+ addButton.style.display = 'block';
1347
+ quantitySelector.style.display = 'none';
1348
+ }
1349
+ })
1350
+ .catch(err => {
1351
+ console.error('Error adding item to cart:', err);
1352
+ alert('An error occurred while adding the item to the cart: ' + err.message);
1353
+ const cart = addToCartLocalStorage(cartPayload);
1354
+ updateCartUI(cart);
1355
+ quantityDisplay.innerText = 1;
1356
+ });
1357
+ }
1358
+
1359
+ function increaseQuantity(button) {
1360
+ const buttonContainer = button.closest('.button-container');
1361
+ const quantityDisplay = buttonContainer.querySelector('.quantity-display');
1362
+ const quantityToAddSelect = buttonContainer.querySelector('.quantity-to-add');
1363
+ const quantityToAdd = parseInt(quantityToAddSelect.value);
1364
+ let currentQuantity = parseInt(quantityDisplay.innerText);
1365
+
1366
+ currentQuantity += quantityToAdd;
1367
+ quantityDisplay.innerText = currentQuantity;
1368
+
1369
+ const itemName = buttonContainer.getAttribute('data-item-name');
1370
+ const itemPrice = parseFloat(buttonContainer.getAttribute('data-item-price'));
1371
+ const itemImage = buttonContainer.getAttribute('data-item-image');
1372
+ const section = buttonContainer.getAttribute('data-item-section');
1373
+ const category = buttonContainer.getAttribute('data-item-category');
1374
+
1375
+ const cartPayload = {
1376
+ itemName: itemName,
1377
+ itemPrice: itemPrice,
1378
+ itemImage: itemImage,
1379
+ section: section,
1380
+ category: category,
1381
+ addons: [],
1382
+ instructions: '',
1383
+ quantity: quantityToAdd
1384
+ };
1385
+
1386
+ button.disabled = true;
1387
+
1388
+ fetch('/cart/add', {
1389
+ method: 'POST',
1390
+ headers: {
1391
+ 'Content-Type': 'application/json',
1392
+ },
1393
+ body: JSON.stringify(cartPayload)
1394
+ })
1395
+ .then(response => {
1396
+ if (!response.ok) {
1397
+ throw new Error(`HTTP error! Status: ${response.status}`);
1398
+ }
1399
+ return response.json();
1400
+ })
1401
+ .then(data => {
1402
+ if (data.success) {
1403
+ alert(`Added ${quantityToAdd} item(s) to cart successfully!`);
1404
+ updateCartUI(data.cart);
1405
+ } else {
1406
+ console.error('Failed to add item to cart:', data.error);
1407
+ alert(data.error || 'Failed to add item to cart.');
1408
+ currentQuantity -= quantityToAdd;
1409
+ quantityDisplay.innerText = currentQuantity;
1410
+ }
1411
+ })
1412
+ .catch(err => {
1413
+ console.error('Error adding item to cart:', err);
1414
+ alert('An error occurred while adding the item to the cart: ' + err.message);
1415
+ const cart = addToCartLocalStorage(cartPayload);
1416
+ updateCartUI(cart);
1417
+ })
1418
+ .finally(() => {
1419
+ button.disabled = false;
1420
+ });
1421
+ }
1422
+
1423
+ function decreaseQuantity(button) {
1424
+ const buttonContainer = button.closest('.button-container');
1425
+ const quantityDisplay = buttonContainer.querySelector('.quantity-display');
1426
+ const quantityToRemoveSelect = buttonContainer.querySelector('.quantity-to-remove');
1427
+ const quantityToRemove = parseInt(quantityToRemoveSelect.value);
1428
+ const addButton = buttonContainer.querySelector('.add-to-cart-btn');
1429
+ const quantitySelector = buttonContainer.querySelector('.quantity-selector');
1430
+ let currentQuantity = parseInt(quantityDisplay.innerText);
1431
+
1432
+ if (currentQuantity <= quantityToRemove) {
1433
+ const itemName = buttonContainer.getAttribute('data-item-name');
1434
+ fetch(`/cart/remove?item_name=${encodeURIComponent(itemName)}&quantity=${currentQuantity}&instructions=&addons=[]`, {
1435
+ method: 'POST',
1436
+ headers: {
1437
+ 'Content-Type': 'application/json',
1438
+ }
1439
+ })
1440
+ .then(response => {
1441
+ if (!response.ok) {
1442
+ throw new Error(`HTTP error! Status: ${response.status}`);
1443
+ }
1444
+ return response.json();
1445
+ })
1446
+ .then(data => {
1447
+ if (data.success) {
1448
+ updateCartUI(data.cart);
1449
+ addButton.style.display = 'block';
1450
+ quantitySelector.style.display = 'none';
1451
+ quantityDisplay.innerText = 0;
1452
+ } else {
1453
+ console.error('Failed to remove item from cart:', data.error);
1454
+ alert(data.error || 'Failed to remove item from cart.');
1455
+ }
1456
+ })
1457
+ .catch(err => {
1458
+ console.error('Error removing item from cart:', err);
1459
+ alert('An error occurred while removing the item from the cart: ' + err.message);
1460
+ const cart = removeFromCartLocalStorage(itemName, currentQuantity, '', []);
1461
+ updateCartUI(cart);
1462
+ addButton.style.display = 'block';
1463
+ quantitySelector.style.display = 'none';
1464
+ quantityDisplay.innerText = 0;
1465
+ });
1466
+ } else {
1467
+ currentQuantity -= quantityToRemove;
1468
+ quantityDisplay.innerText = currentQuantity;
1469
+
1470
+ const itemName = buttonContainer.getAttribute('data-item-name');
1471
+ fetch(`/cart/remove?item_name=${encodeURIComponent(itemName)}&quantity=${quantityToRemove}&instructions=&addons=[]`, {
1472
+ method: 'POST',
1473
+ headers: {
1474
+ 'Content-Type': 'application/json',
1475
+ }
1476
+ })
1477
+ .then(response => {
1478
+ if (!response.ok) {
1479
+ throw new Error(`HTTP error! Status: ${response.status}`);
1480
+ }
1481
+ return response.json();
1482
+ })
1483
+ .then(data => {
1484
+ if (data.success) {
1485
+ alert(`Removed ${quantityToRemove} item(s) from cart successfully!`);
1486
+ updateCartUI(data.cart);
1487
+ } else {
1488
+ console.error('Failed to remove item from cart:', data.error);
1489
+ alert(data.error || 'Failed to remove item from cart.');
1490
+ currentQuantity += quantityToRemove;
1491
+ quantityDisplay.innerText = currentQuantity;
1492
+ }
1493
+ })
1494
+ .catch(err => {
1495
+ console.error('Error removing item from cart:', err);
1496
+ alert('An error occurred while removing the item from the cart: ' + err.message);
1497
+ const cart = removeFromCartLocalStorage(itemName, quantityToRemove, '', []);
1498
+ updateCartUI(cart);
1499
+ });
1500
+ }
1501
+ }
1502
+
1503
+ function updateCartUI(cart) {
1504
+ if (!Array.isArray(cart)) {
1505
+ console.error('Invalid cart data:', cart);
1506
+ return;
1507
+ }
1508
+ const cartIcon = document.getElementById('cart-icon');
1509
+ if (cartIcon) {
1510
+ cartIcon.innerText = cart.length;
1511
+ }
1512
+
1513
+ const buttonContainers = document.querySelectorAll('.button-container');
1514
+ buttonContainers.forEach(container => {
1515
+ const itemName = container.getAttribute('data-item-name');
1516
+ const quantityDisplay = container.querySelector('.quantity-display');
1517
+ const addButton = container.querySelector('.add-to-cart-btn');
1518
+ const quantitySelector = container.querySelector('.quantity-selector');
1519
+
1520
+ const cartItem = cart.find(item =>
1521
+ item.itemName === itemName &&
1522
+ item.instructions === '' &&
1523
+ JSON.stringify(item.addons) === JSON.stringify([])
1524
+ );
1525
+ if (cartItem && cartItem.quantity > 0) {
1526
+ quantityDisplay.innerText = cartItem.quantity;
1527
+ addButton.style.display = 'none';
1528
+ quantitySelector.style.display = 'flex';
1529
+ } else {
1530
+ quantityDisplay.innerText = 0;
1531
+ addButton.style.display = 'block';
1532
+ quantitySelector.style.display = 'none';
1533
+ }
1534
+ });
1535
+ }
1536
+
1537
+ document.addEventListener('DOMContentLoaded', function () {
1538
+ const decreaseBtn = document.getElementById('decreaseQuantity');
1539
+ const increaseBtn = document.getElementById('increaseQuantity');
1540
+ const quantityInput = document.getElementById('quantityInput');
1541
+
1542
+ decreaseBtn.addEventListener('click', function () {
1543
+ let currentQuantity = parseInt(quantityInput.value);
1544
+ if (currentQuantity > 1) {
1545
+ currentQuantity--;
1546
+ quantityInput.value = currentQuantity;
1547
+ }
1548
+ });
1549
+
1550
+ increaseBtn.addEventListener('click', function () {
1551
+ let currentQuantity = parseInt(quantityInput.value);
1552
+ currentQuantity++;
1553
+ quantityInput.value = currentQuantity;
1554
+ });
1555
+
1556
+ fetch('/cart/get')
1557
+ .then(response => {
1558
+ if (!response.ok) {
1559
+ throw new Error(`HTTP error! Status: ${response.status}`);
1560
+ }
1561
+ return response.json();
1562
+ })
1563
+ .then(data => {
1564
+ if (data.success) {
1565
+ updateCartUI(data.cart);
1566
+ } else {
1567
+ console.error('Failed to fetch cart:', data.error);
1568
+ const cart = getCartLocalStorage();
1569
+ updateCartUI(cart);
1570
+ }
1571
+ })
1572
+ .catch(err => {
1573
+ console.error('Error fetching cart:', err);
1574
+ const cart = getCartLocalStorage();
1575
+ updateCartUI(cart);
1576
+ });
1577
+ });
1578
+ </script>
1579
+ </body>
1580
+ </html>