"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get IsCurrentDay () {
        return IsCurrentDay;
    },
    get canSelectDate () {
        return canSelectDate;
    },
    get getCalendarType () {
        return getCalendarType;
    },
    get getDateFromNow () {
        return getDateFromNow;
    },
    get getDateFromValue () {
        return getDateFromValue;
    },
    get getDaysInMonth () {
        return getDaysInMonth;
    },
    get getMatrix () {
        return getMatrix;
    },
    get getNextDate () {
        return getNextDate;
    },
    get getOffsetDayInWeek () {
        return getOffsetDayInWeek;
    },
    get getPrevDate () {
        return getPrevDate;
    },
    get getPropsMap () {
        return getPropsMap;
    },
    get getStartYear () {
        return getStartYear;
    },
    get isCurrentMonth () {
        return isCurrentMonth;
    },
    get isCurrentQuarter () {
        return isCurrentQuarter;
    },
    get isCurrentYear () {
        return isCurrentYear;
    },
    get isSelectedDay () {
        return isSelectedDay;
    },
    get isSelectedMonth () {
        return isSelectedMonth;
    },
    get isSelectedYear () {
        return isSelectedYear;
    }
});
const _calendarRangeHelper = require("./calendarRangeHelper");
const _constants = require("./constants");
const getDaysInMonth = (monthIndex, year)=>new Date(year, monthIndex + 1, 0).getDate();
const getOffsetDayInWeek = (monthIndex, year)=>(new Date(year, monthIndex).getDay() || 7) - 1;
const getStartYear = (year)=>Math.floor(year / _constants.YEAR_RENDER_COUNT) * _constants.YEAR_RENDER_COUNT;
const getNextDate = (currentYear, currentMonth)=>currentMonth + 1 === _constants.MONTHS.length ? [
        currentYear + 1,
        0
    ] : [
        currentYear,
        currentMonth + 1
    ];
const getPrevDate = (currentYear, currentMonth)=>currentMonth - 1 < 0 ? [
        Math.abs(currentYear - 1) || 0,
        11
    ] : [
        currentYear,
        currentMonth - 1
    ];
const getDateFromValue = (date)=>{
    const state = date || new Date();
    return {
        day: date !== undefined ? state.getDate() : 0,
        monthIndex: state.getMonth(),
        year: Math.abs(state.getFullYear())
    };
};
const getDateFromNow = ()=>{
    const nowDate = new Date();
    return {
        day: nowDate.getDate(),
        monthIndex: nowDate.getMonth(),
        year: nowDate.getFullYear()
    };
};
const IsCurrentDay = (date, currentDay)=>{
    const { day, monthIndex: currentMonthIndex, year: currentYear } = getDateFromNow();
    return day === currentDay && date.monthIndex === currentMonthIndex && date.year === currentYear;
};
const isSelectedDay = (date, currentDay, value)=>{
    if (!value) {
        return false;
    }
    const { day, monthIndex, year } = getDateFromValue(value);
    return day === currentDay && date.monthIndex === monthIndex && date.year === year;
};
const isCurrentMonth = (date, monthIndex)=>{
    const { monthIndex: currentMonthIndex, year: currentYear } = getDateFromNow();
    return monthIndex === currentMonthIndex && date.year === currentYear;
};
const isCurrentQuarter = (date, monthIndex)=>{
    const { monthIndex: currentMonthIndex, year: currentYear } = getDateFromNow();
    const currentQuarterCondition = currentMonthIndex - monthIndex <= 3 && currentMonthIndex - monthIndex > 0;
    return currentQuarterCondition && date.year === currentYear;
};
const isSelectedMonth = (date, currentMonth, value)=>{
    if (!value) {
        return false;
    }
    const { monthIndex, year } = getDateFromValue(value);
    return currentMonth === monthIndex && date.year === year;
};
const isCurrentYear = (year)=>{
    const { year: currentYear } = getDateFromNow();
    return year === currentYear;
};
const isSelectedYear = (yearValue, value)=>{
    if (!value) {
        return false;
    }
    const { year } = getDateFromValue(value);
    return yearValue === year;
};
const getPropsMap = (props)=>props.reduce((acc, prop)=>{
        const { year, monthIndex, day } = getDateFromValue(prop.date);
        const key = `${year}-${monthIndex}-${day}`;
        const propList = acc.get(key) || [];
        propList.push(prop);
        return acc.set(key, propList);
    }, new Map());
const canSelectDate = ({ year, monthIndex, day }, value, disabledList)=>{
    if (!(0, _calendarRangeHelper.isSelectProcess)(value)) {
        return true;
    }
    const hoverDate = new Date(year, monthIndex, day);
    const [startDate] = value;
    if (!disabledList?.length) {
        return true;
    }
    const offDisabledRange = disabledList.some(({ date })=>startDate < date && date < hoverDate || startDate > date && date > hoverDate);
    return !offDisabledRange;
};
const getMatrix = (items, rowSize = 7)=>{
    const newItems = [
        ...items
    ];
    let selected;
    const result = newItems.reduce((acc, item, index)=>{
        if (index % rowSize === 0) {
            acc.push([]);
        }
        acc[acc.length - 1].push(item);
        if (item.isSelected) {
            selected = [
                acc.length - 1,
                index % rowSize
            ];
        }
        return acc;
    }, []);
    return [
        result,
        selected
    ];
};
const getCalendarType = (type, locale)=>{
    switch(type){
        case 'Months':
        case 'Quarters':
            return _constants.I18N.year[locale];
        case 'Years':
            return _constants.I18N.period[locale];
        default:
            return _constants.I18N.month[locale];
    }
};
