"use client" import { ChevronUp, ChevronDown, Settings } from "lucide-react" import { memo, useEffect, useState } from "react" import type { LegendProps } from "./types" const setCookie = (name: string, value: string, days = 365) => { if (typeof document === "undefined") return const expires = new Date() expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000) document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=/` } const getCookie = (name: string): string | null => { if (typeof document === "undefined") return null const nameEQ = `${name}=` const ca = document.cookie.split(";") for (let i = 0; i < ca.length; i++) { let c = ca[i] if (!c) continue while (c.charAt(0) === " ") c = c.substring(1, c.length) if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length) } return null } // Toggle switch component function Toggle({ enabled, onChange }: { enabled: boolean; onChange: (v: boolean) => void }) { return ( ) } export const Legend = memo(function Legend({ id, nodes = [], edges = [], isLoading = false, }: LegendProps) { const [isExpanded, setIsExpanded] = useState(false) const [isInitialized, setIsInitialized] = useState(false) const [connectionsExpanded, setConnectionsExpanded] = useState(true) // Toggle states for filtering const [showDocMemory, setShowDocMemory] = useState(true) const [showDocSimilarity, setShowDocSimilarity] = useState(true) const [showUpdates, setShowUpdates] = useState(false) const [showExtends, setShowExtends] = useState(true) const [showInferences, setShowInferences] = useState(false) const [showStrong, setShowStrong] = useState(true) const [showWeak, setShowWeak] = useState(true) useEffect(() => { if (!isInitialized) { const savedState = getCookie("legendCollapsed") if (savedState === "false") { setIsExpanded(true) } else { setIsExpanded(false) } setIsInitialized(true) } }, [isInitialized]) const handleToggleExpanded = () => { const newExpanded = !isExpanded setIsExpanded(newExpanded) setCookie("legendCollapsed", newExpanded ? "false" : "true") } const memoryCount = nodes.filter((n) => n.type === "memory").length const documentCount = nodes.filter((n) => n.type === "document").length const connectionCount = edges.length return ( <> {/* Settings button - Bottom right */} {/* Legend - Positioned at bottom left */}