'use client'; import { useState } from 'react'; import { Box, Typography, Button, Paper, TextField, IconButton, Alert, Chip, FormControl, FormLabel, RadioGroup, FormControlLabel, Radio, ToggleButtonGroup, ToggleButton, } from '@mui/material'; import { ArrowBack, Save, Mic, BabyChangingStation, } 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, Controller } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import { format } from 'date-fns'; const diaperSchema = z.object({ type: z.enum(['wet', 'dirty', 'both', 'clean']), timestamp: z.string(), rash: z.boolean(), notes: z.string().optional(), }); type DiaperFormData = z.infer; export default function DiaperTrackPage() { const router = useRouter(); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const { register, handleSubmit, setValue, watch, control, formState: { errors }, } = useForm({ resolver: zodResolver(diaperSchema), defaultValues: { type: 'wet', rash: false, timestamp: format(new Date(), "yyyy-MM-dd'T'HH:mm"), }, }); const diaperType = watch('type'); const rash = watch('rash'); const setTimeNow = () => { const now = format(new Date(), "yyyy-MM-dd'T'HH:mm"); setValue('timestamp', now); }; const onSubmit = async (data: DiaperFormData) => { setError(null); try { // TODO: Call API to save diaper data console.log('Diaper data:', data); setSuccess(true); setTimeout(() => router.push('/'), 2000); } catch (err: any) { setError(err.message || 'Failed to log diaper change'); } }; return ( router.back()} sx={{ mr: 2 }}> Track Diaper Change {success && ( Diaper change logged successfully! )} {error && ( {error} )} {/* Icon Header */} {/* Time */} Time {/* Diaper Type */} Diaper Type ( { if (value !== null) { field.onChange(value); } }} > 💧 Wet 💩 Dirty 💧💩 Both ✨ Clean )} /> {/* Rash Indicator */} Diaper Rash? setValue('rash', false)} /> } label="No" /> setValue('rash', true)} /> } label="Yes" /> {/* Rash Warning */} {rash && ( Consider applying diaper rash cream and consulting your pediatrician if it persists. )} {/* Notes */} {/* Voice Input Button */} } label="Use Voice Input" onClick={() => {/* TODO: Implement voice input */}} sx={{ cursor: 'pointer' }} /> {/* Submit Button */} ); }