function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _non_iterable_spread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { isSelectProcess } from "./calendarRangeHelper";
import { MONTHS, YEAR_RENDER_COUNT, I18N } from "./constants";
export var getDaysInMonth = function getDaysInMonth(monthIndex, year) {
    return new Date(year, monthIndex + 1, 0).getDate();
};
export var getOffsetDayInWeek = function getOffsetDayInWeek(monthIndex, year) {
    return (new Date(year, monthIndex).getDay() || 7) - 1;
};
export var getStartYear = function getStartYear(year) {
    return Math.floor(year / YEAR_RENDER_COUNT) * YEAR_RENDER_COUNT;
};
export var getNextDate = function getNextDate(currentYear, currentMonth) {
    return currentMonth + 1 === MONTHS.length ? [
        currentYear + 1,
        0
    ] : [
        currentYear,
        currentMonth + 1
    ];
};
export var getPrevDate = function getPrevDate(currentYear, currentMonth) {
    return currentMonth - 1 < 0 ? [
        Math.abs(currentYear - 1) || 0,
        11
    ] : [
        currentYear,
        currentMonth - 1
    ];
};
export var getDateFromValue = function getDateFromValue(date) {
    var state = date || new Date();
    return {
        day: date !== undefined ? state.getDate() : 0,
        monthIndex: state.getMonth(),
        year: Math.abs(state.getFullYear())
    };
};
export var getDateFromNow = function getDateFromNow() {
    var nowDate = new Date();
    return {
        day: nowDate.getDate(),
        monthIndex: nowDate.getMonth(),
        year: nowDate.getFullYear()
    };
};
export var IsCurrentDay = function IsCurrentDay(date, currentDay) {
    var _getDateFromNow = getDateFromNow(), day = _getDateFromNow.day, currentMonthIndex = _getDateFromNow.monthIndex, currentYear = _getDateFromNow.year;
    return day === currentDay && date.monthIndex === currentMonthIndex && date.year === currentYear;
};
export var isSelectedDay = function isSelectedDay(date, currentDay, value) {
    if (!value) {
        return false;
    }
    var _getDateFromValue = getDateFromValue(value), day = _getDateFromValue.day, monthIndex = _getDateFromValue.monthIndex, year = _getDateFromValue.year;
    return day === currentDay && date.monthIndex === monthIndex && date.year === year;
};
export var isCurrentMonth = function isCurrentMonth(date, monthIndex) {
    var _getDateFromNow = getDateFromNow(), currentMonthIndex = _getDateFromNow.monthIndex, currentYear = _getDateFromNow.year;
    return monthIndex === currentMonthIndex && date.year === currentYear;
};
export var isCurrentQuarter = function isCurrentQuarter(date, monthIndex) {
    var _getDateFromNow = getDateFromNow(), currentMonthIndex = _getDateFromNow.monthIndex, currentYear = _getDateFromNow.year;
    var currentQuarterCondition = currentMonthIndex - monthIndex <= 3 && currentMonthIndex - monthIndex > 0;
    return currentQuarterCondition && date.year === currentYear;
};
export var isSelectedMonth = function isSelectedMonth(date, currentMonth, value) {
    if (!value) {
        return false;
    }
    var _getDateFromValue = getDateFromValue(value), monthIndex = _getDateFromValue.monthIndex, year = _getDateFromValue.year;
    return currentMonth === monthIndex && date.year === year;
};
export var isCurrentYear = function isCurrentYear(year) {
    var _getDateFromNow = getDateFromNow(), currentYear = _getDateFromNow.year;
    return year === currentYear;
};
export var isSelectedYear = function isSelectedYear(yearValue, value) {
    if (!value) {
        return false;
    }
    var year = getDateFromValue(value).year;
    return yearValue === year;
};
/**
 * Метод для получения набора неповторяющихся дат.
 */ export var getPropsMap = function getPropsMap(props) {
    return props.reduce(function(acc, prop) {
        var _getDateFromValue = getDateFromValue(prop.date), year = _getDateFromValue.year, monthIndex = _getDateFromValue.monthIndex, day = _getDateFromValue.day;
        var key = "".concat(year, "-").concat(monthIndex, "-").concat(day);
        var propList = acc.get(key) || [];
        propList.push(prop);
        return acc.set(key, propList);
    }, new Map());
};
/**
 * Метод проверяет, можно ли выбрать день.
 */ export var canSelectDate = function canSelectDate(param, value, disabledList) {
    var year = param.year, monthIndex = param.monthIndex, day = param.day;
    if (!isSelectProcess(value)) {
        return true;
    }
    var hoverDate = new Date(year, monthIndex, day);
    var _value = _sliced_to_array(value, 1), startDate = _value[0];
    if (!(disabledList === null || disabledList === void 0 ? void 0 : disabledList.length)) {
        return true;
    }
    var offDisabledRange = disabledList.some(function(param) {
        var date = param.date;
        return startDate < date && date < hoverDate || startDate > date && date > hoverDate;
    });
    return !offDisabledRange;
};
/**
 * Метод для получения двумерного массива и возвращения выбранного элемента.
 */ export var getMatrix = function getMatrix(items) {
    var rowSize = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 7;
    var newItems = _to_consumable_array(items);
    var selected;
    var result = newItems.reduce(function(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
    ];
};
export var getCalendarType = function getCalendarType(type, locale) {
    switch(type){
        case 'Months':
        case 'Quarters':
            return I18N.year[locale];
        case 'Years':
            return I18N.period[locale];
        default:
            return I18N.month[locale];
    }
};
