import React, { useState, useEffect } from 'react'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; import { Label } from '@/components/ui/label'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; const indianFoods = [ // Existing dishes { name: 'Rice (Cooked)', calories: 130, unit: '100g', protein: 2.7, carbs: 28, fat: 0.3, category: 'Staples' }, { name: 'Chapati', calories: 104, unit: '1 piece', protein: 3, carbs: 20, fat: 1.5, category: 'Staples' }, { name: 'Dal (Cooked)', calories: 116, unit: '100g', protein: 7, carbs: 20, fat: 1, category: 'Staples' }, { name: 'Paneer', calories: 265, unit: '100g', protein: 18.3, carbs: 3.4, fat: 20.8, category: 'Dairy' }, { name: 'Chicken Curry', calories: 243, unit: '100g', protein: 15, carbs: 6, fat: 18, category: 'Meat Dishes' }, { name: 'Palak Paneer', calories: 180, unit: '100g', protein: 11, carbs: 6, fat: 14, category: 'Vegetarian Dishes' }, { name: 'Aloo Gobi', calories: 98, unit: '100g', protein: 3, carbs: 14, fat: 4, category: 'Vegetarian Dishes' }, { name: 'Samosa', calories: 262, unit: '1 piece', protein: 4, carbs: 24, fat: 17, category: 'Snacks' }, { name: 'Dosa', calories: 133, unit: '1 piece', protein: 2, carbs: 20, fat: 5, category: 'Breakfast' }, { name: 'Idli', calories: 39, unit: '1 piece', protein: 2, carbs: 8, fat: 0.1, category: 'Breakfast' }, // Vegetables (Uncooked) { name: 'Tomato (Raw)', calories: 18, unit: '100g', protein: 0.9, carbs: 3.9, fat: 0.2, category: 'Vegetables (Raw)' }, { name: 'Onion (Raw)', calories: 40, unit: '100g', protein: 1.1, carbs: 9.3, fat: 0.1, category: 'Vegetables (Raw)' }, { name: 'Cucumber (Raw)', calories: 15, unit: '100g', protein: 0.7, carbs: 3.6, fat: 0.1, category: 'Vegetables (Raw)' }, { name: 'Spinach (Raw)', calories: 23, unit: '100g', protein: 2.9, carbs: 3.6, fat: 0.4, category: 'Vegetables (Raw)' }, { name: 'Carrot (Raw)', calories: 41, unit: '100g', protein: 0.9, carbs: 9.6, fat: 0.2, category: 'Vegetables (Raw)' }, { name: 'Cauliflower (Raw)', calories: 25, unit: '100g', protein: 1.9, carbs: 5, fat: 0.3, category: 'Vegetables (Raw)' }, { name: 'Capsicum (Raw)', calories: 20, unit: '100g', protein: 0.9, carbs: 4.6, fat: 0.2, category: 'Vegetables (Raw)' }, { name: 'Bitter Gourd (Raw)', calories: 17, unit: '100g', protein: 1, carbs: 3.7, fat: 0.2, category: 'Vegetables (Raw)' }, { name: 'Bottle Gourd (Raw)', calories: 14, unit: '100g', protein: 0.6, carbs: 3.2, fat: 0.1, category: 'Vegetables (Raw)' }, { name: 'Okra (Raw)', calories: 33, unit: '100g', protein: 1.9, carbs: 7.5, fat: 0.2, category: 'Vegetables (Raw)' }, // Vegetables (Cooked) { name: 'Spinach (Cooked)', calories: 23, unit: '100g', protein: 2.9, carbs: 3.8, fat: 0.4, category: 'Vegetables (Cooked)' }, { name: 'Cauliflower (Cooked)', calories: 30, unit: '100g', protein: 1.9, carbs: 5.3, fat: 0.3, category: 'Vegetables (Cooked)' }, { name: 'Carrot (Cooked)', calories: 35, unit: '100g', protein: 0.8, carbs: 8.2, fat: 0.2, category: 'Vegetables (Cooked)' }, { name: 'Cabbage (Cooked)', calories: 24, unit: '100g', protein: 1.3, carbs: 5.5, fat: 0.1, category: 'Vegetables (Cooked)' }, { name: 'Green Peas (Cooked)', calories: 84, unit: '100g', protein: 5.4, carbs: 15.6, fat: 0.4, category: 'Vegetables (Cooked)' }, { name: 'Brinjal (Cooked)', calories: 35, unit: '100g', protein: 0.8, carbs: 8.7, fat: 0.2, category: 'Vegetables (Cooked)' }, { name: 'Okra (Cooked)', calories: 30, unit: '100g', protein: 2, carbs: 7, fat: 0.1, category: 'Vegetables (Cooked)' }, { name: 'Potato (Boiled)', calories: 87, unit: '100g', protein: 1.9, carbs: 20.1, fat: 0.1, category: 'Vegetables (Cooked)' }, { name: 'Bitter Gourd (Cooked)', calories: 21, unit: '100g', protein: 1, carbs: 4.3, fat: 0.2, category: 'Vegetables (Cooked)' }, { name: 'Bottle Gourd (Cooked)', calories: 14, unit: '100g', protein: 0.6, carbs: 3.2, fat: 0.1, category: 'Vegetables (Cooked)' }, // Fruits (Uncooked) { name: 'Apple', calories: 52, unit: '100g', protein: 0.3, carbs: 13.8, fat: 0.2, category: 'Fruits' }, { name: 'Banana', calories: 89, unit: '100g', protein: 1.1, carbs: 22.8, fat: 0.3, category: 'Fruits' }, { name: 'Orange', calories: 47, unit: '100g', protein: 0.9, carbs: 11.8, fat: 0.1, category: 'Fruits' }, { name: 'Mango', calories: 60, unit: '100g', protein: 0.8, carbs: 15, fat: 0.4, category: 'Fruits' }, { name: 'Papaya', calories: 43, unit: '100g', protein: 0.5, carbs: 10.8, fat: 0.3, category: 'Fruits' }, { name: 'Pomegranate', calories: 83, unit: '100g', protein: 1.7, carbs: 18.7, fat: 1.2, category: 'Fruits' }, { name: 'Guava', calories: 68, unit: '100g', protein: 2.6, carbs: 14.3, fat: 1, category: 'Fruits' }, { name: 'Watermelon', calories: 30, unit: '100g', protein: 0.6, carbs: 7.6, fat: 0.2, category: 'Fruits' }, { name: 'Pineapple', calories: 50, unit: '100g', protein: 0.5, carbs: 13.1, fat: 0.1, category: 'Fruits' }, { name: 'Strawberry', calories: 32, unit: '100g', protein: 0.7, carbs: 7.7, fat: 0.3, category: 'Fruits' }, ]; const IndianCalorieCalculator = () => { const [searchTerm, setSearchTerm] = useState(''); const [quantity, setQuantity] = useState(1); const [selectedFoods, setSelectedFoods] = useState([]); const [suggestions, setSuggestions] = useState([]); const [totalNutrition, setTotalNutrition] = useState({ calories: 0, protein: 0, carbs: 0, fat: 0 }); const [selectedCategory, setSelectedCategory] = useState('All'); const categories = ['All', ...new Set(indianFoods.map(food => food.category))]; useEffect(() => { const filteredSuggestions = indianFoods.filter(food => (selectedCategory === 'All' || food.category === selectedCategory) && food.name.toLowerCase().includes(searchTerm.toLowerCase()) ); setSuggestions(filteredSuggestions); }, [searchTerm, selectedCategory]); useEffect(() => { const newTotalNutrition = selectedFoods.reduce((sum, food) => ({ calories: sum.calories + food.calories * food.quantity, protein: sum.protein + food.protein * food.quantity, carbs: sum.carbs + food.carbs * food.quantity, fat: sum.fat + food.fat * food.quantity }), { calories: 0, protein: 0, carbs: 0, fat: 0 }); setTotalNutrition(newTotalNutrition); }, [selectedFoods]); const handleAddFood = (food) => { setSelectedFoods([...selectedFoods, { ...food, quantity }]); setSearchTerm(''); setQuantity(1); }; const handleRemoveFood = (index) => { const newSelectedFoods = [...selectedFoods]; newSelectedFoods.splice(index, 1); setSelectedFoods(newSelectedFoods); }; return ( Comprehensive Indian Food Calorie Calculator
setSearchTerm(e.target.value)} />
setQuantity(parseFloat(e.target.value) || 1)} min="0.1" step="0.1" />
{suggestions.length > 0 && (
    {suggestions.map((food, index) => (
  • handleAddFood(food)} > {food.name} ({food.calories} cal per {food.unit})
  • ))}
)}

Selected Foods:

Food Item Quantity Calories Protein (g) Carbs (g) Fat (g) Action {selectedFoods.map((food, index) => ( {food.name} {food.quantity} {food.unit} {(food.calories * food.quantity).toFixed(1)} {(food.protein * food.quantity).toFixed(1)} {(food.carbs * food.quantity).toFixed(1)} {(food.fat * food.quantity).toFixed(1)} ))}

Total Nutrition:

Calories: {totalN

Indian Food Calorie Calculator

    const indianFoods = [ { name: 'Rice (Cooked)', calories: 130, unit: '100g', protein: 2.7, carbs: 28, fat: 0.3 }, { name: 'Chapati', calories: 104, unit: '1 piece', protein: 3, carbs: 20, fat: 1.5 }, { name: 'Dal (Cooked)', calories: 116, unit: '100g', protein: 7, carbs: 20, fat: 1 }, { name: 'Paneer', calories: 265, unit: '100g', protein: 18.3, carbs: 3.4, fat: 20.8 }, { name: 'Chicken Curry', calories: 243, unit: '100g', protein: 15, carbs: 6, fat: 18 }, // Add more foods here... ]; let selectedFoods = []; function addFood() { const searchTerm = document.getElementById('food-search').value.toLowerCase(); const quantity = parseFloat(document.getElementById('quantity').value) || 1; const food = indianFoods.find(f => f.name.toLowerCase().includes(searchTerm)); if (food) { selectedFoods.push({ ...food, quantity }); updateSelectedFoodsList(); updateTotalNutrition(); } else { alert('Food not found. Please try again.'); } } function updateSelectedFoodsList() { const list = document.getElementById('selected-foods'); list.innerHTML = ''; selectedFoods.forEach((food, index) => { const li = document.createElement('li'); li.textContent = `${food.name} (${food.quantity} ${food.unit}): ${(food.calories * food.quantity).toFixed(1)} cal`; const removeBtn = document.createElement('button'); removeBtn.textContent = 'Remove'; removeBtn.onclick = () => removeFood(index); li.appendChild(removeBtn); list.appendChild(li); }); } function removeFood(index) { selectedFoods.splice(index, 1); updateSelectedFoodsList(); updateTotalNutrition(); } function updateTotalNutrition() { const totalNutrition = selectedFoods.reduce((sum, food) => ({ calories: sum.calories + food.calories * food.quantity, protein: sum.protein + food.protein * food.quantity, carbs: sum.carbs + food.carbs * food.quantity, fat: sum.fat + food.fat * food.quantity }), { calories: 0, protein: 0, carbs: 0, fat: 0 }); document.getElementById('total-nutrition').innerHTML = `

    Total Nutrition:

    Calories: ${totalNutrition.calories.toFixed(1)}

    Protein: ${totalNutrition.protein.toFixed(1)}g

    Carbs: ${totalNutrition.carbs.toFixed(1)}g

    Fat: ${totalNutrition.fat.toFixed(1)}g

    `; }