'use strict';

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

var dateHelper = require('../utils/dateHelper.js');

var keys = {
  Space: 'Space',
  Escape: 'Escape'
};
var useKeyNavigation = function useKeyNavigation(_ref) {
  var isCalendarOpen = _ref.isCalendarOpen,
    closeOnEsc = _ref.closeOnEsc,
    format = _ref.format,
    maskWithFormat = _ref.maskWithFormat,
    delimiter = _ref.delimiter,
    onToggle = _ref.onToggle;
  var onKeyDown = function onKeyDown(event) {
    if (event.key === delimiter && maskWithFormat && format && !dateHelper.needFullMonth(format)) {
      event.preventDefault();
      return;
    }
    switch (event.code) {
      case keys.Space:
        {
          if (!isCalendarOpen) {
            event.preventDefault();
            onToggle(true, event);
          }
          break;
        }
      case keys.Escape:
        {
          if (isCalendarOpen && closeOnEsc) {
            event.preventDefault();
            onToggle(false, event);
          }
          break;
        }
    }
  };
  return {
    onKeyDown: onKeyDown
  };
};

exports.keys = keys;
exports.useKeyNavigation = useKeyNavigation;
