import { useState, type ReactNode } from "react"; import { Button } from "@/src/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { SubHeader } from "@/src/components/layouts/header"; import { cn } from "@/src/utils/tailwind"; import React from "react"; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger, } from "@/src/components/ui/sheet"; import { useIsMobile } from "@/src/hooks/use-mobile"; import { Separator } from "@/src/components/ui/separator"; import useSessionStorage from "@/src/components/useSessionStorage"; const SidePanelContext = React.createContext<{ showPanel: boolean; setShowPanel: (value: boolean) => void; isMobile: boolean; } | null>(null); const SidePanel = ({ id, children, className, mobileTitle, scrollable = true, }: { id: string; children: ReactNode; className?: string; mobileTitle?: string; scrollable?: boolean; }) => { const [showPanel, setShowPanel] = useSessionStorage( `${id}-showPanel`, true, ); const [isOpen, setIsOpen] = useState(false); const isMobile = useIsMobile(); const contextValue = React.useMemo( () => ({ showPanel, setShowPanel, isMobile, }), [showPanel, setShowPanel, isMobile], ); if (isMobile) { return (
{mobileTitle}
{children}
); } return (
{children}
); }; const SidePanelHeader = ({ children }: { children: ReactNode }) => { const context = React.useContext(SidePanelContext); // Don't throw if we're in mobile mode (no context) if (!context) return null; const { showPanel, setShowPanel } = context; if (!showPanel) { return ( ); } return (
{children}
); }; const SidePanelTitle = ({ children, className, }: { children: ReactNode; className?: string; }) => ; const SidePanelContent = ({ children, className, }: { children: ReactNode; className?: string; }) => { const context = React.useContext(SidePanelContext); if (!context) return children; const { showPanel } = context; if (!showPanel) return null; return (
{children}
); }; export { SidePanel, SidePanelHeader, SidePanelTitle, SidePanelContent };