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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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
{% extends "base.html" %}

{% block title %}Dishes Management - Admin Dashboard{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2>
                    <i class="fas fa-utensils me-2"></i>
                    Dishes Management
                </h2>
                <div class="d-flex gap-2">
                    <a href="/admin" class="btn btn-outline-secondary">
                        <i class="fas fa-arrow-left me-1"></i>Back to Dashboard
                    </a>
                    <button class="btn btn-success" onclick="addNewDish()">
                        <i class="fas fa-plus me-1"></i>Add New Dish
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Filters and Search -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <div class="row align-items-center">
                        <div class="col-md-3">
                            <label class="form-label">Search Dishes:</label>
                            <input type="text" class="form-control" id="searchInput" 
                                   placeholder="Search by name..." onkeyup="filterDishes()">
                        </div>
                        <div class="col-md-2">
                            <label class="form-label">Category:</label>
                            <select class="form-select" id="categoryFilter" onchange="filterDishes()">
                                <option value="">All Categories</option>
                                <option value="starters">Starters</option>
                                <option value="main-course">Main Course</option>
                                <option value="beverages">Beverages</option>
                                <option value="desserts">Desserts</option>
                            </select>
                        </div>
                        <div class="col-md-2">
                            <label class="form-label">Availability:</label>
                            <select class="form-select" id="availabilityFilter" onchange="filterDishes()">
                                <option value="">All</option>
                                <option value="available">Available</option>
                                <option value="unavailable">Unavailable</option>
                            </select>
                        </div>
                        <div class="col-md-2">
                            <label class="form-label">Price Range:</label>
                            <select class="form-select" id="priceFilter" onchange="filterDishes()">
                                <option value="">All Prices</option>
                                <option value="0-100">₹0 - ₹100</option>
                                <option value="100-300">₹100 - ₹300</option>
                                <option value="300+">₹300+</option>
                            </select>
                        </div>
                        <div class="col-md-3 d-flex align-items-end gap-2">
                            <button class="btn btn-outline-secondary flex-fill" onclick="clearFilters()">
                                <i class="fas fa-times me-1"></i>Clear
                            </button>
                            <button class="btn btn-outline-primary flex-fill" onclick="exportDishes()">
                                <i class="fas fa-download me-1"></i>Export
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Dishes Grid -->
    <div class="row" id="dishes-container">
        <!-- Sample Dish 1 -->
        <div class="col-md-4 col-sm-6 mb-4 dish-item" data-category="main-course" data-price="250" data-available="true">
            <div class="card h-100">
                <img src="https://images.unsplash.com/photo-1563379091339-03246963d96c?w=400&h=200&fit=crop" 
                     class="card-img-top" style="height: 200px; object-fit: cover;" alt="Chicken Biryani">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-start mb-2">
                        <h6 class="card-title mb-0">Chicken Biryani</h6>
                        <div class="d-flex gap-1">
                            <span class="badge bg-warning">Main Course</span>
                            <span class="badge bg-success">Available</span>
                        </div>
                    </div>
                    <p class="card-text text-muted small">
                        Aromatic basmati rice cooked with tender chicken and traditional spices
                    </p>
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <strong class="text-success fs-5">₹250</strong>
                        <div class="d-flex gap-1">
                            <i class="fas fa-star text-warning"></i>
                            <span class="small">4.5 (24 reviews)</span>
                        </div>
                    </div>
                    <div class="d-flex gap-2">
                        <button class="btn btn-primary btn-sm flex-fill" onclick="editDish(1)">
                            <i class="fas fa-edit me-1"></i>Edit
                        </button>
                        <button class="btn btn-warning btn-sm" onclick="toggleAvailability(1)">
                            <i class="fas fa-eye-slash me-1"></i>
                        </button>
                        <button class="btn btn-danger btn-sm" onclick="deleteDish(1)">
                            <i class="fas fa-trash me-1"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Sample Dish 2 -->
        <div class="col-md-4 col-sm-6 mb-4 dish-item" data-category="starters" data-price="180" data-available="true">
            <div class="card h-100">
                <img src="https://images.unsplash.com/photo-1599487488170-d11ec9c172f0?w=400&h=200&fit=crop" 
                     class="card-img-top" style="height: 200px; object-fit: cover;" alt="Paneer Tikka">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-start mb-2">
                        <h6 class="card-title mb-0">Paneer Tikka</h6>
                        <div class="d-flex gap-1">
                            <span class="badge bg-primary">Starters</span>
                            <span class="badge bg-success">Available</span>
                        </div>
                    </div>
                    <p class="card-text text-muted small">
                        Marinated cottage cheese cubes grilled to perfection with Indian spices
                    </p>
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <strong class="text-success fs-5">₹180</strong>
                        <div class="d-flex gap-1">
                            <i class="fas fa-star text-warning"></i>
                            <span class="small">4.2 (18 reviews)</span>
                        </div>
                    </div>
                    <div class="d-flex gap-2">
                        <button class="btn btn-primary btn-sm flex-fill" onclick="editDish(2)">
                            <i class="fas fa-edit me-1"></i>Edit
                        </button>
                        <button class="btn btn-warning btn-sm" onclick="toggleAvailability(2)">
                            <i class="fas fa-eye-slash me-1"></i>
                        </button>
                        <button class="btn btn-danger btn-sm" onclick="deleteDish(2)">
                            <i class="fas fa-trash me-1"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Sample Dish 3 -->
        <div class="col-md-4 col-sm-6 mb-4 dish-item" data-category="beverages" data-price="80" data-available="false">
            <div class="card h-100">
                <img src="https://images.unsplash.com/photo-1571091718767-18b5b1457add?w=400&h=200&fit=crop" 
                     class="card-img-top" style="height: 200px; object-fit: cover;" alt="Mango Lassi">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-start mb-2">
                        <h6 class="card-title mb-0">Mango Lassi</h6>
                        <div class="d-flex gap-1">
                            <span class="badge bg-info">Beverages</span>
                            <span class="badge bg-danger">Unavailable</span>
                        </div>
                    </div>
                    <p class="card-text text-muted small">
                        Refreshing yogurt-based drink with fresh mango pulp and a hint of cardamom
                    </p>
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <strong class="text-success fs-5">₹80</strong>
                        <div class="d-flex gap-1">
                            <i class="fas fa-star text-warning"></i>
                            <span class="small">4.7 (35 reviews)</span>
                        </div>
                    </div>
                    <div class="d-flex gap-2">
                        <button class="btn btn-primary btn-sm flex-fill" onclick="editDish(3)">
                            <i class="fas fa-edit me-1"></i>Edit
                        </button>
                        <button class="btn btn-success btn-sm" onclick="toggleAvailability(3)">
                            <i class="fas fa-eye me-1"></i>
                        </button>
                        <button class="btn btn-danger btn-sm" onclick="deleteDish(3)">
                            <i class="fas fa-trash me-1"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Empty State -->
    <div id="no-dishes" class="text-center py-5" style="display: none;">
        <i class="fas fa-search fa-3x text-muted mb-3"></i>
        <p class="text-muted">No dishes match your filters</p>
        <button class="btn btn-primary" onclick="clearFilters()">
            Clear Filters
        </button>
    </div>
</div>

<!-- Add/Edit Dish Modal -->
<div class="modal fade" id="dishModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="dishModalTitle">
                    <i class="fas fa-plus me-2"></i>Add New Dish
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <form id="dishForm">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">Dish Name *</label>
                                <input type="text" class="form-control" id="dishName" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">Category *</label>
                                <select class="form-select" id="dishCategory" required>
                                    <option value="">Select Category</option>
                                    <option value="starters">Starters</option>
                                    <option value="main-course">Main Course</option>
                                    <option value="beverages">Beverages</option>
                                    <option value="desserts">Desserts</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">Price (₹) *</label>
                                <input type="number" class="form-control" id="dishPrice" min="0" step="0.01" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">Cooking Time (minutes)</label>
                                <input type="number" class="form-control" id="cookingTime" min="0">
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">Description</label>
                        <textarea class="form-control" id="dishDescription" rows="3" 
                                  placeholder="Describe the dish..."></textarea>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">Image Upload</label>
                                <input type="file" class="form-control" id="dishImage" accept="image/*">
                                <small class="text-muted">Upload dish image (JPG, PNG)</small>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" id="isAvailable" checked>
                                    <label class="form-check-label" for="isAvailable">
                                        Available for orders
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" id="isSpecial">
                                    <label class="form-check-label" for="isSpecial">
                                        Today's special
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" id="isVegetarian">
                                    <label class="form-check-label" for="isVegetarian">
                                        Vegetarian
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                    Cancel
                </button>
                <button type="button" class="btn btn-success" onclick="saveDish()">
                    <i class="fas fa-save me-2"></i>Save Dish
                </button>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
    let editingDishId = null;
    
    function filterDishes() {
        const searchTerm = document.getElementById('searchInput').value.toLowerCase();
        const categoryFilter = document.getElementById('categoryFilter').value;
        const availabilityFilter = document.getElementById('availabilityFilter').value;
        const priceFilter = document.getElementById('priceFilter').value;
        
        const dishes = document.querySelectorAll('.dish-item');
        let visibleCount = 0;
        
        dishes.forEach(dish => {
            let show = true;
            
            // Search filter
            if (searchTerm && !dish.textContent.toLowerCase().includes(searchTerm)) {
                show = false;
            }
            
            // Category filter
            if (categoryFilter && dish.dataset.category !== categoryFilter) {
                show = false;
            }
            
            // Availability filter
            if (availabilityFilter) {
                const isAvailable = dish.dataset.available === 'true';
                if ((availabilityFilter === 'available' && !isAvailable) ||
                    (availabilityFilter === 'unavailable' && isAvailable)) {
                    show = false;
                }
            }
            
            // Price filter
            if (priceFilter) {
                const price = parseInt(dish.dataset.price);
                if (priceFilter === '0-100' && (price < 0 || price > 100)) show = false;
                if (priceFilter === '100-300' && (price < 100 || price > 300)) show = false;
                if (priceFilter === '300+' && price < 300) show = false;
            }
            
            dish.style.display = show ? 'block' : 'none';
            if (show) visibleCount++;
        });
        
        document.getElementById('no-dishes').style.display = visibleCount === 0 ? 'block' : 'none';
    }
    
    function clearFilters() {
        document.getElementById('searchInput').value = '';
        document.getElementById('categoryFilter').value = '';
        document.getElementById('availabilityFilter').value = '';
        document.getElementById('priceFilter').value = '';
        filterDishes();
    }
    
    function addNewDish() {
        editingDishId = null;
        document.getElementById('dishModalTitle').innerHTML = '<i class="fas fa-plus me-2"></i>Add New Dish';
        document.getElementById('dishForm').reset();
        document.getElementById('isAvailable').checked = true;
        new bootstrap.Modal(document.getElementById('dishModal')).show();
    }
    
    function editDish(dishId) {
        editingDishId = dishId;
        document.getElementById('dishModalTitle').innerHTML = '<i class="fas fa-edit me-2"></i>Edit Dish';
        
        // In production, this would fetch dish data from API
        // For demo, populating with sample data
        document.getElementById('dishName').value = 'Chicken Biryani';
        document.getElementById('dishCategory').value = 'main-course';
        document.getElementById('dishPrice').value = '250';
        document.getElementById('cookingTime').value = '30';
        document.getElementById('dishDescription').value = 'Aromatic basmati rice cooked with tender chicken and traditional spices';
        document.getElementById('isAvailable').checked = true;
        
        new bootstrap.Modal(document.getElementById('dishModal')).show();
    }
    
    function saveDish() {
        const name = document.getElementById('dishName').value;
        const category = document.getElementById('dishCategory').value;
        const price = document.getElementById('dishPrice').value;
        
        if (!name || !category || !price) {
            alert('Please fill in all required fields');
            return;
        }
        
        const action = editingDishId ? 'updated' : 'added';
        alert(`Dish ${action} successfully! (In production, this would save to the database)`);
        
        bootstrap.Modal.getInstance(document.getElementById('dishModal')).hide();
        // In production, refresh the dishes list
    }
    
    function toggleAvailability(dishId) {
        if (confirm('Toggle dish availability?')) {
            alert(`Dish availability toggled! (In production, this would update the database)`);
            // In production, update the UI to reflect the change
        }
    }
    
    function deleteDish(dishId) {
        if (confirm('Are you sure you want to delete this dish? This action cannot be undone.')) {
            alert(`Dish deleted! (In production, this would remove from database)`);
            // In production, remove the dish element from the DOM
        }
    }
    
    function exportDishes() {
        alert('Export dishes feature - would generate CSV/Excel file with all dish data');
    }
    
    // File upload preview
    document.getElementById('dishImage').addEventListener('change', function(e) {
        const file = e.target.files[0];
        if (file) {
            console.log('Image selected:', file.name);
            // In production, show image preview
        }
    });
</script>
{% endblock %}