'use client'; import { useState, useEffect } from 'react'; import { Box, Typography, Button, Paper, TextField, FormControl, FormLabel, RadioGroup, FormControlLabel, Radio, IconButton, Alert, Chip, } from '@mui/material'; import { ArrowBack, PlayArrow, Stop, Save, Mic, } from '@mui/icons-material'; import { useRouter } from 'next/navigation'; import { AppShell } from '@/components/layouts/AppShell/AppShell'; import { ProtectedRoute } from '@/components/common/ProtectedRoute'; import { motion } from 'framer-motion'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; const feedingSchema = z.object({ type: z.enum(['breast_left', 'breast_right', 'breast_both', 'bottle', 'solid']), amount: z.number().min(0).optional(), unit: z.enum(['ml', 'oz']).optional(), notes: z.string().optional(), }); type FeedingFormData = z.infer; export default function FeedingTrackPage() { const router = useRouter(); const [isTimerRunning, setIsTimerRunning] = useState(false); const [duration, setDuration] = useState(0); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const { register, handleSubmit, watch, formState: { errors }, } = useForm({ resolver: zodResolver(feedingSchema), defaultValues: { type: 'breast_left', unit: 'ml', }, }); const feedingType = watch('type'); useEffect(() => { let interval: NodeJS.Timeout; if (isTimerRunning) { interval = setInterval(() => { setDuration((prev) => prev + 1); }, 1000); } return () => clearInterval(interval); }, [isTimerRunning]); const formatDuration = (seconds: number) => { const mins = Math.floor(seconds / 60); const secs = seconds % 60; return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`; }; const onSubmit = async (data: FeedingFormData) => { setError(null); try { // TODO: Call API to save feeding data console.log('Feeding data:', { ...data, duration }); setSuccess(true); setTimeout(() => router.push('/'), 2000); } catch (err: any) { setError(err.message || 'Failed to log feeding'); } }; return ( router.back()} sx={{ mr: 2 }}> Track Feeding {success && ( Feeding logged successfully! )} {error && ( {error} )} {/* Timer Section */} {formatDuration(duration)} {!isTimerRunning ? ( ) : ( )} {/* Feeding Type */} Feeding Type } label="Left Breast" /> } label="Right Breast" /> } label="Both" /> } label="Bottle" /> } label="Solid Food" /> {/* Amount (for bottle/solid) */} {(feedingType === 'bottle' || feedingType === 'solid') && ( } label="ml" /> } label="oz" /> )} {/* Notes */} {/* Voice Input Button */} } label="Use Voice Input" onClick={() => {/* TODO: Implement voice input */}} sx={{ cursor: 'pointer' }} /> {/* Submit Button */} ); }