'use client' import { useState, useCallback } from 'react' import { useTranslations } from 'next-intl' import Box from '@mui/material/Box' import Card from '@mui/material/Card' import CardContent from '@mui/material/CardContent' import Typography from '@mui/material/Typography' import Button from '@mui/material/Button' import CircularProgress from '@mui/material/CircularProgress' import Collapse from '@mui/material/Collapse' import { useTheme } from '@mui/material/styles' import { alpha } from '@mui/material/styles' import classnames from 'classnames' // Util Imports import { commonLayoutClasses } from '@layouts/utils/layoutClasses' import UploadBox from './components/UploadBox' import ResultCard from './components/ResultCard' import type { UploadedFile } from './components/UploadBox' import type { PestResult } from './components/ResultCard' export default function PlantPestDetection() { const t = useTranslations('pestDetection') const theme = useTheme() const primary = theme.palette.primary const [file, setFile] = useState(null) const [result, setResult] = useState(null) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const handleFileSelect = useCallback((newFile: UploadedFile | null) => { setFile(newFile) setResult(null) setError(null) }, []) const handleAnalyze = useCallback(() => { if (!file) return setLoading(true) setError(null) setResult(null) const delay = 1500 + Math.random() * 1000 setTimeout(() => { setResult({ pest: t('mockResult.pest'), confidence: 92, description: t('mockResult.description'), treatment: t('mockResult.treatment'), }) setLoading(false) }, delay) }, [file, t]) const handleReset = useCallback(() => { if (file) { URL.revokeObjectURL(file.preview) } setFile(null) setResult(null) setError(null) setLoading(false) }, [file]) return ( {/* Header */} {t('title')} {t('subtitle')} {/* Upload card */} {/* Action buttons */} {file && ( )} {/* Loading state */} {t('analyzing')} {/* Result card */} {result && !loading && ( {t('resultTitle')} )} ) }