import { useState, useEffect } from "react"; import type { ReactNode } from "react"; import { ChevronLeft, ChevronRight, ChevronDown, ChevronUp } from "lucide-react"; import { Button } from "~/components/ui/button"; import { cn } from "~/lib/utils"; interface DraftSidebarProps { collapsed: boolean; onCollapsedChange: (collapsed: boolean) => void; queueSection: ReactNode; participantsSection: ReactNode; className?: string; } export function DraftSidebar({ collapsed, onCollapsedChange, queueSection, participantsSection, className, }: DraftSidebarProps) { // Track which sections are expanded // At least one must be expanded at all times const [queueExpanded, setQueueExpanded] = useState(() => { if (typeof window === "undefined") return true; const stored = localStorage.getItem("draftSidebarQueueExpanded"); return stored !== null ? JSON.parse(stored) : true; }); const [participantsExpanded, setParticipantsExpanded] = useState(() => { if (typeof window === "undefined") return true; const stored = localStorage.getItem("draftSidebarParticipantsExpanded"); return stored !== null ? JSON.parse(stored) : true; }); // Persist section states to localStorage useEffect(() => { if (typeof window !== "undefined") { localStorage.setItem( "draftSidebarQueueExpanded", JSON.stringify(queueExpanded) ); } }, [queueExpanded]); useEffect(() => { if (typeof window !== "undefined") { localStorage.setItem( "draftSidebarParticipantsExpanded", JSON.stringify(participantsExpanded) ); } }, [participantsExpanded]); const toggleQueueSection = () => { // Prevent collapsing if it's the only expanded section if (queueExpanded && !participantsExpanded) { return; } setQueueExpanded(!queueExpanded); }; const toggleParticipantsSection = () => { // Prevent collapsing if it's the only expanded section if (participantsExpanded && !queueExpanded) { return; } setParticipantsExpanded(!participantsExpanded); }; // Calculate flex sizes for sections const queueFlexSize = queueExpanded && participantsExpanded ? "1" : queueExpanded ? "1" : "0"; const participantsFlexSize = queueExpanded && participantsExpanded ? "1" : participantsExpanded ? "1" : "0"; if (collapsed) { return ( ); } return ( <> {/* Mobile backdrop */}
onCollapsedChange(true)} aria-label="Close sidebar" />
{/* Collapse button */}
{/* Queue Section */}
{queueExpanded && (
{queueSection}
)}
{/* Available Participants Section */}
{participantsExpanded && (
{participantsSection}
)}
); }