import { ButtonBase, Stack, Typography, TypographyProps } from "@mui/material"; import React, { useState } from "react"; import { format } from "date-fns"; import { DateType, EthiopianDate } from "./util/EthiopianDateUtils"; import { useEtLocalization } from "./EtLocalizationProvider"; type EtDateViewerProps = { date: Date; initialDateType?: DateType; disableSwitcher?: boolean; showTime?: boolean; } & TypographyProps; const EtDateViewer: React.FC = ({ date, initialDateType, disableSwitcher, showTime, ...props }) => { const { localType, getLocalMonthName } = useEtLocalization(); const [dateType, setDateType] = useState( initialDateType ?? localType ); const handleDateTypeChange = (event: React.MouseEvent) => { event.stopPropagation(); const newDateType = dateType === "GC" ? localType : "GC"; setDateType(newDateType ?? "GC"); }; const { disableSwitcher: disableSwitch } = useEtLocalization(); return ( {!disableSwitcher && !disableSwitch && ( {dateType === "CUSTOM" ? "CU" : dateType} )} {showTime ? dateType === "GC" ? `${format(date, "MMM dd/yyyy")} ${format(date, "hh:mm a")}` : EthiopianDate.formatEtDate( EthiopianDate.toEth(date), dateType ?? localType, getLocalMonthName, date.getTime() ) : dateType === "GC" ? format(date, "MMM dd/yyyy") : EthiopianDate.formatEtDate( EthiopianDate.toEth(date), dateType ?? localType, getLocalMonthName )} ); }; export default EtDateViewer;