import { useState, useEffect } from 'react' import { Target, Plus, Pencil, Trash2, TrendingUp, Calendar } from 'lucide-react' import { api } from '../utils/api' import dayjs from 'dayjs' import 'dayjs/locale/de' dayjs.locale('de') // Goal Mode Definitions const GOAL_MODES = [ { id: 'weight_loss', icon: '📉', label: 'Gewichtsreduktion', description: 'Kaloriendefizit, Fettabbau', color: '#D85A30' }, { id: 'strength', icon: '💪', label: 'Kraftaufbau', description: 'Muskelwachstum, progressive Belastung', color: '#378ADD' }, { id: 'endurance', icon: '🏃', label: 'Ausdauer', description: 'VO2Max, aerobe Kapazität', color: '#1D9E75' }, { id: 'recomposition', icon: '⚖️', label: 'Körperkomposition', description: 'Gleichzeitig Fett ab- & Muskeln aufbauen', color: '#7B68EE' }, { id: 'health', icon: '❤️', label: 'Allgemeine Gesundheit', description: 'Ausgewogen, präventiv', color: '#E67E22' } ] // Goal Type Definitions const GOAL_TYPES = { weight: { label: 'Gewicht', unit: 'kg', icon: '⚖️' }, body_fat: { label: 'Körperfett', unit: '%', icon: '📊' }, lean_mass: { label: 'Muskelmasse', unit: 'kg', icon: '💪' }, vo2max: { label: 'VO2Max', unit: 'ml/kg/min', icon: '🫁' }, strength: { label: 'Kraft', unit: 'kg', icon: '🏋️' }, flexibility: { label: 'Beweglichkeit', unit: 'cm', icon: '🤸' }, bp: { label: 'Blutdruck', unit: 'mmHg', icon: '❤️' }, rhr: { label: 'Ruhepuls', unit: 'bpm', icon: '💓' } } export default function GoalsPage() { const [goalMode, setGoalMode] = useState(null) const [goals, setGoals] = useState([]) const [showGoalForm, setShowGoalForm] = useState(false) const [editingGoal, setEditingGoal] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [toast, setToast] = useState(null) // Form state const [formData, setFormData] = useState({ goal_type: 'weight', is_primary: false, target_value: '', unit: 'kg', target_date: '', name: '', description: '' }) useEffect(() => { loadData() }, []) const loadData = async () => { setLoading(true) setError(null) try { const [modeData, goalsData] = await Promise.all([ api.getGoalMode(), api.listGoals() ]) setGoalMode(modeData.goal_mode) setGoals(goalsData) } catch (err) { console.error('Failed to load goals:', err) setError('Fehler beim Laden der Ziele') } finally { setLoading(false) } } const showToast = (message, duration = 2000) => { setToast(message) setTimeout(() => setToast(null), duration) } const handleGoalModeChange = async (newMode) => { try { await api.updateGoalMode(newMode) setGoalMode(newMode) showToast('✓ Trainingsmodus aktualisiert') } catch (err) { console.error('Failed to update goal mode:', err) setError('Fehler beim Aktualisieren des Trainingsmodus') } } const handleCreateGoal = () => { setEditingGoal(null) setFormData({ goal_type: 'weight', is_primary: goals.length === 0, // First goal is primary by default target_value: '', unit: GOAL_TYPES['weight'].unit, target_date: '', name: '', description: '' }) setShowGoalForm(true) } const handleEditGoal = (goal) => { setEditingGoal(goal.id) setFormData({ goal_type: goal.goal_type, is_primary: goal.is_primary, target_value: goal.target_value, unit: goal.unit, target_date: goal.target_date || '', name: goal.name || '', description: goal.description || '' }) setShowGoalForm(true) } const handleGoalTypeChange = (type) => { setFormData(f => ({ ...f, goal_type: type, unit: GOAL_TYPES[type].unit })) } const handleSaveGoal = async () => { if (!formData.target_value) { setError('Bitte Zielwert eingeben') return } try { const data = { goal_type: formData.goal_type, is_primary: formData.is_primary, target_value: parseFloat(formData.target_value), unit: formData.unit, target_date: formData.target_date || null, name: formData.name || null, description: formData.description || null } if (editingGoal) { await api.updateGoal(editingGoal, data) showToast('✓ Ziel aktualisiert') } else { await api.createGoal(data) showToast('✓ Ziel erstellt') } await loadData() setShowGoalForm(false) setEditingGoal(null) } catch (err) { console.error('Failed to save goal:', err) setError(err.message || 'Fehler beim Speichern') } } const handleDeleteGoal = async (goalId) => { if (!confirm('Ziel wirklich löschen?')) return try { await api.deleteGoal(goalId) showToast('✓ Ziel gelöscht') await loadData() } catch (err) { console.error('Failed to delete goal:', err) setError('Fehler beim Löschen') } } const getProgressColor = (progress) => { if (progress >= 100) return 'var(--accent)' if (progress >= 75) return '#1D9E75' if (progress >= 50) return '#378ADD' if (progress >= 25) return '#E67E22' return '#D85A30' } if (loading) { return (
{error}
Wähle deine grundlegende Trainingsausrichtung. Dies beeinflusst die Gewichtung und Interpretation aller Analysen.
Noch keine Ziele definiert