import * as React from "react"; import { Box, Typography, ToggleButtonGroup, ToggleButton, Paper } from "@mui/material"; import { useTheme, alpha } from "@mui/material/styles"; import IconButton from "@mui/material/IconButton"; import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; import ChevronRightIcon from "@mui/icons-material/ChevronRight"; import { ChartDataPoint, HistoryChartProps, } from "./HistoryChart.models"; import { formatDisplay } from "./HistoryChart.utils"; interface ViewProps extends HistoryChartProps { activeTab: string; setActiveTab: (v: string) => void; currentData: ChartDataPoint[]; visibleData: ChartDataPoint[]; maxAmount: number; visibleCount: number; startIndex: number; setStartIndex: React.Dispatch>; activeDataKey: string; } export default function HistoryChartView(props: ViewProps) { const { header, summary, tabs, colorScheme, mode, periodType, selectedPeriodId, comparison, togglePeriodType, setSelectedPeriodId, toggleComparison, activeTab, setActiveTab, currentData, visibleData, maxAmount, visibleCount, startIndex, setStartIndex, activeDataKey, } = props; const theme = useTheme(); const isDark = theme.palette.mode === "dark"; const handleTabChange = (_: React.MouseEvent, newTab: string | null) => { if (newTab !== null) setActiveTab(newTab); }; const canGoLeft = startIndex > 0; const canGoRight = startIndex + visibleCount < currentData.length; const handlePrev = () => { if (canGoLeft) setStartIndex((prev) => prev - visibleCount); }; const handleNext = () => { if (canGoRight) setStartIndex((prev) => prev + visibleCount); }; return ( {header} {summary && ( {summary} )} {tabs.map((tab) => ( {tab} ))} Rolling Calendar Compare {currentData.length > 0 ? ( {canGoLeft && ( )} {visibleData.map((point) => { const currentHeight = (point.amount / maxAmount) * 100; const compareHeight = comparison ? ((point.compare?.amount ?? 0) / maxAmount) * 100 : 0; const isSelected = selectedPeriodId === point.id; const display = formatDisplay(point, activeDataKey, comparison); return ( setSelectedPeriodId(isSelected ? null : point.id) } sx={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", cursor: "pointer", height: "100%" }} > {comparison && ( )} {point.label} {comparison && point.compare && ( {point.compare.label} )} {display} ); })} {canGoRight && ( )} ) : ( No Data Available )} ); }