import React from 'react';
import './Calendar.scss';
import {dateName, Day, decadeNames, frIsLeap, frJDN, jdnGregorian, jdnLongCount, Month, monthName} from './dates';
type MonthProps = {
year: number;
month: Month;
};
type DateProps = MonthProps & {
day: Day;
};
export type CalendarProps = MonthProps & {
todayJDN: number;
onSwitch?: (year: number, month: Month) => void,
};
type CalendarState = {};
function DecadeName({name}: { name: string }): JSX.Element {
return
{name}
;
}
function DayDetail({jdn}: { jdn: number }): JSX.Element {
return
{jdnGregorian(jdn).toDateString()}
{jdnLongCount(jdn)}
;
}
function NormalDay({year, month, day, todayJDN}: DateProps & { todayJDN: number }): JSX.Element {
const jdn = frJDN(year, month, day);
return
{day}
{decadeNames[(day - 1) % 10]}
;
}
function NormalMonth({year, month, todayJDN}: MonthProps & { todayJDN: number }): JSX.Element {
const decadeHeads = decadeNames.map(name => );
return
{decadeHeads}
{
Array.from(Array(3).keys()).map(i =>
{
Array.from(Array(10).keys()).map(j => <>
{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: number, todayJDN: number}): JSX.Element {
return {
Array.from(Array(frIsLeap(year) ? 6 : 5).keys()).map(i => <>
{i % 2 === 1 && }
>)
} ;
}
export class Calendar extends React.Component {
private goToNormalized(year: number, month: number) {
if (month < 1) {
--year;
month += 13;
}
if (month > 13) {
++year;
month -= 13;
}
this.props.onSwitch && this.props.onSwitch(year, month as Month);
}
prevYear() {
this.goToNormalized(this.props.year - 1, this.props.month);
}
prevMonth() {
this.goToNormalized(this.props.year, this.props.month - 1);
}
nextYear() {
this.goToNormalized(this.props.year + 1, this.props.month);
}
nextMonth() {
this.goToNormalized(this.props.year, this.props.month + 1);
}
render(): JSX.Element {
return
{this.props.month < 13 && monthName(this.props.month)} {this.props.year}
{this.props.month < 13 &&
}
{this.props.month === 13 && }
;
}
}