import React, { useState } from 'react';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
const CalorieIntakeCalculator = () => {
const [age, setAge] = useState('');
const [weight, setWeight] = useState('');
const [height, setHeight] = useState('');
const [gender, setGender] = useState('');
const [activityLevel, setActivityLevel] = useState('');
const [goalType, setGoalType] = useState('maintain');
const [result, setResult] = useState(null);
const calculateCalories = () => {
// Validate inputs
if (!age || !weight || !height || !gender || !activityLevel) {
alert('Please fill in all fields');
return;
}
// Basal Metabolic Rate (BMR) calculation using Mifflin-St Jeor Equation
let bmr;
if (gender === 'male') {
bmr = 10 * weight + 6.25 * height - 5 * age + 5;
} else {
bmr = 10 * weight + 6.25 * height - 5 * age - 161;
}
// Activity level multipliers
const activityMultipliers = {
sedentary: 1.2,
light: 1.375,
moderate: 1.55,
active: 1.725,
veryActive: 1.9
};
// Total Daily Energy Expenditure (TDEE)
const tdee = bmr * activityMultipliers[activityLevel];
// Adjust calories based on goal
let finalCalories;
switch (goalType) {
case 'lose':
finalCalories = tdee - 500; // Moderate weight loss
break;
case 'gain':
finalCalories = tdee + 500; // Moderate weight gain
break;
default:
finalCalories = tdee; // Maintain weight
}
setResult({
bmr: Math.round(bmr),
tdee: Math.round(tdee),
calories: Math.round(finalCalories)
});
};
return (
Calorie Intake Calculator
{/* Age Input */}
setAge(e.target.value)}
placeholder="Enter your age"
className="w-full"
/>
{/* Weight Input */}
setWeight(e.target.value)}
placeholder="Enter your weight"
className="w-full"
/>
{/* Height Input */}
setHeight(e.target.value)}
placeholder="Enter your height"
className="w-full"
/>
{/* Gender Select */}
{/* Activity Level Select */}
{/* Goal Type Select */}
{/* Calculate Button */}
{/* Results Display */}
{result && (
Your Results
Basal Metabolic Rate (BMR):
{result.bmr} calories/day
Total Daily Energy Expenditure (TDEE):
{result.tdee} calories/day
Recommended Daily Intake:
{result.calories} calories/day
)}
);
};
export default CalorieIntakeCalculator;