'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 useQuarters = function useQuarters(_ref) {
  var date = _ref.date,
    value = _ref.value,
    eventList = _ref.eventList,
    disabledList = _ref.disabledList,
    min = _ref.min,
    max = _ref.max,
    includeEdgeDates = _ref.includeEdgeDates;
  return React.useMemo(function () {
    var quarters = constants.QUARTER_NAMES.map(function (quarterName) {
      var _quarterDates$quarter = constants.quarterDates[quarterName],
        monthIndex = _quarterDates$quarter.monthIndex,
        day = _quarterDates$quarter.day;
      return {
        quarterName: quarterName,
        isCurrent: calendarGridHelper.isCurrentQuarter(date, monthIndex),
        isSelected: Array.isArray(value) ? Boolean(value.find(function (v) {
          return calendarGridHelper.isSelectedMonth(date, monthIndex, v);
        })) : calendarGridHelper.isSelectedMonth(date, monthIndex, value),
        inRange: Array.isArray(value) ? calendarRangeHelper.isDateInRange(date.year, monthIndex, day, value) : false,
        date: {
          year: date.year,
          monthIndex: monthIndex,
          day: 1
        }
      };
    });
    if (eventList !== null && eventList !== void 0 && eventList.length || disabledList !== null && disabledList !== void 0 && disabledList.length || max || min) {
      var modifiedQuarters = getDateWithModification.getDatesWithModifications({
        dates: quarters,
        type: types.CalendarState.Quarters,
        min: min,
        max: max,
        includeEdgeDates: includeEdgeDates,
        eventList: eventList,
        disabledList: disabledList
      });
      return calendarGridHelper.getMatrix(modifiedQuarters, 2);
    }
    return calendarGridHelper.getMatrix(quarters, 2);
  }, [date, value, eventList, disabledList, max, min]);
};

exports.useQuarters = useQuarters;
