'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 useCalendarNavigation = function useCalendarNavigation(_ref) {
  var calendarState = _ref.calendarState,
    dispatch = _ref.dispatch,
    date = _ref.date;
  var handlePrev = React.useCallback(function () {
    var withShift = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    if (calendarState === types.CalendarState.Days) {
      if (withShift) {
        dispatch({
          type: types.ActionType.PREVIOUS_YEAR,
          payload: {
            step: 1
          }
        });
        return;
      }
      dispatch({
        type: types.ActionType.PREVIOUS_MONTH,
        payload: {
          monthIndex: date.monthIndex,
          year: date.year
        }
      });
      return;
    }
    if (calendarState === types.CalendarState.Months || calendarState === types.CalendarState.Quarters) {
      dispatch({
        type: types.ActionType.PREVIOUS_YEAR,
        payload: {
          step: 1
        }
      });
      return;
    }
    if (calendarState === types.CalendarState.Years) {
      dispatch({
        type: types.ActionType.PREVIOUS_START_YEAR,
        payload: {
          yearsCount: constants.YEAR_RENDER_COUNT
        }
      });
    }
  }, [date, calendarState]);
  var handleNext = React.useCallback(function () {
    var withShift = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    if (calendarState === types.CalendarState.Days) {
      if (withShift) {
        dispatch({
          type: types.ActionType.NEXT_YEAR,
          payload: {
            step: 1
          }
        });
        return;
      }
      dispatch({
        type: types.ActionType.NEXT_MONTH,
        payload: {
          monthIndex: date.monthIndex,
          year: date.year
        }
      });
      return;
    }
    if (calendarState === types.CalendarState.Months || calendarState === types.CalendarState.Quarters) {
      dispatch({
        type: types.ActionType.NEXT_YEAR,
        payload: {
          step: 1
        }
      });
      return;
    }
    if (calendarState === types.CalendarState.Years) {
      dispatch({
        type: types.ActionType.NEXT_START_YEAR,
        payload: {
          yearsCount: constants.YEAR_RENDER_COUNT
        }
      });
    }
  }, [date, calendarState]);
  return {
    handlePrev: handlePrev,
    handleNext: handleNext
  };
};

exports.useCalendarNavigation = useCalendarNavigation;
