"use client"; import React, { useState, useEffect } from 'react'; import { BarChart3, MessageSquare, Users, ShoppingCart, Package, Settings, Search, Grid, Bell, Calendar, LayoutDashboard, Wallet, Building2, Cpu, Utensils, LogOut } from 'lucide-react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { deleteCookie, getCookie } from 'cookies-next'; import styles from './page.module.css'; // Restaurant-focused modules only const apps = [ { id: 'restaurant', name: 'Restaurant', icon: , color: '#F1C40F' }, { id: 'pos', name: 'POS', icon: , color: '#27AE60' }, { id: 'inventory', name: 'Inventory', icon: , color: '#786FA6' }, { id: 'accounting', name: 'Accounting', icon: , color: '#546DE5' }, { id: 'calendar', name: 'Calendar', icon: , color: '#017E84' }, { id: 'settings', name: 'Settings', icon: , color: '#7F8C8D' }, ]; export default function Home() { const [search, setSearch] = useState(''); const [user, setUser] = useState<{ id: string; name: string; role: string; email: string } | null>(null); const [loading, setLoading] = useState(true); const router = useRouter(); useEffect(() => { const checkAuth = async () => { const token = getCookie('auth_token'); if (!token) { setUser(null); setLoading(false); return; } try { const res = await fetch('http://localhost:5000/api/auth/me', { headers: { 'Authorization': `Bearer ${token}` } }); const data = await res.json(); if (res.ok) { setUser(data); } else { deleteCookie('auth_token'); setUser(null); } } catch (err) { setUser(null); } finally { setLoading(false); } }; checkAuth(); }, []); const handleLogout = () => { deleteCookie('auth_token'); localStorage.removeItem('user'); setUser(null); router.push('/auth/login'); }; const filteredApps = apps.filter(app => { const matchesSearch = app.name.toLowerCase().includes(search.toLowerCase()); if (!matchesSearch) return false; if (loading) return true; if (!user) return true; // Show all for guests (landing page feel) if (user.role === 'admin') return true; const rolePermissions: Record = { 'waiter': ['POS', 'Restaurant', 'Calendar'], 'cashier': ['POS', 'Accounting', 'Calendar'], 'manager': ['Restaurant', 'POS', 'Inventory', 'Accounting', 'Calendar', 'Settings'], }; const allowedApps = rolePermissions[user.role as keyof typeof rolePermissions] || []; return allowedApps.includes(app.name); }); return ( {/* O */} Dine360 setSearch(e.target.value)} /> {user ? ( {user.name.substring(0, 2).toUpperCase()} ) : ( Login )} {filteredApps.map((app, index) => { const content = ( {app.icon} {app.name} ); return ( {content} ); })} ); }