import { useCallback } from 'react';
import { CalendarState, ActionType } from '../store/types.js';
import { YEAR_RENDER_COUNT } from '../utils/constants.js';

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

export { useCalendarNavigation };
