"use client" import { useState, useEffect, useRef } from "react" import { usePathname } from "next/navigation" import Link from "next/link" import { cn } from "@/lib/utils" import { ChevronsLeft, Layers, Component, PanelTopIcon as PanelTopLeft, ChevronDown } from "lucide-react" import { PercolateLogo } from "./ui/percolate-logo" import { useSidebar } from "@/contexts/sidebar-context" import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" // Fixed border radius for UI components const UI_BORDER_RADIUS = "6px" // Add this function after the imports const getElevation1Shadow = (theme: string) => { return theme === "dark" ? "0 1px 2px 0 rgba(0, 0, 0, 0.3)" : "0 1px 2px 0 rgba(0, 0, 0, 0.05)" } // Foundation items const foundationItems = [ { name: "Color", id: "color" }, { name: "Iconography", id: "iconography" }, { name: "Typography", id: "typography" }, { name: "Spacing", id: "spacing" }, { name: "Elevation", id: "elevation" }, ] // Component items const componentItems = [ { name: "Accordion", id: "accordion" }, { name: "Alert", id: "alerts" }, { name: "Alert Dialog", id: "alert-dialog" }, { name: "Avatar", id: "avatars" }, { name: "Badge", id: "badges" }, { name: "Breadcrumb", id: "breadcrumbs" }, { name: "Button", id: "buttons" }, { name: "Calendar", id: "calendar" }, { name: "Card", id: "cards" }, { name: "Checkbox", id: "checkbox" }, { name: "Collapsible", id: "collapsible" }, { name: "Combobox", id: "combobox" }, { name: "Command", id: "command" }, { name: "Context Menu", id: "context-menu" }, { name: "Dropdown", id: "dropdowns" }, { name: "Form", id: "forms" }, { name: "Hover Card", id: "hover-card" }, { name: "Label", id: "label" }, { name: "Modal", id: "modals" }, { name: "Pagination", id: "pagination" }, { name: "Progress", id: "progress" }, { name: "Scroll Area", id: "scroll-area" }, { name: "Sheet", id: "sheet" }, { name: "Sidebar", id: "sidebar" }, { name: "Skeleton", id: "skeleton" }, { name: "Slider", id: "slider" }, { name: "Switch", id: "switch" }, { name: "Tab", id: "tabs" }, { name: "Table", id: "tables" }, { name: "Top Navigation", id: "top-navigation" }, { name: "Tooltip", id: "tooltips" }, ] // Block items - Updated to include AI Chat Interface const blockItems = [ { name: "AI Chat Interface", id: "ai-chat-interface" }, { name: "Contact Form", id: "contact-form" }, { name: "Data Table", id: "data-table" }, { name: "User Profile", id: "user-profile" }, { name: "Settings Panel", id: "settings-panel" }, { name: "Login", id: "login" }, ] interface SidebarProps { isFirstLoad?: boolean } export function Sidebar({ isFirstLoad = false }: SidebarProps) { const pathname = usePathname() const [mounted, setMounted] = useState(false) const { setSidebarVisible } = useSidebar() const scrollContainerRef = useRef(null) const [openSections, setOpenSections] = useState({ foundation: true, components: true, blocks: true, }) const toggleSection = (section: string) => { setOpenSections((prev) => ({ ...prev, [section]: !prev[section], })) } // Save scroll position to localStorage const saveScrollPosition = () => { if (scrollContainerRef.current) { const scrollTop = scrollContainerRef.current.scrollTop localStorage.setItem("sidebar-scroll-position", scrollTop.toString()) } } // Restore scroll position from localStorage const restoreScrollPosition = () => { if (scrollContainerRef.current) { const savedScrollPosition = localStorage.getItem("sidebar-scroll-position") if (savedScrollPosition) { scrollContainerRef.current.scrollTop = Number.parseInt(savedScrollPosition, 10) } } } // Handle mounting and scroll position restoration useEffect(() => { setMounted(true) // Restore scroll position after a short delay to ensure DOM is ready const timer = setTimeout(() => { restoreScrollPosition() }, 100) return () => clearTimeout(timer) }, []) // Add scroll event listener to save position useEffect(() => { const scrollContainer = scrollContainerRef.current if (!scrollContainer) return const handleScroll = () => { saveScrollPosition() } // Throttle scroll events for better performance let timeoutId: NodeJS.Timeout const throttledHandleScroll = () => { clearTimeout(timeoutId) timeoutId = setTimeout(handleScroll, 100) } scrollContainer.addEventListener("scroll", throttledHandleScroll) return () => { scrollContainer.removeEventListener("scroll", throttledHandleScroll) clearTimeout(timeoutId) } }, [mounted]) // Save scroll position when pathname changes useEffect(() => { saveScrollPosition() }, [pathname]) if (!mounted) { return null } // Get current section from pathname const currentSection = pathname.replace("/", "") || "introduction" return (
{/* Logo and toggle header */}
percolate UI
{/* Scrollable content area that fills the entire height */}
{/* Introduction section */}
{/* Foundation section */} toggleSection("foundation")}>
FOUNDATION
{/* Components section */} toggleSection("components")}>
COMPONENTS
{/* Blocks section */} {blockItems.length > 0 && ( toggleSection("blocks")}>
BLOCKS
)}
) }