import { generateCalendarGrid, generateMonths, generateWeekDays, generateYears, getDaysInMonth, getFirstDayOfMonth, getFirstWeekdayOfMonth, } from "./calendar";
describe('getFirstDayOfMonth Function', () => {
    test('should return the correct number of days in a month', () => {
        var _a, _b, _c, _d, _e, _f;
        expect((_a = getFirstDayOfMonth(2023, 1)) === null || _a === void 0 ? void 0 : _a.getDay()).toBe(0);
        expect((_b = getFirstDayOfMonth(2023, 1)) === null || _b === void 0 ? void 0 : _b.getDate()).toBe(1);
        expect((_c = getFirstDayOfMonth(2023, 2)) === null || _c === void 0 ? void 0 : _c.getDay()).toBe(3);
        expect((_d = getFirstDayOfMonth(2023, 2)) === null || _d === void 0 ? void 0 : _d.getDate()).toBe(1);
        expect((_e = getFirstDayOfMonth(2023, 5)) === null || _e === void 0 ? void 0 : _e.getDay()).toBe(1);
        expect((_f = getFirstDayOfMonth(2023, 5)) === null || _f === void 0 ? void 0 : _f.getDate()).toBe(1);
    });
    test('should handle invalid input', () => {
        expect(getFirstDayOfMonth(2023, 0)).toBeUndefined();
        expect(getFirstDayOfMonth(2023, -1)).toBeUndefined();
        expect(getFirstDayOfMonth(2023, 13)).toBeUndefined();
    });
});
describe('getDaysInMonth Function', () => {
    test('should return the correct number of days in a month', () => {
        expect(getDaysInMonth(2023, 1)).toBe(31);
        expect(getDaysInMonth(2023, 2)).toBe(28);
        expect(getDaysInMonth(2020, 2)).toBe(29);
        expect(getDaysInMonth(2023, 4)).toBe(30);
        expect(getDaysInMonth(2023, 5)).toBe(31);
        expect(getDaysInMonth(2023, 11)).toBe(30);
        expect(getDaysInMonth(2023, 12)).toBe(31);
    });
    test('should handle invalid input', () => {
        expect(getDaysInMonth(2023, 0)).toBeUndefined();
        expect(getDaysInMonth(2023, -1)).toBeUndefined();
        expect(getDaysInMonth(-2023, 5)).toBeUndefined();
    });
});
describe('getFirstWeekdayOfMonth Function', () => {
    test('should return the correct first weekday of a month', () => {
        expect(getFirstWeekdayOfMonth(2023, 1)).toBe(7);
        expect(getFirstWeekdayOfMonth(2023, 2)).toBe(3);
        expect(getFirstWeekdayOfMonth(2020, 2)).toBe(6);
        expect(getFirstWeekdayOfMonth(2023, 4)).toBe(6);
    });
    test('should handle invalid input', () => {
        expect(getFirstWeekdayOfMonth(2023, 0)).toBe(1);
        expect(getFirstWeekdayOfMonth(2023, -1)).toBe(1);
        expect(getFirstWeekdayOfMonth(-2023, 5)).toBe(1);
    });
});
describe('generateWeekDays Function', () => {
    test('should generate the correct weekday header', () => {
        const language = 'en';
        const weekdays = generateWeekDays(language);
        expect(weekdays.length).toBe(7);
        expect(weekdays[0].textContent).toBe('Mon');
        expect(weekdays[1].textContent).toBe('Tue');
        expect(weekdays[2].textContent).toBe('Wed');
        expect(weekdays[3].textContent).toBe('Thu');
        expect(weekdays[4].textContent).toBe('Fri');
        expect(weekdays[5].textContent).toBe('Sat');
        expect(weekdays[6].textContent).toBe('Sun');
    });
    test('should generate the correct weekday header in german', () => {
        const language = 'de';
        const weekdays = generateWeekDays(language);
        expect(weekdays.length).toBe(7);
        expect(weekdays[0].textContent).toBe('Mo');
        expect(weekdays[1].textContent).toBe('Di');
        expect(weekdays[2].textContent).toBe('Mi');
        expect(weekdays[3].textContent).toBe('Do');
        expect(weekdays[4].textContent).toBe('Fr');
        expect(weekdays[5].textContent).toBe('Sa');
        expect(weekdays[6].textContent).toBe('So');
    });
    test('should handle invalid language', () => {
        const language = 'xyz';
        const weekdays = generateWeekDays(language);
        expect(weekdays.length).toBe(7);
        expect(weekdays[0].textContent).toBe('Mo');
        expect(weekdays[1].textContent).toBe('Di');
        expect(weekdays[2].textContent).toBe('Mi');
        expect(weekdays[3].textContent).toBe('Do');
        expect(weekdays[4].textContent).toBe('Fr');
        expect(weekdays[5].textContent).toBe('Sa');
        expect(weekdays[6].textContent).toBe('So');
    });
});
describe('generateCalendarGrid Function', () => {
    test('should generate the correct calendar grid for a month starts on a sunday', () => {
        const year = 2023;
        const month = 1;
        const grid = generateCalendarGrid(year, month);
        expect(grid.length).toBe(31);
        expect(grid[0].day).toBe(1);
        expect(grid[grid.length - 1].day).toBe(31);
    });
    test('should generate the correct calendar grid for the year < 1900', () => {
        const year = 1899;
        const month = 1;
        const grid = generateCalendarGrid(year, month);
        expect(grid.length).toBe(31);
        expect(grid[0].day).toBe(1);
        expect(grid[grid.length - 1].day).toBe(31);
    });
    test('should generate the correct calendar grid for the month february', () => {
        const year = 2023;
        const month = 2;
        const grid = generateCalendarGrid(year, month);
        expect(grid.length).toBe(28);
        expect(grid[0].day).toBe(1);
        expect(grid[grid.length - 1].day).toBe(28);
    });
    test('should generate the correct calendar grid for a month starts on a monday', () => {
        const year = 2023;
        const month = 5;
        const grid = generateCalendarGrid(year, month);
        expect(grid.length).toBe(31);
        expect(grid[0].day).toBe(1);
        expect(grid[grid.length - 1].day).toBe(31);
    });
    test('should handle min and max date constraints', () => {
        const year = 2023;
        const month = 1;
        const minDate = '2023-01-15';
        const maxDate = '2023-01-25';
        const grid = generateCalendarGrid(year, month, minDate, maxDate);
        expect(grid[0].disabled).toBe(true);
        expect(grid[13].disabled).toBe(true);
        expect(grid[14].disabled).toBe(false);
        expect(grid[24].disabled).toBe(false);
        expect(grid[25].disabled).toBe(true);
        expect(grid[30].disabled).toBe(true);
    });
    test('should handle allowed dates callback', () => {
        const year = 2023;
        const month = 1;
        const allowedDates = (isoDate) => isoDate.endsWith('15');
        const grid = generateCalendarGrid(year, month, undefined, undefined, allowedDates);
        expect(grid[0].disabled).toBe(true);
        expect(grid[13].disabled).toBe(true);
        expect(grid[14].disabled).toBe(false);
        expect(grid[15].disabled).toBe(true);
        expect(grid[30].disabled).toBe(true);
    });
});
describe('generateMonths Function', () => {
    test('should generate the correct months in german short and long', () => {
        const months = generateMonths('de');
        expect(months.length).toBe(12);
        expect(months[0].value).toBe(1);
        expect(months[0].label).toBe('Januar');
        expect(months[0].disabled).toBe(false);
    });
    test('should generate the correct months in italian short and long', () => {
        const months = generateMonths('it');
        expect(months.length).toBe(12);
        expect(months[0].value).toBe(1);
        expect(months[0].label).toBe('gennaio');
        expect(months[0].disabled).toBe(false);
    });
    test('should generate the correct months in english with min', () => {
        const months = generateMonths('it', 2023, '2023-03-12', '2023-03-12');
        expect(months.length).toBe(12);
        expect(months[0].value).toBe(1);
        expect(months[0].label).toBe('gennaio');
        expect(months[0].disabled).toBe(true);
        expect(months[1].disabled).toBe(true);
        expect(months[2].selected).toBe(true);
        expect(months[2].disabled).toBe(false);
        expect(months[3].disabled).toBe(false);
    });
    test('should generate the correct months in english with max', () => {
        const months = generateMonths('it', 2023, undefined, undefined, '2023-03-12');
        expect(months.length).toBe(12);
        expect(months[0].value).toBe(1);
        expect(months[0].label).toBe('gennaio');
        expect(months[0].disabled).toBe(false);
        expect(months[0].selected).toBe(false);
        expect(months[1].disabled).toBe(false);
        expect(months[1].selected).toBe(false);
        expect(months[2].disabled).toBe(false);
        expect(months[2].selected).toBe(false);
        expect(months[3].selected).toBe(false);
        expect(months[3].disabled).toBe(true);
    });
    test('should generate the correct months in italian with min & max', () => {
        const months = generateMonths('it', 2023, undefined, '2023-03-12', '2023-05-12');
        expect(months.length).toBe(12);
        expect(months[0].value).toBe(1);
        expect(months[0].label).toBe('gennaio');
        expect(months[0].disabled).toBe(true);
        expect(months[1].disabled).toBe(true);
        expect(months[2].disabled).toBe(false);
        expect(months[3].disabled).toBe(false);
        expect(months[4].disabled).toBe(false);
        expect(months[5].disabled).toBe(true);
    });
    test('should generate the correct months before min date', () => {
        const months = generateMonths('en', 2023, undefined, '2023-08-08');
        expect(months[0].disabled).toBe(true);
        expect(months[6].disabled).toBe(true);
        expect(months[7].value).toBe(8);
        expect(months[7].disabled).toBe(false);
        expect(months[8].disabled).toBe(false);
        expect(months[10].disabled).toBe(false);
    });
    test('should generate the correct months before max date', () => {
        const months = generateMonths('en', 2023, undefined, undefined, '2023-08-08');
        expect(months[0].disabled).toBe(false);
        expect(months[6].disabled).toBe(false);
        expect(months[7].value).toBe(8);
        expect(months[7].disabled).toBe(false);
        expect(months[8].disabled).toBe(true);
        expect(months[10].disabled).toBe(true);
    });
    test('should generate the correct months in english with min & max with a different year', () => {
        const months = generateMonths('en', 2023, '2023-10-31', '2023-10-31', '2024-02-29');
        expect(months[0].disabled).toBe(true);
        expect(months[1].disabled).toBe(true);
        expect(months[2].disabled).toBe(true);
        expect(months[3].disabled).toBe(true);
        expect(months[4].disabled).toBe(true);
        expect(months[5].disabled).toBe(true);
        expect(months[6].disabled).toBe(true);
        expect(months[7].disabled).toBe(true);
        expect(months[8].disabled).toBe(true);
        expect(months[9].disabled).toBe(false);
        expect(months[9].selected).toBe(true);
        expect(months[10].disabled).toBe(false);
        expect(months[11].disabled).toBe(false);
    });
    test('should generate the correct months in english with min & max with a different year', () => {
        const months = generateMonths('en', 2024, '2023-10-31', '2023-10-31', '2024-02-29');
        expect(months.length).toBe(12);
        expect(months[0].disabled).toBe(false);
        expect(months[1].disabled).toBe(false);
        expect(months[2].disabled).toBe(true);
        expect(months[3].disabled).toBe(true);
        expect(months[4].disabled).toBe(true);
        expect(months[5].disabled).toBe(true);
        expect(months[6].disabled).toBe(true);
        expect(months[7].disabled).toBe(true);
        expect(months[8].disabled).toBe(true);
        expect(months[9].disabled).toBe(true);
        expect(months[9].selected).toBe(false);
        expect(months[10].disabled).toBe(true);
        expect(months[11].disabled).toBe(true);
    });
});
describe('generateYears Function', () => {
    test('should generate the years of 2023', () => {
        const years = generateYears(2023, 2023, 2023);
        expect(years.length).toBe(1);
        expect(years[0].value).toBe(2023);
        expect(years[0].label).toBe('2023');
        expect(years[0].selected).toBe(true);
        expect(years[0].disabled).toBe(false);
    });
    test('should generate the years 2023, 2022, 2024', () => {
        const years = generateYears(2023, 2022, 2024);
        expect(years.length).toBe(3);
        expect(years[0].value).toBe(2022);
        expect(years[0].label).toBe('2022');
        expect(years[0].selected).toBe(false);
        expect(years[0].disabled).toBe(false);
        expect(years[1].value).toBe(2023);
        expect(years[1].label).toBe('2023');
        expect(years[1].selected).toBe(true);
        expect(years[1].disabled).toBe(false);
        expect(years[2].value).toBe(2024);
        expect(years[2].label).toBe('2024');
        expect(years[2].selected).toBe(false);
        expect(years[2].disabled).toBe(false);
    });
});
