import React, { useState, useEffect } from "react"; import { FaTimes, FaPlay, FaCheckCircle, FaSpinner, FaClipboardList, FaCalculator, FaBullseye, } from "react-icons/fa"; interface RunMrpModalProps { isOpen: boolean; onClose: () => void; onRunComplete: () => void; } type Step = | "idle" | "demand" | "inventory" | "suggestions" | "completed" | "error"; const RunMrpModal: React.FC = ({ isOpen, onClose, onRunComplete, }) => { const [currentStep, setCurrentStep] = useState("idle"); const [progress, setProgress] = useState(0); useEffect(() => { if (currentStep !== "idle" && currentStep !== "completed") { const interval = setInterval(() => { setProgress((prev) => { if (prev >= 100) { clearInterval(interval); return 100; } return prev + 10; }); }, 150); return () => clearInterval(interval); } }, [currentStep]); useEffect(() => { if (progress >= 100) { if (currentStep === "demand") { setCurrentStep("inventory"); setProgress(0); } else if (currentStep === "inventory") { setCurrentStep("suggestions"); setProgress(0); } else if (currentStep === "suggestions") { onRunComplete(); // Signal completion to parent setCurrentStep("completed"); setProgress(100); } } }, [progress, currentStep, onRunComplete]); const handleStartMrp = () => { setCurrentStep("demand"); setProgress(0); }; const handleClose = () => { setCurrentStep("idle"); setProgress(0); onClose(); }; if (!isOpen) return null; const getStepClass = (step: Step, targetStep: Step) => { if (currentStep === step) return "text-blue-600 font-semibold"; if ( (targetStep === "demand" && currentStep !== "idle") || (targetStep === "inventory" && (currentStep === "suggestions" || currentStep === "completed")) || (targetStep === "suggestions" && currentStep === "completed") ) { return "text-green-600"; } return "text-gray-500"; }; const renderStep = ( step: Step, targetStep: Step, icon: React.ReactNode, label: string ) => (
{currentStep === step ? ( ) : getStepClass(step, targetStep) === "text-green-600" ? ( ) : ( icon )}

{label}

{currentStep === step && (
)}
); return (

MRP Çalıştırma Süreci

{currentStep === "idle" && (

MRP sürecini başlatmak için butona tıklayın. Bu işlem mevcut ihtiyaç ve önerileri güncelleyecektir.

)} {currentStep !== "idle" && ( <> {renderStep( "demand", "demand", , "Talep Toplama" )} {renderStep( "inventory", "demand", , "Stok Kontrolü ve Net İhtiyaç Hesaplama" )} {renderStep( "suggestions", "inventory", , "Üretim ve Satınalma Önerileri Oluşturma" )} )} {currentStep === "completed" && (

MRP Süreci Başarıyla Tamamlandı!

İlgili sayfalara giderek sonuçları inceleyebilirsiniz.

)}
); }; export default RunMrpModal;