"use client" import { useState, useEffect } from "react" import Link from "next/link" import { usePathname } from "next/navigation" import { LayoutDashboard, Building2, Users, CreditCard, Wrench, FileText, Receipt, Settings, LogOut, X, Menu, ChevronRight, Zap, Sparkles, Bot, BarChart3, Hammer, ClipboardList, PanelLeftClose, PanelLeftOpen, CalendarDays, Activity, Brain, Bell, Palette, KeyRound, Plug, Webhook, ShieldCheck, } from "lucide-react" import { cn } from "@/lib/utils" import { Logo, LogoMark } from "@/components/shared/logo" import { signOut } from "@/app/actions/auth" import type { Profile } from "@/types" import { initials } from "@/lib/utils" const navItems = [ { label: "Dashboard", href: "/dashboard", icon: LayoutDashboard, section: "main" }, { label: "Properties", href: "/properties", icon: Building2, section: "main" }, { label: "Tenants", href: "/tenants", icon: Users, section: "main" }, { label: "Rent Tracker", href: "/rent", icon: CreditCard, section: "main" }, { label: "Maintenance", href: "/maintenance", icon: Wrench, section: "main" }, { label: "Leases", href: "/leases", icon: FileText, section: "main" }, { label: "Expenses", href: "/expenses", icon: Receipt, section: "main" }, { label: "AI Dashboard", href: "/ai-dashboard", icon: Brain, section: "main" }, { label: "AI Assistant", href: "/ai", icon: Bot, section: "main" }, { label: "Reports", href: "/reports", icon: BarChart3, section: "main" }, { label: "Vendors", href: "/vendors", icon: Hammer, section: "main" }, { label: "Inspections", href: "/inspections", icon: ClipboardList, section: "main" }, { label: "Calendar", href: "/calendar", icon: CalendarDays, section: "main" }, { label: "Activity", href: "/activity", icon: Activity, section: "main" }, { label: "AI Insights", href: "/recommendations", icon: Zap, section: "main" }, { label: "AI Impact", href: "/impact", icon: Sparkles, section: "main" }, { label: "Predictions", href: "/predictions", icon: BarChart3, section: "main" }, { label: "Follow-ups", href: "/follow-ups", icon: Bell, section: "main" }, ] const planConfig: Record = { starter: { label: "Starter", color: "text-white/50", bg: "bg-white/5", border: "border-white/10" }, pro: { label: "Pro", color: "text-indigo-300", bg: "bg-indigo-500/10", border: "border-indigo-500/20" }, landlord: { label: "Landlord", color: "text-violet-300", bg: "bg-violet-500/10", border: "border-violet-500/20" }, lifetime: { label: "Lifetime", color: "text-amber-300", bg: "bg-amber-500/10", border: "border-amber-500/20" }, } interface SidebarProps { profile: Profile | null; isAdmin?: boolean } function NavContent({ profile, collapsed, onClose, isAdmin, }: { profile: Profile | null collapsed?: boolean onClose?: () => void isAdmin?: boolean }) { const pathname = usePathname() function isActive(href: string) { if (href === "/dashboard") return pathname === "/dashboard" return pathname.startsWith(href) } const plan = profile?.plan ?? "starter" const pc = planConfig[plan] ?? planConfig.starter return (
{/* Logo */}
{!collapsed && } {collapsed && } {onClose && ( )}
{/* Nav */} {/* Bottom — plan + user */} {!collapsed && (
{pc.label} Plan
{plan === "starter" && ( Upgrade → )}
{profile?.full_name ? initials(profile.full_name) : "?"}

{profile?.full_name ?? "User"}

{profile?.email}

)} {/* Collapsed bottom — just avatar + logout */} {collapsed && (
{profile?.full_name ? initials(profile.full_name) : "?"}
)}
) } export function Sidebar({ profile, isAdmin }: SidebarProps) { const [mobileOpen, setMobileOpen] = useState(false) const [collapsed, setCollapsed] = useState(false) // Persist collapse preference useEffect(() => { const stored = localStorage.getItem("sidebar-collapsed") if (stored === "true") setCollapsed(true) }, []) function toggleCollapse() { const next = !collapsed setCollapsed(next) localStorage.setItem("sidebar-collapsed", String(next)) } return ( <> {/* Desktop sidebar */} {/* Mobile hamburger */}
{/* Mobile drawer */} {mobileOpen && (
setMobileOpen(false)} />
)} ) }