import { useState } from "react"; import { BarChart3, ChevronDown, ChevronLeft, ChevronRight, CloudSun, Droplet, Filter, Gauge, Home, Lightbulb, MonitorDot, Settings, TabletSmartphone, Waves, Wind, } from "lucide-react"; import logo from "../../assets/logo.png"; import type { AppPage } from "../../app/App"; type SidebarProps = { theme: "dark" | "light"; activePage: AppPage; collapsed: boolean; onNavigate: (page: AppPage) => void; onToggleCollapsed: () => void; }; const RADIUS = "rounded-[6px]"; const navigationItems: { label: string; page: AppPage; icon: React.ElementType; }[] = [ { label: "Painel Principal", page: "dashboard", icon: Home }, { label: "Meteorologia", page: "meteo", icon: CloudSun }, { label: "Gráficos Gerais", page: "maincharts", icon: BarChart3 }, { label: "Sinótico", page: "synoptic" , icon: MonitorDot } ]; const climateItems = [ { label: "Iluminação", icon: Lightbulb }, { label: "Ventilação", icon: Wind }, { label: "Gráficos", icon: BarChart3 }, ]; const irrigationItems = [ { label: "Regas", icon: Droplet }, { label: "Filtros de Rega", icon: Filter }, { label: "Consumos", icon: Gauge }, { label: "Drenagem", icon: Waves }, { label: "Gráficos", icon: BarChart3 }, ]; const utilityItems: { label: string; page: AppPage; icon: React.ElementType; }[] = [ { label: "Consola (VNC)", page: "console", icon: TabletSmartphone }, { label: "Configurações", page: "settings", icon: Settings }, ]; export function Sidebar({ theme, activePage, collapsed, onNavigate, onToggleCollapsed, }: SidebarProps) { const isDark = theme === "dark"; const [climateOpen, setClimateOpen] = useState(false); const [irrigationOpen, setIrrigationOpen] = useState(false); const [activeTreeItem, setActiveTreeItem] = useState(null); const handleTreeClick = (key: string) => { setActiveTreeItem(key); if (key === "climate:Gráficos") { onNavigate("climateCharts"); } }; const handleTreeToggle = (section: "climate" | "irrigation") => { if (collapsed) { onToggleCollapsed(); } if (section === "climate") { setClimateOpen((current) => !current); setIrrigationOpen(false); return; } setIrrigationOpen((current) => !current); setClimateOpen(false); }; return ( ); } function TreeSection({ theme, collapsed, label, icon: Icon, open, onToggle, items, sectionKey, activeTreeItem, onItemClick, }: { theme: "dark" | "light"; collapsed: boolean; label: string; icon: React.ElementType; open: boolean; onToggle: () => void; items: { label: string; icon: React.ElementType }[]; sectionKey: string; activeTreeItem: string | null; onItemClick: (key: string) => void; }) { const isDark = theme === "dark"; const hasActiveChild = items.some( (item) => activeTreeItem === `${sectionKey}:${item.label}`, ); return (
{!collapsed && open && (
{items.map((item) => { const SubIcon = item.icon; const key = `${sectionKey}:${item.label}`; const active = activeTreeItem === key; return ( ); })}
)}
); } function SectionLabel({ collapsed, label, }: { collapsed: boolean; label: string; }) { if (collapsed) { return
; } return (

{label}

); } function ActiveIndicator({ isDark }: { isDark: boolean }) { return ( ); } function navButtonClass(isDark: boolean, active: boolean, collapsed: boolean) { const alignment = collapsed ? "justify-center px-0" : "px-4"; if (active) { return isDark ? `relative flex w-full items-center gap-3 ${RADIUS} border border-[#2C3D56] bg-[#131D2F] ${alignment} py-3.5 text-left text-[14px] font-extrabold text-white` : `relative flex w-full items-center gap-3 ${RADIUS} border border-[#CBD5E1] bg-white ${alignment} py-3.5 text-left text-[14px] font-extrabold text-[#0F172A]`; } return isDark ? `relative flex w-full items-center gap-3 ${RADIUS} ${alignment} py-3.5 text-left text-[14px] font-semibold text-[#8EA0BA] transition hover:bg-[#111A2B] hover:text-white` : `relative flex w-full items-center gap-3 ${RADIUS} ${alignment} py-3.5 text-left text-[14px] font-semibold text-slate-600 transition hover:bg-white hover:text-[#0F172A]`; } function navIconClass(isDark: boolean, active: boolean) { if (active) { return isDark ? "h-5 w-5 shrink-0 text-[#4FD1C5]" : "h-5 w-5 shrink-0 text-[#0F766E]"; } return isDark ? "h-5 w-5 shrink-0 text-[#6F819B]" : "h-5 w-5 shrink-0 text-slate-500"; }