import React from 'react';
import './Calendar.scss';
import {
dateName,
dateRuralName,
decadeNames,
FrenchDay,
FrenchMonth,
frEndYear,
frIsLeap,
frJDN,
frStartYear,
jdnFrench,
monthName,
} from '@common/french';
import {jdnDate} from '@common/gregorian';
import {jdnLongCount} from '@common/longCount';
import {useMobileTooltipProps} from '@common/ui/MobileTooltip';
import {MonthBasedCalendar} from '@common/ui/MonthBasedCalendar';
type FrenchYear = number;
type MonthProps = {
year: FrenchYear;
month: FrenchMonth;
};
type DateProps = MonthProps & {
day: FrenchDay;
};
function DecadeName({name}: { name: string }): JSX.Element {
return
{name}
;
}
function DayDetail({jdn}: { jdn: number }): JSX.Element {
return
{jdnDate(jdn).toDateString()}
{jdnLongCount(jdn)?.join('.')}
;
}
function NormalDay({year, month, day, todayJDN}: DateProps & { todayJDN: number }): JSX.Element {
const jdn = frJDN(year, month, day);
const rural = dateRuralName(month, day)!;
const mobile = useMobileTooltipProps();
return
{day}
{decadeNames[(day - 1) % 10]}
;
}
function NormalMonth({year, month, todayJDN}: MonthProps & { todayJDN: number }): JSX.Element {
const decadeHeads = decadeNames.map((name, i) => );
return
{decadeHeads}
{
Array.from(Array(3).keys()).map(i =>
{
Array.from(Array(10).keys()).map(j =>
{j % 2 === 1 && }
{j === 4 && }
)
}
)
}
;
}
function ComplementaryDay({year, month, day, todayJDN}: DateProps & { todayJDN: number }): JSX.Element {
const jdn = frJDN(year, month, day);
return ;
}
function ComplementaryDays({year, todayJDN}: { year: FrenchYear, todayJDN: number }): JSX.Element {
const leap = frIsLeap(year);
return {
Array.from(Array(6).keys()).map(i =>
{(i < 5 || leap) && }
{i === 5 && !leap && }
{i % 2 === 1 && }
)
}
;
}
export class Calendar extends MonthBasedCalendar {
override parseYear(year: string): FrenchYear {
return +year;
}
override parseMonth(month: string): FrenchMonth {
return +month as FrenchMonth;
}
override yearToString(year: FrenchYear): string {
return year.toString();
}
override monthToString(month: FrenchMonth): string {
return month.toString();
}
private goToNormalized(year: number, month: number) {
while (month < 1) {
--year;
month += 13;
}
while (month > 13) {
++year;
month -= 13;
}
if (year < frStartYear) {
year = frStartYear;
month = 1;
} else if (year > frEndYear) {
year = frEndYear;
month = 13;
}
this.goTo(year, month as FrenchMonth);
}
override prevYear = () => {
this.goToNormalized(this.props.year - 1, this.props.month);
};
override prevMonth = () => {
this.goToNormalized(this.props.year, this.props.month - 1);
};
override nextYear = () => {
this.goToNormalized(this.props.year + 1, this.props.month);
};
override nextMonth = () => {
this.goToNormalized(this.props.year, this.props.month + 1);
};
override isValidYear(year: string): boolean {
return /^-?\d+/.test(year);
}
override jdnLookup(jdn: number): { year: FrenchYear; month: FrenchMonth } {
return jdnFrench(jdn);
}
override monthName(year: FrenchYear, month: FrenchMonth): string {
return month === 13 ? year.toString() : `${monthName(month)} ${year}`;
}
override renderMonthOptions(): JSX.Element[] {
return Array.from(Array(13).keys()).map(i => {
const month = i + 1 as FrenchMonth;
return ;
});
}
override renderBody(): JSX.Element {
if (this.props.month < 13) {
return ;
} else {
return ;
}
}
}