'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var types = require('../store/types.js');
var constants = require('../utils/constants.js');
var calendarGridHelper = require('../utils/calendarGridHelper.js');
var calendarRangeHelper = require('../utils/calendarRangeHelper.js');
var getDateWithModification = require('../utils/getDateWithModification.js');

/**
 * Хук для получения списка годов.
 */
var useYears = function useYears(_ref) {
  var date = _ref.date,
    value = _ref.value,
    startYear = _ref.startYear,
    eventList = _ref.eventList,
    disabledList = _ref.disabledList,
    min = _ref.min,
    max = _ref.max,
    includeEdgeDates = _ref.includeEdgeDates;
  return React.useMemo(function () {
    // type-coverage:ignore-next-line
    var years = Array.from(Array(constants.YEAR_RENDER_COUNT), function (_, i) {
      var yearValue = startYear + i;
      return {
        isCurrent: calendarGridHelper.isCurrentYear(startYear + i),
        isSelected: Array.isArray(value) ? Boolean(value.find(function (v) {
          return calendarGridHelper.isSelectedYear(yearValue, v);
        })) : calendarGridHelper.isSelectedYear(yearValue, value),
        inRange: Array.isArray(value) ? calendarRangeHelper.isDateInRange(yearValue, 0, 1, value) : false,
        date: {
          year: yearValue,
          monthIndex: 0,
          day: 1
        },
        yearValue: yearValue
      };
    });
    if (eventList !== null && eventList !== void 0 && eventList.length || disabledList !== null && disabledList !== void 0 && disabledList.length || max || min) {
      var modifiedMonths = getDateWithModification.getDatesWithModifications({
        dates: years,
        type: types.CalendarState.Years,
        min: min,
        max: max,
        includeEdgeDates: includeEdgeDates,
        eventList: eventList,
        disabledList: disabledList
      });
      return calendarGridHelper.getMatrix(modifiedMonths, 3);
    }
    return calendarGridHelper.getMatrix(years, 3);
  }, [date, startYear, value, eventList, disabledList, max, min]);
};

exports.useYears = useYears;
