import React, { useState } from 'react'; import { Box, Typography, TextField, Select, MenuItem, FormControl, InputLabel, Button, Grid, Paper, Accordion, AccordionSummary, AccordionDetails, CircularProgress, IconButton, } from '@mui/material'; import { ExpandMore as ExpandMoreIcon, FolderOpen as FolderOpenIcon, Refresh as RefreshIcon, Clear as ClearIcon, } from '@mui/icons-material'; import ProcessingStatus from './ProcessingStatus'; interface FileProcessingManagerProps { fileType: 'Shell' | 'MSAG' | 'Dx Supplementary'; } const FileProcessingManager: React.FC = ({ fileType }) => { const [folderPath, setFolderPath] = useState('C://BenefitAgents/Inputfiles'); const [environment, setEnvironment] = useState(''); const [isLoading, setIsLoading] = useState(false); const [loadStatus, setLoadStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle'); const [configAccordionExpanded, setConfigAccordionExpanded] = useState(true); const [triggerProcessing, setTriggerProcessing] = useState(false); const environments = [ { value: 'CRMTSTLIB', label: 'CRMTSTLIB - Testing' }, { value: 'RL1FLO', label: 'RL1FLO - O Lib - Release 1' }, { value: 'RL1FLM', label: 'RL1FLM - M Lib - Release 1' }, { value: 'RL2FLO', label: 'RL2FLO - O Lib - Release 2' }, { value: 'RL2FLM', label: 'RL2FLM - M Lib - Release 2' }, { value: 'RL3FLO', label: 'RL1FLO - O Lib - Release 3' }, { value: 'RL3FLM', label: 'RL1FLM - M Lib - Release 3' }, { value: 'RL4FLO', label: 'RL2FLO - O Lib - Release 4' }, { value: 'RL4FLM', label: 'RL2FLM - M Lib - Release 4' }, ]; const handleFolderSelect = () => { // In a real application, this would open a file dialog // For now, we'll simulate folder selection const input = document.createElement('input'); input.type = 'file'; input.webkitdirectory = true; input.onchange = (e) => { const files = (e.target as HTMLInputElement).files; if (files && files.length > 0) { const path = files[0].webkitRelativePath.split('/')[0]; setFolderPath(path); } }; input.click(); }; const handleLoad = async () => { if (!folderPath || !environment) return; setConfigAccordionExpanded(false); // Auto-minimize the configuration accordion setTriggerProcessing(true); }; const handleClear = () => { setFolderPath('C://BenefitAgents/Inputfiles'); setEnvironment(''); setIsLoading(false); setLoadStatus('idle'); setConfigAccordionExpanded(true); // Expand configuration accordion when clearing setTriggerProcessing(false); }; const handleLoadingChange = (loading: boolean) => { setIsLoading(loading); }; const handleStatusChange = (status: 'idle' | 'loading' | 'success' | 'error') => { setLoadStatus(status); }; const handleProcessingComplete = () => { setTriggerProcessing(false); }; const isLoadButtonEnabled = folderPath && environment && !isLoading; return ( {/* Configuration Accordion */} setConfigAccordionExpanded(!configAccordionExpanded)} sx={{ flexShrink: 0 }} > } sx={{ backgroundColor: 'grey.50', '& .MuiAccordionSummary-content': { alignItems: 'center', }, }} > {fileType} Configuration {/* Configuration Form */} {fileType} Processing Configuration {/* Folder Path Selection */} setFolderPath(e.target.value)} variant="outlined" helperText="Default path or select a custom folder" /> {/* Environment Selection */} Environment {/* Action Buttons */} {/* Processing Status Component */} ); }; export default FileProcessingManager;