import { useState } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { motion } from "framer-motion"; const stagesList = [ "Design", "Manufacturing", "Inspection & Assembly", "Trial", "Sample Validation", "Pilot Run", "Handover" ]; export default function ProjectManagementApp() { const [projects, setProjects] = useState([]); const [name, setName] = useState(""); const [number, setNumber] = useState(""); const today = new Date().toISOString().split("T")[0]; const addProject = () => { if (!name || !number) return; const stages = {}; stagesList.forEach(stage => { stages[stage] = { plannedStart: "", plannedEnd: "", actualStart: "", actualEnd: "", issue: "", status: "On Time" }; }); setProjects([...projects, { id: Date.now(), name, number, stages, movements: [], completedDate: "" }]); setName(""); setNumber(""); }; const updateStage = (id, stage, field, value) => { setProjects(projects.map(p => { if (p.id !== id) return p; const prev = p.stages[stage]; const updated = { ...prev, [field]: value }; // AUTO DELAY LOGIC if (updated.actualEnd && updated.plannedEnd && updated.actualEnd > updated.plannedEnd) { updated.status = "Delay"; } else { updated.status = "On Time"; } return { ...p, stages: { ...p.stages, [stage]: updated }, movements: [...p.movements, `${stage} updated (${field}) on ${new Date().toLocaleDateString()}`] }; })); }; // COMPLETED PROJECTS MONTH/YEAR const completedProjects = projects.filter(p => { const h = p.stages["Handover"]; return h.actualEnd; }); const grouped = {}; completedProjects.forEach(p => { const date = new Date(p.stages["Handover"].actualEnd); const key = `${date.getFullYear()}-${date.getMonth() + 1}`; if (!grouped[key]) grouped[key] = []; grouped[key].push(p.name); }); return (