import React, { useState, useMemo, useEffect } from 'react'; import { Layout, FileText, CheckCircle, Clock, Settings, Plus, Search, Bell, Shield, MessageSquare, FileCheck, XCircle, FileCode, FolderOpen, Activity, Award, Wrench, AlertTriangle, History, TrendingUp, MoreVertical, Filter, BarChart3, Calendar, FileSearch, HardHat, ClipboardCheck, ChevronRight, Info, CheckCircle2 } from 'lucide-react'; import { Chart as ChartJS, ArcElement, Tooltip, Legend, CategoryScale, LinearScale, BarElement, PointElement, LineElement, Title } from 'chart.js'; import { Doughnut, Bar } from 'react-chartjs-2'; // Register ChartJS components for visual reporting ChartJS.register(ArcElement, Tooltip, Legend, CategoryScale, LinearScale, BarElement, PointElement, LineElement, Title); const App = () => { // --- CORE STATE --- const [activeTab, setActiveTab] = useState('dashboard'); const [searchQuery, setSearchQuery] = useState(''); const [isModalOpen, setIsModalOpen] = useState(false); const [notification, setNotification] = useState(null); // --- DATA STATE --- const [documents, setDocuments] = useState([ { id: 1, docId: 'KR-SOP-MAN-001', name: 'CNC Lathe Operating Instructions', status: 'Approved', owner: 'Alex Rivera', date: '2023-10-15', department: 'Manufacturing', iso: 'ISO 9001' }, { id: 2, docId: 'KR-POL-QUA-002', name: 'Quality Policy Manual', status: 'Approved', owner: 'Sarah Chen', date: '2023-08-22', department: 'Quality Assurance', iso: 'ISO 9001' }, { id: 3, docId: 'KR-ENV-PRC-005', name: 'Hazardous Waste Storage', status: 'Approved', owner: 'Jordan Smith', date: '2023-11-02', department: 'Manufacturing', iso: 'ISO 14001' }, { id: 4, docId: 'KR-SOP-ENG-004', name: 'Drafting Standards', status: 'Pending', owner: 'Mike Ross', date: '2023-12-01', department: 'Engineering', iso: 'ISO 9001' }, { id: 5, docId: 'KR-SOP-HR-012', name: 'Onboarding Workflow', status: 'Pending', owner: 'Elena Gilbert', date: '2023-10-25', department: 'HR', iso: 'ISO 9001' }, ]); const [calibrations, setCalibrations] = useState([ { id: 'c1', name: 'CNC-4 Milling Center', calId: 'CAL-9921', due: '2024-04-10', status: 'Overdue' }, { id: 'c2', name: 'Mitutoyo Caliper Set', calId: 'CAL-8842', due: '2024-12-05', status: 'Verified' }, { id: 'c3', name: 'Instron Tensile Tester', calId: 'CAL-1102', due: '2024-05-15', status: 'Due Soon' } ]); const [training] = useState([ { name: 'Sarah Miller', dept: 'Quality Assurance', score: 92, status: 'Compliant', certs: ['Lead Auditor', 'Six Sigma'] }, { name: 'Robert Chen', dept: 'Manufacturing', score: 65, status: 'Incomplete', certs: ['Forklift'] }, { name: 'Elena Rodriguez', dept: 'Engineering', score: 100, status: 'Compliant', certs: ['PE Cert'] } ]); const [auditLog, setAuditLog] = useState([ { timestamp: new Date().toLocaleTimeString(), user: 'SYSTEM', action: 'System Initialization', ref: 'BOOT-001' }, { timestamp: new Date().toLocaleTimeString(), user: 'J. Doe', action: 'Portal Accessed', ref: 'AUTH-202' }, ]); const [capas] = useState([ { id: 'CP-101', issue: 'Improper label adhesion', status: 'Open', priority: 'High', date: '2024-01-12' }, { id: 'CP-102', issue: 'Calibration drift in Unit 4', status: 'Closed', priority: 'Medium', date: '2023-12-05' } ]); // --- ACTIONS --- const triggerNotification = (msg) => { setNotification(msg); setTimeout(() => setNotification(null), 3000); }; const handleStatusChange = (id, newStatus) => { const doc = documents.find(d => d.id === id); setDocuments(prev => prev.map(f => f.id === id ? { ...f, status: newStatus } : f)); setAuditLog(prev => [{ timestamp: new Date().toLocaleTimeString(), user: 'J. Doe', action: `Status change to ${newStatus}`, ref: doc?.docId || 'N/A' }, ...prev]); triggerNotification(`Record ${doc?.docId} updated to ${newStatus}`); }; const performCalibration = (id) => { setCalibrations(prev => prev.map(c => c.id === id ? { ...c, status: 'Verified', due: '2025-01-01' } : c)); triggerNotification("Equipment recalibration logged successfully."); }; // --- COMPUTED DATA --- const filteredFiles = useMemo(() => { return documents.filter(f => f.name.toLowerCase().includes(searchQuery.toLowerCase()) || f.docId.toLowerCase().includes(searchQuery.toLowerCase()) ); }, [documents, searchQuery]); const stats = useMemo(() => { const pending = documents.filter(d => d.status === 'Pending').length; const isoCounts = documents.reduce((acc, d) => { acc[d.iso] = (acc[d.iso] || 0) + 1; return acc; }, {}); return { pending, isoCounts, total: documents.length }; }, [documents]); const doughnutData = { labels: ['ISO 9001', 'ISO 14001', 'ISO 45001'], datasets: [{ data: [stats.isoCounts['ISO 9001'] || 0, stats.isoCounts['ISO 14001'] || 0, 0], backgroundColor: ['#4f46e5', '#10b981', '#f59e0b'], borderWidth: 0, cutout: '75%', }] }; // --- UI COMPONENTS --- const StatusBadge = ({ status }) => { const styles = { Approved: 'bg-green-100 text-green-700 border-green-200', Pending: 'bg-amber-100 text-amber-700 border-amber-200', Rejected: 'bg-red-100 text-red-700 border-red-200', Verified: 'bg-blue-100 text-blue-700 border-blue-200', Overdue: 'bg-red-100 text-red-700 border-red-200', 'Due Soon': 'bg-orange-100 text-orange-700 border-orange-200', Compliant: 'bg-green-100 text-green-700 border-green-200', Incomplete: 'bg-slate-100 text-slate-700 border-slate-200', Open: 'bg-rose-100 text-rose-700 border-rose-200', Closed: 'bg-slate-100 text-slate-700 border-slate-200', }; return ( {status} ); }; const SidebarItem = ({ icon: Icon, label, id }) => ( ); return (
{/* Toast Notification */} {notification && (
{notification}
)} {/* Sidebar */} {/* Main Container */}
{/* Universal Header */}
Workspace {activeTab}

{activeTab.replace('-', ' ')}

setSearchQuery(e.target.value)} />
{/* Dynamic Viewport */}
{activeTab === 'dashboard' && (
{[ { label: 'Controlled Docs', value: stats.total, icon: FileText, color: 'text-indigo-600', bg: 'bg-indigo-50' }, { label: 'Pending Review', value: stats.pending, icon: Clock, color: 'text-amber-600', bg: 'bg-amber-50' }, { label: 'Equipment Health', value: '94%', icon: Wrench, color: 'text-emerald-600', bg: 'bg-emerald-50' }, { label: 'CAPA Closed', value: '88%', icon: Shield, color: 'text-blue-600', bg: 'bg-blue-50' }, ].map((stat, i) => (

{stat.label}

{stat.value}

))}

Certification Pulse

{stats.total} Total Assets
{Object.entries(stats.isoCounts).map(([key, val]) => (
{key}
{val}
))}

Critical Review Queue

{documents.filter(d => d.status === 'Pending').map(doc => (

{doc.name}

{doc.docId} Owner: {doc.owner}
))} {stats.pending === 0 && (

Queue Fully Cleared

)}
)} {activeTab === 'files' && (
{filteredFiles.map(doc => ( ))}
Reference No. Documentation Title ISO Compliance Department Status Custodian
{doc.docId}

{doc.name}

Archived: {doc.date}

{doc.iso}
{doc.department} {doc.owner}
)} {activeTab === 'approvals' && (

Advanced Workflow Engine

System-mandated sequential validation. Requires verification from Department Head and Quality Assurance Director before record finalization.

{documents.filter(d => d.status === 'Pending').map(doc => (

{doc.name}

{doc.docId} • IN REVIEW

))}
)} {activeTab === 'calibration' && (
{calibrations.map((cal, i) => (

{cal.name}

{cal.calId}

Recalibration Due

{cal.due}

))}
)} {activeTab === 'audit' && (

Immutable Audit Trail

Cryptographically verified logs (Simulation)

{auditLog.map((log, i) => (
{log.timestamp}
{log.user} {log.action} {log.ref}
))}
)} {activeTab === 'training' && (
{training.map((person, i) => (
{person.name.split(' ').map(n => n[0]).join('')}

{person.name}

{person.dept}

Matrix Proficiency {person.score}%
{person.certs.map((c, j) => (
{c}
))}
))}
)} {activeTab === 'capa' && (
{capas.map((capa) => (

{capa.issue}

{capa.id} Initiated: {capa.date}
))}
)}
{/* Modern Modal Overlay */} {isModalOpen && (

Register Record

Initiate formal ISO documentation workflow and department authorization.

)}
); }; export default App;