import { ReactNode, useEffect, useState } from 'react';
import { useNavigate, useLocation } from 'react-router-dom';
import { useAuthStore } from '../store/authStore';
import { api } from '../lib/api';
import {
LayoutDashboard,
Store,
Building2,
FolderOpen,
Package,
Target,
TrendingUp,
Wrench,
Activity,
Clock,
Calendar,
Shield,
FileText,
Settings,
LogOut,
CheckCircle,
Key,
Users
} from 'lucide-react';
interface LayoutProps {
children: ReactNode;
}
interface VersionInfo {
build_version: string;
git_sha: string;
build_time: string;
image_tag: string;
}
interface NavLinkProps {
to: string;
icon: ReactNode;
label: string;
isActive: boolean;
}
function NavLink({ to, icon, label, isActive }: NavLinkProps) {
return (
{icon}
{label}
);
}
interface NavSectionProps {
title: string;
children: ReactNode;
}
function NavSection({ title, children }: NavSectionProps) {
return (
);
}
export function Layout({ children }: LayoutProps) {
const navigate = useNavigate();
const location = useLocation();
const { user, logout } = useAuthStore();
const [versionInfo, setVersionInfo] = useState(null);
useEffect(() => {
const fetchVersion = async () => {
try {
const data = await api.getVersion();
setVersionInfo(data);
} catch (error) {
console.error('Failed to fetch version info:', error);
}
};
fetchVersion();
}, []);
const handleLogout = () => {
logout();
navigate('/login');
};
const isActive = (path: string, exact = true) => {
if (exact) {
return location.pathname === path;
}
return location.pathname.startsWith(path);
};
return (
{/* Sidebar */}
{/* Logo/Brand */}
CannaIQ
{user?.email}
{versionInfo && (
{versionInfo.build_version} ({versionInfo.git_sha.slice(0, 7)})
)}
{/* Navigation */}
{/* Logout */}
{/* Version Footer */}
{versionInfo && (
{versionInfo.build_version} ({versionInfo.git_sha.slice(0, 7)})
{versionInfo.image_tag}
)}
{/* Main Content */}
);
}