import { useState, useEffect } from 'react';
import { Link, usePage } from '@inertiajs/react';
import { motion, AnimatePresence } from 'framer-motion';
import {
LayoutDashboard, Server, Monitor, Layers, Box, Boxes, Cloud,
Shield, HardDrive, Activity, KeyRound, BookOpen,
Users, Settings, ChevronLeft, ChevronRight, Bell, Search,
LogOut, User, Menu, X, Zap, ChevronDown
} from 'lucide-react';
import { cn, getStatusDot } from '@/lib/utils';
import { Button } from '@/Components/ui/Button';
const ICONS = {
LayoutDashboard, Server, Monitor, Layers, Box, Boxes, Cloud,
Shield, HardDrive, Activity, KeyRound, BookOpen, Users, Settings
};
function NavItem({ item, collapsed, active }) {
const Icon = ICONS[item.icon] ?? Server;
return (
{active && (
)}
{!collapsed && (
{item.name}
)}
{collapsed && (
{item.name}
)}
);
}
export default function AppLayout({ children, title }) {
const { auth, navigation, flash, app } = usePage().props;
const [collapsed, setCollapsed] = useState(false);
const [mobileOpen, setMobileOpen] = useState(false);
const [notifOpen, setNotifOpen] = useState(false);
const currentPath = window.location.pathname;
useEffect(() => {
setMobileOpen(false);
}, [currentPath]);
const isActive = (href) => {
if (href === '/') return currentPath === '/';
return currentPath.startsWith(href);
};
const topNav = navigation?.filter(n => !['acl', 'admin'].includes(n.key)) ?? [];
const adminNav = navigation?.filter(n => ['acl', 'admin'].includes(n.key)) ?? [];
return (
{/* ── Sidebar ─────────────────────────────────────────── */}
{/* Logo */}
{!collapsed && (
{app?.name ?? 'Infra Manager'}
v{app?.version ?? '1.0.0'}
)}
{/* Nav */}
{/* Collapse toggle */}
{/* User */}

{!collapsed && (
{auth?.user?.name}
{auth?.user?.roles?.[0]}
)}
{/* ── Mobile Sidebar ──────────────────────────────────── */}
{mobileOpen && (
<>
setMobileOpen(false)}
/>
{app?.name ?? 'Infra Manager'}
>
)}
{/* ── Main content ────────────────────────────────────── */}
{/* Top Bar */}
{title && (
{title}
)}
{/* Notifications */}
{/* App env badge */}
{app?.env !== 'production' && (
{app?.env?.toUpperCase()}
)}
{/* Flash messages */}
{(flash?.success || flash?.error || flash?.warning) && (
{flash?.success || flash?.error || flash?.warning}
)}
{/* Page Content */}
{children}
);
}