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

export { keys, useKeyNavigation };
