import React, { useEffect, useState, useMemo } from 'react'; import { useSelector } from 'react-redux'; import StyledWrapper from './StyledWrapper'; import { IconCpu, IconDatabase, IconClock, IconServer, IconChevronDown, IconChartLine } from '@tabler/icons'; const getProcessOptions = (processes) => { return [ { value: 'cumulative', label: 'Cumulative (All Processes)' }, ...(processes ?? []).map((process) => ({ value: String(process.pid), label: `PID ${process.pid}${process.title ? ` - ${process.title}` : ''}${process.type ? ` (${process.type})` : ''}` })) ]; }; const Performance = () => { const { systemResources } = useSelector((state) => state.performance); const [selectedPid, setSelectedPid] = useState('cumulative'); useEffect(() => { const { ipcRenderer } = window; if (!ipcRenderer) { console.warn('IPC Renderer not available'); return; } const startMonitoring = async () => { try { await ipcRenderer.invoke('renderer:start-system-monitoring', 2000); } catch (error) { console.error('Failed to start system monitoring:', error); } }; const stopMonitoring = async () => { try { await ipcRenderer.invoke('renderer:stop-system-monitoring'); } catch (error) { console.error('Failed to stop system monitoring:', error); } }; startMonitoring(); return () => { stopMonitoring(); }; }, []); const formatBytes = (bytes) => { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; const formatUptime = (seconds) => { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); const secs = Math.floor(seconds % 60); if (hours > 0) return `${hours}h ${minutes}m ${secs}s`; if (minutes > 0) return `${minutes}m ${secs}s`; return `${secs}s`; }; const SystemResourceCard = ({ icon: Icon, title, value, subtitle, color = 'default', trend }) => (