import { Plus, Shuffle, Trash2 } from 'lucide-react'; import type { Process } from '@core/types'; import { useProcessStore } from '../../store/processStore'; import ProcessCard from './ProcessCard'; import IconButton from '../shared/IconButton'; import { generateId, nextColor } from '../shared/processUtils'; interface ProcessListProps { onEditProcess: (process: Process) => void; onAddNew: () => void; } const MAX_PROCESSES = 16; /** Generates a random process for quick testing */ function makeRandomProcess(index: number): Process { const cpuDur = Math.floor(Math.random() * 6) + 1; const ioDur = Math.floor(Math.random() * 5) + 1; const hasBothBursts = Math.random() > 0.4; return { id: generateId(), name: `P${index}`, arrivalTime: Math.floor(Math.random() * 8), priority: Math.floor(Math.random() * 10) + 1, color: nextColor(), bursts: hasBothBursts ? [{ type: 'cpu', duration: cpuDur }, { type: 'io', duration: ioDur }, { type: 'cpu', duration: Math.floor(Math.random() * 4) + 1 }] : [{ type: 'cpu', duration: cpuDur }], }; } const ProcessList = ({ onEditProcess, onAddNew }: ProcessListProps) => { const processes = useProcessStore(s => s.processes); const removeProcess = useProcessStore(s => s.removeProcess); const clearProcesses = useProcessStore(s => s.clearProcesses); const addProcess = useProcessStore(s => s.addProcess); const canAdd = processes.length < MAX_PROCESSES; const handleRandomize = () => { const p = makeRandomProcess(processes.length + 1); addProcess(p); }; return (
{/* List header */}
{processes.length}/{MAX_PROCESSES} processos
{/* Cards */}
{processes.length === 0 ? (
Nenhum processo adicionado Clique em + para criar
) : ( processes.map(p => ( )) )}
{/* Add button */} {canAdd && ( )}
); }; export default ProcessList;