import { Grid, Chip, Box } from "@mui/material"; import React, { useContext, useEffect, useRef } from "react"; import { EthiopianDate } from "../util/EthiopianDateUtils"; import { EtDatePickerContext } from "../EtDatePickerContext"; type EthiopianYearListProps = { startYear?: number; yearRange?: number; onYearClick: (year: number) => void; }; const EthiopianYearList: React.FC = ({ startYear, yearRange, onYearClick, }) => { const { disableFuture, disablePast, minDate, maxDate } = useContext(EtDatePickerContext); const CURRENT_YEAR = startYear ?? EthiopianDate.toEth(new Date()).Year; const START_YEAR = minDate ? EthiopianDate.toEth(minDate).Year : CURRENT_YEAR - (yearRange ?? 100); const END_YEAR = maxDate ? EthiopianDate.toEth(maxDate).Year : yearRange ? START_YEAR + yearRange : START_YEAR + 201; const currentYearRef = useRef(null); useEffect(() => { if (currentYearRef.current) { currentYearRef.current.scrollIntoView({ behavior: "auto", block: "center", }); } }, []); const isDisabled = (year: number) => { if (disablePast && year < CURRENT_YEAR) { return true; } if (disableFuture && year > CURRENT_YEAR) { return true; } if (minDate && year < EthiopianDate.toEth(minDate).Year) { return true; } if (maxDate && year > EthiopianDate.toEth(maxDate).Year) { return true; } return false; }; return ( {Array.from( { length: END_YEAR - START_YEAR + 1 }, (_, index) => START_YEAR + index ).map((year) => ( onYearClick(year)} /> ))} ); }; export default EthiopianYearList;