import * as React from "react"; import { Box, Container, Grid, Typography, ToggleButton, ToggleButtonGroup } from "@mui/material"; import { useTheme, alpha } from "@mui/material/styles"; import { DashboardProps, DashboardState } from "./Dashboard.models"; interface ViewProps extends DashboardProps { state: DashboardState; setState: React.Dispatch>; } export default function DashboardView({ config, data, latest, state, setState, onModeChange }: ViewProps) { const theme = useTheme(); const themeMode = theme.palette.mode; const { mode, periodType, comparison } = state; // Resolve colors with fallbacks const colors = React.useMemo(() => { const palette = config.style?.palette?.[mode]; const modeColors = palette ? palette[themeMode] : null; if (modeColors) { return { primary: modeColors.primary, light: modeColors.background || alpha(modeColors.primary, 0.1), text: modeColors.text || (themeMode === 'light' ? theme.palette.text.primary : '#fff') }; } // Fallback to standard theme colors const themeColor = mode === 'expense' ? theme.palette.error : theme.palette.success; return { primary: themeColor.main, light: alpha(themeColor.main, themeMode === 'light' ? 0.08 : 0.15), text: themeColor.main }; }, [config.style?.palette, mode, themeMode, theme.palette]); const handleModeChange = (_: any, newMode: any) => { if (newMode && onModeChange) { onModeChange(newMode); setState(prev => ({ ...prev, mode: newMode })); } }; return ( Expenses Income {config.sections.map((section) => { const Component = section.component; return ( {section.title && !section.isList && ( {section.title} )} {section.isList ? ( {section.title && ( {section.title} )} {(data[section.dataKey || ""] || []).map((item: any, idx: number) => ( ))} ) : ( setState(prev => ({ ...prev, periodType: p }))} comparison={comparison} setComparison={(c: any) => setState(prev => ({ ...prev, comparison: c }))} /> )} ); })} ); }