File size: 4,380 Bytes
b430e29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
let currentIndex = 0,
  menu = document.querySelector(".menu-icon"),
  navbar = document.querySelector(".navbar"),
  bag = document.getElementById("bill"),
  listProductBill = [],
  checkTakeAWay = false;

// JavaScript for automatic slide change
const slides = document.querySelectorAll(".swiper-slide");
function showSlide1(index) {
  slides.forEach((slide, i) => {
    slide.style.display = i === index ? "block" : "none";
  });
}
function nextSlide() {
  currentIndex = (currentIndex + 1) % slides.length;
  showSlide1(currentIndex);
}
setInterval(nextSlide, 3000);
showSlide1(currentIndex);

// Menu open and close
menu.onclick = () => {
  menu.classList.toggle("move");
  navbar.classList.toggle("open-menu");
};

// Close menu
window.onscroll = () => {
  menu.classList.remove("move");
  navbar.classList.remove("open-menu");
};

// Open Menu Products
function goToShoppingPage() {
  window.location.href = "Products.html";
}
function goToHomePage() {
  window.location.href = "mainCoffee.html";
}

function MenuToTakeAWay() {
  goToShoppingPage();
  checkTakeAWay = true;
}

function displayBill() {
  if (bag !== null) {
    if (bag.style.width === "0%") {
      bag.style.width = "20%";
    } else {
      bag.style.width = "0%";
    }
  } else {
    console.error("Element with ID 'bill' not found.");
  }
}

// add products with name, images and price to the cart, display cart in the right
// Function to handle click on the heart icon
function handleHeartClick(event) {
  // Navigate up to the parent product-box element
  let productBox = event.target.closest(".product-box");

  if (productBox !== null) {
    // Get specific information from product-box
    let productName = productBox.querySelector("h2").textContent.trim();
    let priceRange = productBox
      .querySelector(".product-info span")
      .textContent.trim();
    let imageUrl = productBox.querySelector("img").src;

    let existingProduct = listProductBill.find(
      (product) => product.name === productName
    );
    if (existingProduct) {
      // If product exists, increment the quantity
      existingProduct.quantity++;
    } else {
      // Create an object with the extracted information
      let productInfo = {
        name: productName,
        price: priceRange,
        image: imageUrl,
        quantity: 1,
      };

      // Push the information to the list
      listProductBill.push(productInfo);
    }
    // Display the list in the console
    console.log(listProductBill);
  } else {
    console.log("Product information not found!");
  }
  renderListProduct();
}
// Attach click event listener to all heart icons with class "bx-shopping-bag"
let heartIcons = document.querySelectorAll(".bx-shopping-bag");
heartIcons.forEach((icon) => {
  icon.addEventListener("click", handleHeartClick);
});

// Delete products in bill
function removeProduct(productName) {
  const shouldDelete = window.confirm(
    `Do you want to remove "${productName}" from the list?`
  );
  if (shouldDelete) {
    const indexToRemove = listProductBill.findIndex(
      (product) => product.name === productName
    );
    if (indexToRemove !== -1) {
      listProductBill.splice(indexToRemove, 1);
      renderListProduct();
    } else {
      alert(`Product not found: ${productName}`);
    }
  }
}
// Total price and ask customer with cash or credit cards
function showHiddenTag() {
  var hiddenTag = document.getElementById("hiddenTag");
  document.getElementById("thankyou").style.width = "20%";
  if (checkTakeAWay === true) {
    hiddenTag.innerHTML = `<h1>Thank you so much!</h1>
    <h3>Your items will be there in a few minutes!</h3>
    <h1>$ ${totalBill}</h1>`;
  } else {
    hiddenTag.innerHTML = `<h1>Wish you a good appetite!</h1>
  <h3>Your items will be there in a few minutes!</h3>
  <h1>$ ${totalBill}</h1>`;
  }
  setTimeout(function () {
    document.getElementById("thankyou").style.width = "0%";
  }, 5000);
  displayBill();
  listProductBill = [];
  renderListProduct();
  checkTakeAWay = false;
}

function CheckBook() {
  let number = document.getElementById("booknumber").value;
  let name = document.getElementById("bookname").value;

  alert(
    `Hi ${name}, We will contact you via this number ${number} as soon as possible!`
  );

  // Reset input values
  document.getElementById("booknumber").value = "";
  document.getElementById("bookname").value = "";
}