import React, { useState, useEffect, useCallback } from 'react'; // --- MOCK ICONS (using emojis for web) --- // This component provides a simple way to use icons with emojis. const Icon = ({ name, size = 24, color = '#000' }) => { const icons = { home: '๐Ÿ ', people: '๐Ÿ‘ฅ', cloud: 'โ˜๏ธ', settings: 'โš™๏ธ', airplane: 'โœˆ๏ธ', ai: '๐Ÿง ', camera: '๐Ÿ“ท', chart: '๐Ÿ“Š', edit: 'โœ๏ธ', computer: '๐Ÿ’ป', wrench: '๐Ÿ”ง', building: '๐Ÿ—๏ธ', bolt: 'โšก', satellite: '๐Ÿ“ก', flask: '๐Ÿงช', heart: 'โค๏ธ', car: '๐Ÿš—', user: '๐Ÿ‘ค', id: '๐Ÿ†”', briefcase: '๐Ÿ’ผ', download: '๐Ÿ“ฅ', 'arrow-left': 'โฌ…๏ธ', share: '๐Ÿ“ค', upload: 'โฌ†๏ธ', }; return {icons[name] || 'โ“'}; }; // --- CUSTOM HEADER COMPONENTS --- // A header with a wave-like SVG background. const WaveHeader = ({ title }) => (

{title}

); // A simple back button component. const BackButton = ({ onClick }) => ( ); // A header component that includes a back button. const HeaderWithBack = ({ title, onBackPress }) => (
{onBackPress && }
); // --- CUSTOM MESSAGE BOX COMPONENT --- const MessageBox = ({ message, onClose }) => { if (!message) return null; return (

{message}

); }; // --- SCREENS --- // 1. Login/Register Screen const AuthScreen = ({ navigate, setUserProfile, showMessage }) => { const [isLogin, setIsLogin] = useState(true); const [formData, setFormData] = useState({ username: '', password: '', confirmPassword: '', fullName: '', employeeId: '', department: 'Aeronautical Engineering', role: 'Staff' }); const [error, setError] = useState(''); const getUsers = () => { const users = localStorage.getItem('attendance_app_users'); return users ? JSON.parse(users) : []; }; const saveUsers = (users) => { localStorage.setItem('attendance_app_users', JSON.stringify(users)); }; // Initialize an admin user if no users exist. useEffect(() => { const users = getUsers(); if (users.length === 0) { const adminUser = { username: 'admin', password: 'admin', fullName: 'Admin User', employeeId: '001', department: 'Administration', role: 'Admin', }; saveUsers([adminUser]); } }, []); const departments = [ 'Aeronautical Engineering', 'Artificial Intelligence & Data Science', 'Computer Science & Engineering', 'Mechanical Engineering', 'Civil Engineering', 'Electrical & Electronics Engineering', 'Electronics & Communication Engineering', 'Information Technology', 'Chemical Engineering', 'Mechatronics','Computer Science and Bussiness Science' ]; const handleInputChange = (field, value) => { setFormData(prev => ({...prev, [field]: value})); setError(''); }; const handleLogin = () => { const users = getUsers(); const foundUser = users.find(user => user.username === formData.username && user.password === formData.password); if (foundUser) { setUserProfile({ name: foundUser.fullName, position: foundUser.role, employeeId: foundUser.employeeId, department: foundUser.department, role: foundUser.role, }); navigate('MainApp'); } else { setError('Invalid username or password.'); } }; const handleRegister = () => { if (!formData.username || !formData.fullName || !formData.employeeId || !formData.password) { setError('Please fill all the fields.'); return; } if (formData.password !== formData.confirmPassword) { setError('Passwords do not match.'); return; } const users = getUsers(); const existingUser = users.find(user => user.username === formData.username); if (existingUser) { setError('Username already exists.'); return; } const newUser = { username: formData.username, password: formData.password, fullName: formData.fullName, employeeId: formData.employeeId, department: formData.department, role: formData.role, }; const updatedUsers = [...users, newUser]; saveUsers(updatedUsers); setUserProfile({ name: newUser.fullName, position: newUser.role, employeeId: newUser.employeeId, department: newUser.department, role: newUser.role, }); navigate('MainApp'); }; const handleAuthAction = () => { if (isLogin) { handleLogin(); } else { handleRegister(); } }; return (

{isLogin ? 'Login' : 'Register'}

{error &&

{error}

} handleInputChange('username', e.target.value)} /> {!isLogin && ( <> handleInputChange('fullName', e.target.value)} /> handleInputChange('employeeId', e.target.value)} /> )} handleInputChange('password', e.target.value)} /> {!isLogin && handleInputChange('confirmPassword', e.target.value)} />}
College Logo
); }; // 2. Department/Home Screen const DepartmentScreen = ({ navigate, attendanceRecords, userProfile, departments }) => { const [selectedDept, setSelectedDept] = useState(userProfile?.department || departments[0]); const [selectedYear, setSelectedYear] = useState('First Year'); const [selectedSection, setSelectedSection] = useState('Section A'); const years = ['First Year', 'Second Year', 'Third Year', 'Fourth Year']; const sections = ['Section A', 'Section B']; const filteredRecords = attendanceRecords ? attendanceRecords.filter(record => record.department === selectedDept && record.year === selectedYear && record.section === selectedSection ) : []; const total = filteredRecords.reduce((sum, rec) => sum + (rec.total || 0), 0); const present = filteredRecords.reduce((sum, rec) => sum + (rec.present || 0), 0); const absent = filteredRecords.reduce((sum, rec) => sum + (rec.absent || 0), 0); const onDuty = filteredRecords.reduce((sum, rec) => sum + (rec.onDuty || 0), 0); const chartData = total === 0 ? [] : [ { label: 'Present', value: (present / total) * 100, color: '#2ecc71' }, { label: 'Absent', value: (absent / total) * 100, color: '#e74c3c' }, { label: 'On Duty', value: (onDuty / total) * 100, color: '#f39c12' }, ]; const departmentData = [ { name: 'Aeronautical Engineering', icon: 'airplane' }, { name: 'Artificial Intelligence & Data Science', icon: 'ai' }, { name: 'Computer Science & Engineering', icon: 'computer' }, { name: 'Mechanical Engineering', icon: 'wrench' }, { name: 'Civil Engineering', icon: 'building' }, { name: 'Electrical & Electronics Engineering', icon: 'bolt' }, { name: 'Electronics & Communication Engineering', icon: 'satellite' }, { name: 'Information Technology', icon: 'computer' }, { name: 'Chemical Engineering', icon: 'flask' }, { name: 'Mechatronics', icon: 'wrench' }, { name: 'Computer Science and Bussiness Science', icon: 'computer' } ]; return (
{/* Dashboard chart above department list */}
{chartData.length > 0 ? chartData.map(d => (

{d.label}: {d.value.toFixed(1)}%

)) : (

No attendance data for this class to display a chart.

)}
{/* Class selection for chart */}
{/* Department list */}

Department

{departmentData.map((dept, index) => ( ))}
); }; // 3. Year Selection Screen const YearScreen = ({ navigate, params }) => { const years = ['First Year', 'Second Year', 'Third Year', 'Fourth Year']; return (
navigate('MainApp', { screen: 'Home' })} />

{params.department}

{years.map((year, index) => ( ))}
); }; // 4. Section Selection Screen const SectionScreen = ({ navigate, params }) => { const sections = ['Section A', 'Section B']; const { year, department } = params; return (
navigate('Year', { department })} />

{`${department} - ${year}`}

{sections.map((section, index) => ( ))}
); }; // 5. Attendance Entry Screen const AttendanceScreen = ({ addAttendanceRecord, year, section, department, navigate, defaultStudentCounts, showMessage, studentList }) => { const [formData, setFormData] = useState({ total: '', present: '', absent: '', onDuty: '', absentNumbers: '' }); useEffect(() => { const classKey = `${department}-${year}-${section}`; const totalStudents = defaultStudentCounts[classKey]; if (totalStudents) { setFormData(prevData => ({ ...prevData, total: totalStudents })); } else { setFormData(prevData => ({ ...prevData, total: '' })); } }, [department, year, section, defaultStudentCounts]); // Get current roster for validation const rosterKey = `${department}-${year}-${section}`; const currentRoster = studentList[rosterKey] || []; const validRegNos = currentRoster.map(s => s.regNo.trim()); const handleInputChange = (field, value) => { const numericValue = value === '' ? '' : parseInt(value, 10); setFormData(prevData => ({ ...prevData, [field]: isNaN(numericValue) ? '' : numericValue, })); }; const handleSubmit = () => { // Validate total = present + absent + onDuty const total = Number(formData.total); const present = Number(formData.present); const absent = Number(formData.absent); const onDuty = Number(formData.onDuty); if (!total) { showMessage("Please enter the total number of students."); return; } if (present + absent + onDuty !== total) { showMessage("Sum of Present, Absent, and On Duty must equal Total students."); return; } // Validate absentNumbers const absentNumbersArr = (formData.absentNumbers || '') .split(',') .map(s => s.trim()) .filter(s => s); const invalidRegNos = absentNumbersArr.filter(regNo => !validRegNos.includes(regNo)); if (absentNumbersArr.length !== absent) { showMessage(`Number of absent register numbers (${absentNumbersArr.length}) does not match Absent count (${absent}).`); return; } if (invalidRegNos.length > 0) { showMessage(`Invalid register numbers: ${invalidRegNos.join(', ')}. Please check the roster for valid register numbers.`); return; } const newRecord = { ...formData, date: new Date(), year, section, department }; addAttendanceRecord(newRecord); showMessage("Report Submitted!"); setFormData({ total: formData.total, present: '', absent: '', onDuty: '', absentNumbers: '' }); }; return (
navigate('Section', { department, year })} />

Total Number of Students:

handleInputChange('total', e.target.value)} />

Total Number of Students Present:

handleInputChange('present', e.target.value)} />

Total Number of Students Absents:

handleInputChange('absent', e.target.value)} />

Total Number of Students on OD:

handleInputChange('onDuty', e.target.value)} />

Enter the Absent Students Register Numbers (comma separated):