File size: 9,729 Bytes
971e00f
 
 
 
 
a5d5b7c
971e00f
 
20a362d
 
 
 
 
 
 
809761b
 
 
 
 
7bbe077
 
 
809761b
7bbe077
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809761b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
971e00f
809761b
a5d5b7c
971e00f
 
 
809761b
971e00f
809761b
 
971e00f
 
a5d5b7c
971e00f
 
a5d5b7c
809761b
971e00f
809761b
 
971e00f
 
a5d5b7c
809761b
 
 
 
 
 
 
 
 
971e00f
 
809761b
971e00f
a5d5b7c
971e00f
809761b
 
 
 
 
 
 
 
971e00f
809761b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
971e00f
809761b
971e00f
a5d5b7c
 
809761b
 
 
 
 
 
 
 
a5d5b7c
971e00f
 
 
 
809761b
971e00f
 
 
809761b
 
 
 
971e00f
a5d5b7c
b161656
a5d5b7c
5ee0e99
 
971e00f
0afc76c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
971e00f
 
 
a5d5b7c
7bbe077
 
 
 
 
 
 
 
 
 
 
 
 
809761b
 
a5d5b7c
0afc76c
a5d5b7c
 
971e00f
809761b
093138f
72563f0
093138f
 
809761b
 
093138f
809761b
093138f
 
 
 
 
 
 
 
 
 
809761b
 
 
ad7067d
ff72402
093138f
a3468e8
093138f
 
809761b
a3468e8
093138f
 
 
0afc76c
093138f
 
a3468e8
093138f
 
 
bcd9d8c
 
 
 
 
 
a3468e8
bcd9d8c
093138f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72563f0
f0c7359
a3468e8
 
bcd9d8c
a3468e8
bcd9d8c
a3468e8
bcd9d8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72563f0
 
093138f
971e00f
 
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Food Menu</title>
    <style>
        body {
        font-family: Arial, sans-serif;
        background-color: #fdf4e3; /* Updated background color */
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
    }
        /* Header */
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: #ff6b00;
            padding: 15px;
            color: white;
        }
        .search-bar {
            flex-grow: 1;
            margin: 0 10px;
        }
        .search-bar input {
            width: 70%;
            padding: 8px;
            border-radius: 5px;
            border: none;
        }
        .avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: white;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            position: relative;
        }
        .avatar-menu {
            display: none;
            position: absolute;
            top: 50px;
            right: 0;
            background: white;
            color: black;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            border-radius: 5px;
            width: 150px;
            text-align: left;
        }
        .avatar-menu a {
            display: block;
            padding: 10px;
            text-decoration: none;
            color: black;
        }
        .avatar-menu a:hover {
            background: #f0f0f0;
        }
        .avatar:hover .avatar-menu {
            display: block;
        }
        .nav-links {
            list-style: none;
            display: flex;
            gap: 20px;
            margin: 0;
            padding: 0;
        }
        .nav-links li {
            display: inline;
        }
        .nav-links a {
            text-decoration: none;
            color: #333;
            font-weight: bold;
        }
        .cart-btn {
            background: #28a745;
            color: white;
            border: none;
            padding: 8px 15px;
            cursor: pointer;
            border-radius: 5px;
            font-weight: bold;
        }

        /* Main Container */
        .container {
            max-width: 800px;
            margin: 20px auto;
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        /* Menu Items */
        .menu-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px;
            border-bottom: 1px solid #ddd;
            background: white;
            border-radius: 10px;
            margin-bottom: 15px;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
        }
        .menu-details {
            flex-grow: 1;
            padding-right: 15px;
        }
        .bestseller {
            color: #ff5733;
            font-size: 14px;
            font-weight: bold;
            display: flex;
            align-items: center;
            margin-bottom: 5px;
        }
        .menu-details h3 {
            margin: 5px 0;
            font-size: 18px;
            font-weight: bold;
        }
        .price {
            font-weight: bold;
            font-size: 18px;
        }
        .rating {
            display: flex;
            align-items: center;
            font-size: 14px;
            margin: 5px 0;
        }
        .save-btn {
            background: #f8d7da;
            border: none;
            padding: 5px 10px;
            border-radius: 15px;
            font-size: 12px;
            color: #c82333;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            margin-top: 5px;
        }
        .description {
            font-size: 14px;
            color: #666;
            margin-top: 5px;
        }
        .add-container {
            position: relative;
            text-align: center;
        }
        .menu-img {
            width: 120px;
            height: 120px;
            border-radius: 10px;
            object-fit: cover;
            display: block;
        }
        .add-btn {
            background: #28a745;
            color: white;
            border: none;
            padding: 8px 15px;
            cursor: pointer;
            border-radius: 5px;
            font-weight: bold;
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
        }
        .customizable {
            font-size: 14px;
            color: gray;
            margin-top: 10px;
           /* margin-bottom: 5px; */
        }
       .quantity-control {
        display: flex;
        align-items: center;
        gap: 10px;
        background: #28a745;
        color: white;
        padding: 5px 10px;
        border-radius: 20px;
        font-weight: bold;
    }
    .quantity-control button {
        background: white;
        border: none;
        color: #28a745;
        font-size: 16px;
        font-weight: bold;
        padding: 5px 10px;
        border-radius: 50%;
        cursor: pointer;
    }
    .quantity-control span {
        font-size: 16px;
        font-weight: bold;
    }
    </style>
</head>
<body>

 <div class="header">
        <div class="search-bar">
            <input type="text" id="search" placeholder="Search food items..." onkeyup="searchMenu()">
        </div>
        <div class="avatar">👤
            <div class="avatar-menu">
                <a href="#">Profile</a>
                <a href="#">Rewards</a>
                <a href="#">My Orders</a>
                <a href="#" onclick="logout()">Logout</a>
            </div>
        </div>
    </div>

<!-- Main Content -->
<div class="container">
    <h2 align-item: "center">Menu</h2>
    <div id="menu"></div>
</div>

<script>
    let filteredMenu = [];
    let cart = []; // Array to store added items

    // Fetch menu items from Flask backend
    async function fetchMenu() {
        try {
            const response = await fetch('/get_menu');  // Call the Flask API
            const menuItems = await response.json();

            // Check if the response is valid
            if (!Array.isArray(menuItems)) {
                console.error("Invalid menu data");
                return;
            }

            filteredMenu = menuItems; // Save fetched data to filteredMenu
            displayMenu(filteredMenu); // Display menu items

        } catch (error) {
            console.error("Error fetching menu:", error);
        }
    }

    // Display menu items on the page
    function displayMenu(menuItems) {
        const menuContainer = document.getElementById("menu");
        menuContainer.innerHTML = '';

       menuItems.forEach(item => {
            const menuItem = document.createElement("div");
            menuItem.classList.add("menu-item");
            menuItem.innerHTML = `
                 <div class="menu-details">
                    <h3>${item.Name}</h3>
                    <p class="price">$${item.Price__c}</p>
                    <p class="description">${item.Description__c}</p>
                </div>
                <div class="add-container">
                    <img class="menu-img" src="${item.Image1__c}" alt="${item.Name}">
                    ${cart[item.Name] ? `
                        <div class="quantity-control">
                            <button onclick="decreaseQuantity('${item.Name}')">-</button>
                            <span>${cart[item.Name].quantity}</span>
                            <button onclick="increaseQuantity('${item.Name}')">+</button>
                        </div>`
                    : `<button class="add-btn" onclick='addToCart(${JSON.stringify(item)})'>ADD</button>`}
                    <p class="customizable" style="text-align: center; margin-top: 10px;">Customisable</p>
                </div>
            `;
            menuContainer.appendChild(menuItem);
        });
    }

    // Search for menu items
    function searchMenu() {
        const query = document.getElementById("search").value.toLowerCase();
        const filtered = filteredMenu.filter(item => item.Name.toLowerCase().includes(query));
        displayMenu(filtered);
    }

    // Filter menu items by category
    function filterCategory(category) {
        const filtered = filteredMenu.filter(item => item.Category__c === category);
        displayMenu(filtered);
    }

    // Initialize the menu display when the page loads
    document.addEventListener("DOMContentLoaded", () => {
        fetchMenu(); // Fetch menu data from the backend
    });

  // Function to handle adding an item to the cart
    function addToCart(item.Name, price, image) {
        if (cart[item.Name]) {
            cart[item.Name].quantity += 1;
        } else {
            cart[item.Name] = { ...item, quantity: 1 };
        }
       displayMenu(filteredMenu); // Refresh menu UI to update button
    }

    // Function to increase quantity
    function increaseQuantity(name) {
        cart[name].quantity += 1;
        displayMenu(filteredMenu);
    }

    // Function to decrease quantity
    function decreaseQuantity(name) {
        if (cart[name].quantity > 1) {
            cart[name].quantity -= 1;
        } else {
            delete cart[name]; // Remove item from cart if quantity is 0
        }
        displayMenu(filteredMenu);
    }

</script>
</body>
</html>