import React, { useState } from "react"; import { Link, useLocation } from "react-router"; import { cn } from "~/lib/utils"; import { InogenLogo } from "~/components/ui/brand-logo"; import { useAuth } from "~/contexts/auth-context"; import { GalleryVerticalEnd, LayoutDashboard, FolderOpen, Users, BarChart3, Settings, ChevronLeft, ChevronDown, FileText, Calendar, Bell, User, Database, Shield, HelpCircle, LogOut, ChevronRight, Refrigerator, } from "lucide-react"; import { FolderKanban, Box, Package, Workflow, MonitorSmartphone, Leaf, Building2, Globe, Lightbulb, Star, } from "lucide-react"; interface SidebarProps { isCollapsed?: boolean; onToggleCollapse?: () => void; className?: string; } interface MenuItem { id: string; label: string; icon: React.ComponentType<{ className?: string }>; href?: string; children?: MenuItem[]; badge?: string | number; } const menuItems: MenuItem[] = [ { id: "dashboard", label: "صفحه اصلی", icon: LayoutDashboard, href: "/dashboard", }, { id: "project-management", label: "مدیریت اجرای پروژه‌ها", icon: FolderKanban, href: "/dashboard/project-management", }, { id: "innovation-basket", label: "سبد فناوری و نوآوری", icon: Box, children: [ { id: "product-innovation", label: "نوآوری در محصول", icon: Package, href: "/dashboard/innovation-basket/product-innovation", }, { id: "process-innovation", label: "نوآوری در فرآیند", icon: Workflow, href: "/dashboard/innovation-basket/process-innovation", }, { id: "digital-innovation", label: "نوآوری دیجیتال", icon: MonitorSmartphone, href: "/dashboard/innovation-basket/digital-innovation", }, { id: "green-innovation", label: "نوآوری سبز", icon: Leaf, href: "/dashboard/innovation-basket/green-innovation", }, { id: "internal-innovation", label: "نوآوری ساخت داخل", icon: Building2, href: "/dashboard/innovation-basket/internal-innovation", }, ], }, { id: "ecosystem", label: "زیست بوم فناوری و نوآوری", icon: Globe, href: "/dashboard/ecosystem", }, { id: "ideas", label: "ایده‌های فناوری و نوآوری", icon: Lightbulb, href: "/dashboard/ideas", }, { id: "top-innovations", label: "نوآور برتر", icon: Star, href: "/dashboard/top-innovations", }, ]; const bottomMenuItems: MenuItem[] = [ { id: "settings", label: "تنظیمات", icon: Settings, href: "/dashboard/settings", }, { id: "logout", label: "خروج", icon: LogOut, href: "#", }, ]; export function Sidebar({ isCollapsed = false, onToggleCollapse, className, }: SidebarProps) { const location = useLocation(); const [expandedItems, setExpandedItems] = useState([]); const { logout } = useAuth(); const toggleExpanded = (itemId: string) => { setExpandedItems((prev) => prev.includes(itemId) ? prev.filter((id) => id !== itemId) : [...prev, itemId], ); }; const isActiveRoute = (href?: string, children?: MenuItem[]) => { if (href && location.pathname === href) return true; if (children) { return children.some( (child) => child.href && location.pathname === child.href, ); } return false; }; const renderMenuItem = (item: MenuItem, level = 0) => { const isActive = isActiveRoute(item.href, item.children); const isExpanded = expandedItems.includes(item.id); const hasChildren = item.children && item.children.length > 0; const ItemIcon = item.icon; const handleClick = () => { if (item.id === "logout") { logout(); } else if (hasChildren) { toggleExpanded(item.id); } }; const menuItemContent = (
{!isCollapsed && ( {item.label} )}
{!isCollapsed && (
{item.badge && ( {item.badge} )} {hasChildren && ( )}
)}
); return (
{item.href && item.id !== "logout" ? ( {menuItemContent} ) : ( )} {/* Submenu */} {hasChildren && isExpanded && !isCollapsed && (
{item.children?.map((child) => renderMenuItem(child, level + 1))}
)} {/* Tooltip for collapsed state */} {isCollapsed && level === 0 && (
{item.label}
)}
); }; return (
{/* Header */}
{!isCollapsed ? (
سیستم اینوژن
نسخه ۰.۱
) : (
)}
{/* Main Menu */}
{/* Bottom Menu */}
{/* Collapse Toggle */} {onToggleCollapse && (
)}
); } export default Sidebar;