import { eachDayOfInterval, isAfter, isBefore, isSameDay } from 'date-fns';
import { Lunar } from 'lunar-typescript';
export default function getPanelCellsData(_a) {
    var selected = _a.selected, rangeDate = _a.rangeDate, hoverRangeDate = _a.hoverRangeDate, disabledPanelDate = _a.disabledPanelDate, defaultPanelDate = _a.defaultPanelDate, row = _a.row, col = _a.col, dateConfig = _a.dateConfig, texts = _a.texts, _b = _a.offset, offset = _b === void 0 ? 0 : _b, inView = _a.inView, disableRangeOverView = _a.disableRangeOverView, showLunarDate = _a.showLunarDate;
    var isSame = dateConfig.isSame, startDate = dateConfig.startDate, endDate = dateConfig.endDate, offsetDate = dateConfig.offsetDate;
    var index = 0;
    var cells = [];
    for (var rowIndex = 0; rowIndex < row; rowIndex++) {
        for (var colIndex = 0; colIndex < col; colIndex++) {
            var currentDate = offsetDate(defaultPanelDate, index - offset);
            var text = texts ? texts[index] : currentDate.getDate();
            var lunarText = '';
            if (showLunarDate) {
                var date = currentDate;
                var d = Lunar.fromDate(date);
                var lunarDay = d.getDayInChinese();
                var solarTerm = d.getJieQi();
                if (1 === d.getDay()) {
                    lunarText = d.getMonthInChinese() + '月';
                }
                else {
                    lunarText = solarTerm || lunarDay;
                }
            }
            var isCurrent = isSame(new Date(), currentDate);
            var isInView = inView ? inView(currentDate, defaultPanelDate) : true;
            var isDisabled = eachDayOfInterval({
                start: startDate(currentDate),
                end: endDate(currentDate),
            }).every(function (date) { return disabledPanelDate(date); });
            var isInHoverRange = false;
            var isRangeEndpoint = false;
            var isInRange = false;
            if (hoverRangeDate) {
                var isInHoverRangeDate = isDateInRangeInclusive(currentDate, hoverRangeDate);
                isInHoverRange = disableRangeOverView
                    ? isInHoverRangeDate && isInView
                    : isInHoverRangeDate;
            }
            if (rangeDate) {
                var isInRangeDate = isDateInRangeInclusive(currentDate, rangeDate);
                isInRange = disableRangeOverView
                    ? isInRangeDate && isInView
                    : isInRangeDate;
                var isRangeEndpointDate = isSame(currentDate, rangeDate[0]) ||
                    isSame(currentDate, rangeDate[1]);
                isRangeEndpoint = disableRangeOverView
                    ? isRangeEndpointDate && isInView
                    : isRangeEndpointDate;
            }
            var isSelected = !!selected &&
                (rangeDate ? isRangeEndpoint : isSame(selected, currentDate));
            cells[index] = {
                value: currentDate,
                text: text,
                lunarText: lunarText,
                isCurrent: isCurrent,
                isSelected: isSelected,
                isInView: isInView,
                isDisabled: isDisabled,
                isInHoverRange: isInHoverRange,
                isInRange: isInRange,
            };
            index++;
        }
    }
    return cells;
}
function isDateInRangeInclusive(date, range) {
    return (isSameDay(date, range[0]) ||
        isSameDay(date, range[1]) ||
        (isAfter(date, range[0]) && isBefore(date, range[1])));
}
