'use client'; import React, { useState } from 'react'; import { DragDropContext, Droppable, Draggable, DropResult } from 'react-beautiful-dnd'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Switch } from '@/components/ui/switch'; import { Label } from '@/components/ui/label'; import { Badge } from '@/components/ui/badge'; import { GripVertical, Eye, EyeOff, Download, Upload, RotateCcw } from 'lucide-react'; import { useSidebarLayout, SidebarItem } from '@/hooks/use-sidebar-layout'; import { Input } from '@/components/ui/input'; import { useToast } from '@/hooks/use-toast'; export function SidebarCustomizer() { const { settings, updateItemOrder, toggleItemVisibility, updateShortcuts, updateShowIcons, exportSettings, importSettings, resetToDefaults } = useSidebarLayout(); const { toast } = useToast(); const [dragEnabled, setDragEnabled] = useState(false); const handleDragEnd = (result: DropResult) => { if (!result.destination) return; const items = Array.from(settings.items); const [reorderedItem] = items.splice(result.source.index, 1); items.splice(result.destination.index, 0, reorderedItem); updateItemOrder(items); }; const handleFileImport = async (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (!file) return; try { await importSettings(file); toast({ title: "Settings imported", description: "Your sidebar settings have been imported successfully.", }); } catch (error) { toast({ title: "Import failed", description: "Failed to import settings. Please check the file format.", variant: "destructive", }); } // Reset the input event.target.value = ''; }; const handleExport = () => { exportSettings(); toast({ title: "Settings exported", description: "Your settings have been downloaded as a JSON file.", }); }; const handleReset = () => { resetToDefaults(); toast({ title: "Settings reset", description: "Sidebar settings have been reset to defaults.", }); }; const getSidebarIcon = (iconId: string) => { const iconMap: Record = { search: ( ), home: ( ), queue: ( ), radio: ( ), artists: ( ), albums: ( ), playlists: ( ), favorites: ( ), browse: ( ), songs: ( ), history: ( ), settings: ( ), }; return iconMap[iconId] || iconMap.home; }; return (
{/* Global Settings */} Sidebar Settings Customize your sidebar appearance and behavior
{/* Item Management */} Sidebar Items Drag to reorder items and toggle visibility
{(provided) => (
{settings.items.map((item, index) => ( {(provided, snapshot) => (
{settings.showIcons && getSidebarIcon(item.icon)} {item.label} {!item.visible && Hidden}
)}
))} {provided.placeholder}
)}
{/* Import/Export */} Settings Management Export, import, or reset your settings
); }