import { useState } from 'react'; import './RunForm.css'; const INJURY_LOCATIONS = [ { key: 'left_knee', label: 'Left Knee' }, { key: 'right_knee', label: 'Right Knee' }, ]; const RPE_DESCRIPTIONS = { 1: { label: 'Very easy', detail: 'Gentle warm-up, recovery jog' }, 2: { label: 'Very easy', detail: 'Full conversation easy' }, 3: { label: 'Easy', detail: 'Easy run, full sentences' }, 4: { label: 'Comfortable', detail: 'Can talk in full sentences' }, 5: { label: 'Moderate', detail: 'Talking becomes slightly harder' }, 6: { label: 'Comfortably hard', detail: 'Tempo effort, short sentences only' }, 7: { label: 'Hard', detail: 'Threshold pace, conversation difficult' }, 8: { label: 'Very hard', detail: 'Interval pace, a few words at a time' }, 9: { label: 'Extremely hard', detail: 'Near max, sustain only briefly' }, 10: { label: 'All-out', detail: 'Max sprint, lasts only seconds' }, }; function RunForm({ onAddRun }) { const today = new Date().toISOString().split('T')[0]; const [date, setDate] = useState(today); const [distance, setDistance] = useState(''); const [time, setTime] = useState(''); const [rpe, setRpe] = useState(5); const [notes, setNotes] = useState(''); const [injuries, setInjuries] = useState( Object.fromEntries(INJURY_LOCATIONS.map((loc) => [loc.key, { enabled: false, during: '', after: '' }])) ); function handleSubmit(e) { e.preventDefault(); const dist = parseFloat(distance); const mins = parseFloat(time); if (!date || isNaN(dist) || dist <= 0 || isNaN(mins) || mins <= 0) return; const runData = { date, distance_km: dist, time_minutes: mins, rpe: Number(rpe), notes: notes.trim(), }; for (const loc of INJURY_LOCATIONS) { const inj = injuries[loc.key]; if (inj.enabled) { runData[`${loc.key}_during`] = inj.during ? Number(inj.during) : null; runData[`${loc.key}_after`] = inj.after ? Number(inj.after) : null; } } onAddRun(runData); setDistance(''); setTime(''); setRpe(5); setNotes(''); setInjuries( Object.fromEntries(INJURY_LOCATIONS.map((loc) => [loc.key, { enabled: false, during: '', after: '' }])) ); } return (
); } export default RunForm;