"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useState } from "react"; import { Settings, RefreshCw, LogOut, Compass, X, Radio, Calendar, } from "lucide-react"; import { cn } from "@/utils/cn"; import { api } from "@/lib/api"; import { useAuth } from "@/lib/auth-context"; import { useToast } from "@/lib/toast-context"; import Image from "next/image"; interface MobileSidebarProps { isOpen: boolean; onClose: () => void; } export function MobileSidebar({ isOpen, onClose }: MobileSidebarProps) { const pathname = usePathname(); const { logout } = useAuth(); const { toast } = useToast(); const [isSyncing, setIsSyncing] = useState(false); // Close on route change useEffect(() => { onClose(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [pathname]); // Handle library sync const handleSync = async () => { if (isSyncing) return; try { setIsSyncing(true); await api.scanLibrary(); window.dispatchEvent(new CustomEvent("notifications-changed")); onClose(); } catch (error) { console.error("Failed to sync library:", error); toast.error("Failed to start scan. Please try again."); } finally { setTimeout(() => setIsSyncing(false), 2000); } }; // Handle logout const handleLogout = async () => { try { await logout(); toast.success("Logged out successfully"); onClose(); } catch (error) { console.error("Logout error:", error); toast.error("Failed to logout"); } }; if (!isOpen) return null; return ( <> {/* Backdrop */}