'use client'; import React, { useState } from 'react'; import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Box, Typography, TextField, Select, MenuItem, FormControl, InputLabel, Alert, Chip, Grid, InputAdornment, } from '@mui/material'; import CheckCircleIcon from '@mui/icons-material/CheckCircle'; import EditIcon from '@mui/icons-material/Edit'; import CloseIcon from '@mui/icons-material/Close'; interface VoiceActivityReviewProps { open: boolean; transcript: string; classification: { type: string; details: Record; confidence: number; timestamp?: Date; }; onApprove: (data: any) => void; onEdit: (editedData: any) => void; onReject: () => void; onClose: () => void; } export function VoiceActivityReview({ open, transcript, classification, onApprove, onEdit, onReject, onClose, }: VoiceActivityReviewProps) { const [isEditing, setIsEditing] = useState(false); const [editedData, setEditedData] = useState>({}); React.useEffect(() => { if (open) { setEditedData(classification.details || {}); setIsEditing(false); } }, [open, classification]); const handleApprove = () => { onApprove({ type: classification.type, details: classification.details, timestamp: classification.timestamp, }); }; const handleSaveEdit = () => { onEdit({ type: classification.type, details: editedData, timestamp: classification.timestamp, }); }; const renderFieldEditor = (key: string, value: any) => { // Render different input types based on field if (key === 'notes') { return ( setEditedData({ ...editedData, [key]: e.target.value })} variant="outlined" size="small" /> ); } if (key === 'amount') { return ( setEditedData({ ...editedData, [key]: Number(e.target.value) })} variant="outlined" size="small" InputProps={{ endAdornment: {editedData.unit || 'ml'}, }} /> ); } if (key === 'duration') { return ( setEditedData({ ...editedData, [key]: Number(e.target.value) })} variant="outlined" size="small" InputProps={{ endAdornment: min, }} /> ); } if (key === 'feedingType') { return ( Feeding Type ); } if (key === 'diaperType') { return ( Diaper Type ); } if (key === 'quality') { return ( Sleep Quality ); } if (key === 'location') { return ( Location ); } if (key === 'side') { return ( Side ); } // Default text input return ( setEditedData({ ...editedData, [key]: e.target.value })} variant="outlined" size="small" /> ); }; const getActivityLabel = () => { return classification.type.charAt(0).toUpperCase() + classification.type.slice(1); }; const getConfidenceColor = () => { if (classification.confidence >= 0.7) return 'success'; if (classification.confidence >= 0.4) return 'warning'; return 'error'; }; return ( Review Voice Command {/* Transcript */} You said: "{transcript}" {/* Extracted Data */} {isEditing ? 'Edit Activity Details' : 'Extracted Details'} {isEditing ? ( {Object.entries(editedData).map(([key, value]) => ( {renderFieldEditor(key, value)} ))} ) : ( {Object.entries(classification.details).map(([key, value]) => ( {key.charAt(0).toUpperCase() + key.slice(1).replace(/([A-Z])/g, ' $1')}: {value === null || value === undefined ? '-' : String(value)} ))} )} {/* Help text */} {!isEditing && ( Please review the extracted information. Click Edit to make changes or Approve if it looks correct. )} {isEditing ? ( <> ) : ( <> )} ); }