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 total = currentData.length; const maxStartIndex = Math.max(total - visibleCount, 0); const clampedStartIndex = Math.min(startIndex, maxStartIndex); const handleTabChange = (_: React.MouseEvent, newTab: string | null) => { if (newTab !== null) setActiveTab(newTab); }; const canGoLeft = clampedStartIndex > 0; const canGoRight = clampedStartIndex < maxStartIndex; const handlePrev = () => { if (!canGoLeft) return; setStartIndex((prev) => Math.max(prev - visibleCount, 0)); }; const handleNext = () => { if (!canGoRight) return; setStartIndex((prev) => { const next = prev + visibleCount; return Math.min(next, maxStartIndex); }); }; 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 )} ); }