import { useState } from 'react'; import { Settings, Layout, Grid, Columns, Save, RotateCcw, Eye, EyeOff, GripVertical } from 'lucide-react'; import type { DashboardConfig, TabConfig, LayoutMode, LayoutPreset } from '@/types'; interface DashboardCustomizerProps { config: DashboardConfig; onConfigChange: (config: DashboardConfig) => void; onSavePreset: (name: string, description: string) => void; onLoadPreset: (presetId: string) => void; onResetToDefault: () => void; } const DEFAULT_PRESETS: LayoutPreset[] = [ { id: 'trading-focus', name: 'Trading Focus', description: 'Optimized for active trading with chart and controls prominent', mode: 'grid', tabs: [], }, { id: 'analysis-focus', name: 'Analysis Focus', description: 'Full-screen analytics and AI insights', mode: 'tabs', tabs: [], }, { id: 'news-focus', name: 'News Focus', description: 'News and market updates at the forefront', mode: 'split', tabs: [], }, { id: 'balanced', name: 'Balanced View', description: 'Equal emphasis on all components', mode: 'grid', tabs: [], }, ]; export default function DashboardCustomizer({ config, onConfigChange, onSavePreset, onLoadPreset, onResetToDefault, }: DashboardCustomizerProps) { const [isOpen, setIsOpen] = useState(false); const [activeTab, setActiveTab] = useState<'layout' | 'tabs' | 'presets'>('layout'); const [draggedTab, setDraggedTab] = useState(null); const [presetName, setPresetName] = useState(''); const [presetDescription, setPresetDescription] = useState(''); const handleLayoutModeChange = (mode: LayoutMode) => { onConfigChange({ ...config, mode }); }; const handleTabToggle = (tabId: string) => { const updatedTabs = config.tabs.map((tab) => tab.id === tabId ? { ...tab, visible: !tab.visible } : tab ); onConfigChange({ ...config, tabs: updatedTabs }); }; const handleTabPin = (tabId: string) => { const updatedTabs = config.tabs.map((tab) => tab.id === tabId ? { ...tab, pinned: !tab.pinned } : tab ); onConfigChange({ ...config, tabs: updatedTabs }); }; const handleTabSizeChange = (tabId: string, size: TabConfig['size']) => { const updatedTabs = config.tabs.map((tab) => tab.id === tabId ? { ...tab, size } : tab ); onConfigChange({ ...config, tabs: updatedTabs }); }; const handleDragStart = (tab: TabConfig) => { setDraggedTab(tab); }; const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); }; const handleDrop = (targetTab: TabConfig) => { if (!draggedTab) return; const updatedTabs = [...config.tabs]; const draggedIndex = updatedTabs.findIndex((t) => t.id === draggedTab.id); const targetIndex = updatedTabs.findIndex((t) => t.id === targetTab.id); if (draggedIndex !== -1 && targetIndex !== -1) { updatedTabs.splice(draggedIndex, 1); updatedTabs.splice(targetIndex, 0, draggedTab); // Update order numbers const reorderedTabs = updatedTabs.map((tab, index) => ({ ...tab, order: index, })); onConfigChange({ ...config, tabs: reorderedTabs }); } setDraggedTab(null); }; const handleSavePreset = () => { if (presetName.trim()) { onSavePreset(presetName, presetDescription); setPresetName(''); setPresetDescription(''); setActiveTab('presets'); } }; const allPresets = [...DEFAULT_PRESETS, ...config.customPresets]; if (!isOpen) { return ( ); } return (
{/* Header */}

Dashboard Customization

Personalize your trading interface

{/* Tabs */}
{/* Content */}
{activeTab === 'layout' && (

Choose Layout Mode

)} {activeTab === 'tabs' && (

Manage Tabs

Drag to reorder, toggle visibility

{config.tabs .sort((a, b) => a.order - b.order) .map((tab) => (
handleDragStart(tab)} onDragOver={handleDragOver} onDrop={() => handleDrop(tab)} className={`p-4 rounded-lg border-2 transition-all cursor-move ${ tab.visible ? 'border-gray-700 bg-dark-hover' : 'border-gray-800 bg-gray-900/50 opacity-60' }`} >
{tab.label}
Order: {tab.order + 1}
{/* Size selector */} {/* Pin button */} {/* Visibility toggle */}
))}
)} {activeTab === 'presets' && (

Quick Presets

{allPresets.map((preset) => ( ))}

Save Current Layout

setPresetName(e.target.value)} className="w-full px-4 py-2 bg-dark-bg border border-gray-700 rounded-lg focus:border-gold-500 focus:outline-none" />