// Product Data const products = { vegPickles: [ { id: 1, name: "Avakaya (Mango Pickle)", description: "The king of pickles; raw mango pieces with mustard and chili.", price: 299, originalPrice: 349, image: "http://static.photos/food/640x360/5", weightOptions: ["250g", "500g", "1kg"], spiceLevel: 3, shelfLife: "6 months", ingredients: "Raw mango, mustard seeds, red chili powder, fenugreek, turmeric, salt, oil", rating: 4.8, isBestseller: true }, { id: 2, name: "Bellam Avakaya", description: "Sweet and spicy mango pickle made with Jaggery.", price: 329, originalPrice: 379, image: "http://static.photos/food/640x360/6", weightOptions: ["250g", "500g"], spiceLevel: 2, shelfLife: "6 months", ingredients: "Raw mango, jaggery, mustard seeds, red chili powder, fenugreek, turmeric, salt, oil", rating: 4.7, isSpecial: true }, // Add more veg pickles... ], nonVegPickles: [ { id: 101, name: "Chicken Boneless Pickle", description: "Tender chunks marinated in ginger-garlic and garam masala.", price: 449, originalPrice: 499, image: "http://static.photos/food/640x360/7", weightOptions: ["250g", "500g"], spiceLevel: 3, shelfLife: "3 months", ingredients: "Chicken, ginger, garlic, garam masala, red chili powder, turmeric, salt, oil", rating: 4.9, isBestseller: true }, // Add more non-veg pickles... ], vadiyalu: [ { id: 201, name: "Gummadi Vadiyalu", description: "Ash gourd (pumpkin) chunks mixed with urad dal batter.", price: 199, originalPrice: 249, image: "http://static.photos/food/640x360/8", weightOptions: ["250g", "500g", "1kg"], spiceLevel: 1, shelfLife: "12 months", ingredients: "Ash gourd, urad dal, green chilies, salt", rating: 4.5 }, // Add more vadiyalu... ], masalas: [ { id: 301, name: "Biryani Masala", description: "Hyderabadi-style aromatic blend.", price: 149, originalPrice: 179, image: "http://static.photos/food/640x360/9", weightOptions: ["100g", "250g"], spiceLevel: 2, shelfLife: "12 months", ingredients: "Cinnamon, cardamom, cloves, bay leaves, star anise, mace, nutmeg, pepper", rating: 4.7, isNew: true }, // Add more masalas... ] }; // Cart System let cart = JSON.parse(localStorage.getItem('cart')) || []; let isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'; // DOM Elements const productGrids = { veg: document.querySelector('#veg-pickles .product-grid'), nonVeg: document.querySelector('#nonveg-pickles .product-grid'), vadiyalu: document.querySelector('#vadiyalu .product-grid'), masalas: document.querySelector('#masalas .product-grid') }; // Initialize the app document.addEventListener('DOMContentLoaded', () => { renderProducts(); setupEventListeners(); // Check if user is logged in if (isLoggedIn) { updateUserUI(); } }); // Render all products function renderProducts() { renderProductCategory('veg', products.vegPickles); renderProductCategory('nonVeg', products.nonVegPickles); renderProductCategory('vadiyalu', products.vadiyalu); renderProductCategory('masalas', products.masalas); } // Render products for a specific category function renderProductCategory(category, products) { const grid = productGrids[category]; grid.innerHTML = ''; products.forEach(product => { const productCard = document.createElement('div'); productCard.className = 'product-card'; productCard.innerHTML = ` ${product.name} ${product.isBestseller ? 'Bestseller' : ''} ${product.isNew ? 'New' : ''} ${product.isSpecial ? 'Special' : ''}

${product.name}

${renderRatingStars(product.rating)} ${renderSpiceLevel(product.spiceLevel)}
₹${product.price} ${product.originalPrice ? `₹${product.originalPrice}` : ''}

Shelf Life: ${product.shelfLife}

`; grid.appendChild(productCard); }); } // Render rating stars function renderRatingStars(rating) { let stars = ''; const fullStars = Math.floor(rating); const hasHalfStar = rating % 1 >= 0.5; for (let i = 0; i < 5; i++) { if (i < fullStars) { stars += ''; } else if (i === fullStars && hasHalfStar) { stars += ''; } else { stars += ''; } } return stars; } // Render spice level indicator function renderSpiceLevel(level) { let spice = ''; for (let i = 0; i < level; i++) { spice += '🌶️'; } return spice; } // Setup event listeners function setupEventListeners() { // Add to cart buttons document.querySelectorAll('.btn-add-to-cart').forEach(button => { button.addEventListener('click', (e) => { if (!isLoggedIn) { document.querySelector('custom-login-modal').openModal(); return; } const productId = parseInt(e.target.closest('button').dataset.id); addToCart(productId); showToast('Product added to cart!'); }); }); // Wishlist buttons document.querySelectorAll('.btn-wishlist').forEach(button => { button.addEventListener('click', (e) => { if (!isLoggedIn) { document.querySelector('custom-login-modal').openModal(); return; } const productId = parseInt(e.target.closest('button').dataset.id); toggleWishlist(productId); }); }); // User login event document.addEventListener('userLoggedIn', () => { isLoggedIn = true; localStorage.setItem('isLoggedIn', 'true'); updateUserUI(); }); } // Add product to cart function addToCart(productId) { // Find product in all categories let product = null; for (const category in products) { product = products[category].find(p => p.id === productId); if (product) break; } if (!product) return; // Check if product already in cart const existingItem = cart.find(item => item.id === productId); if (existingItem) { existingItem.quantity += 1; } else { cart.push({ ...product, quantity: 1, selectedWeight: product.weightOptions[0] }); } localStorage.setItem('cart', JSON.stringify(cart)); updateCartCount(); } // Toggle product in wishlist function toggleWishlist(productId) { // In a real app, this would be saved to backend const button = document.querySelector(`.btn-wishlist[data-id="${productId}"]`); const icon = button.querySelector('i'); if (icon.classList.contains('far')) { icon.classList.remove('far'); icon.classList.add('fas'); showToast('Added to wishlist!'); } else { icon.classList.remove('fas'); icon.classList.add('far'); showToast('Removed from wishlist!'); } } // Update cart count in navbar function updateCartCount() { const count = cart.reduce((total, item) => total + item.quantity, 0); const event = new CustomEvent('cartUpdated', { detail: count }); document.dispatchEvent(event); } // Update UI when user logs in function updateUserUI() { const event = new CustomEvent('userStatusChanged', { detail: isLoggedIn }); document.dispatchEvent(event); } // Show toast notification function showToast(message) { const toast = document.getElementById('toast'); toast.textContent = message; toast.classList.remove('hidden'); setTimeout(() => { toast.classList.add('hidden'); }, 3000); }