import React, { useState, useEffect } from 'react';
import { Clock, User, Bell, CheckCircle, AlertCircle, Plus, X, ChevronRight, Activity } from 'lucide-react';
const ClinicQueueManager = () => {
const [view, setView] = useState('receptionist');
const [patients, setPatients] = useState([]);
const [showAddForm, setShowAddForm] = useState(false);
const [formData, setFormData] = useState({
name: '',
phone: '',
appointmentTime: '',
reason: ''
});
// Load patients from storage on mount
useEffect(() => {
const loadPatients = async () => {
try {
const result = await window.storage.get('clinic-patients');
if (result && result.value) {
setPatients(JSON.parse(result.value));
}
} catch (error) {
console.log('No existing patients found');
}
};
loadPatients();
}, []);
// Save patients to storage whenever they change
useEffect(() => {
const savePatients = async () => {
if (patients.length > 0) {
try {
await window.storage.set('clinic-patients', JSON.stringify(patients));
} catch (error) {
console.error('Error saving patients:', error);
}
}
};
savePatients();
}, [patients]);
const addPatient = () => {
if (formData.name && formData.phone && formData.appointmentTime) {
const newPatient = {
id: Date.now(),
...formData,
status: 'scheduled',
addedAt: new Date().toISOString()
};
setPatients([...patients, newPatient]);
setFormData({ name: '', phone: '', appointmentTime: '', reason: '' });
setShowAddForm(false);
}
};
const checkInPatient = (id) => {
setPatients(patients.map(p =>
p.id === id ? { ...p, status: 'waiting', checkedInAt: new Date().toISOString() } : p
));
};
const callNextPatient = () => {
const nextPatient = patients.find(p => p.status === 'waiting');
if (nextPatient) {
setPatients(patients.map(p =>
p.id === nextPatient.id ? { ...p, status: 'in-consultation', calledAt: new Date().toISOString() } : p
));
}
};
const completeConsultation = (id) => {
setPatients(patients.map(p =>
p.id === id ? { ...p, status: 'completed', completedAt: new Date().toISOString() } : p
));
};
const sendReminder = (patient) => {
alert(`Reminder sent to ${patient.name} at ${patient.phone}\n\n"Your appointment is scheduled for ${patient.appointmentTime}. Please arrive 10 minutes early."`);
};
const deletePatient = (id) => {
setPatients(patients.filter(p => p.id !== id));
};
const getStatusColor = (status) => {
switch(status) {
case 'scheduled': return 'bg-gradient-to-r from-blue-500 to-cyan-500 text-white';
case 'waiting': return 'bg-gradient-to-r from-amber-500 to-orange-500 text-white';
case 'in-consultation': return 'bg-gradient-to-r from-emerald-500 to-teal-500 text-white';
case 'completed': return 'bg-gradient-to-r from-slate-400 to-slate-500 text-white';
default: return 'bg-gradient-to-r from-slate-400 to-slate-500 text-white';
}
};
const getStatusIcon = (status) => {
switch(status) {
case 'scheduled': return
Real-time patient flow management
Manage today's appointments
No patients scheduled today
{waitingPatients.length} patients waiting
No patients waiting