import { needFullMonth } from "../utils/dateHelper";
export var keys = {
    Space: 'Space',
    Escape: 'Escape'
};
export var useKeyNavigation = function useKeyNavigation(param) {
    var isCalendarOpen = param.isCalendarOpen, closeOnEsc = param.closeOnEsc, format = param.format, maskWithFormat = param.maskWithFormat, delimiter = param.delimiter, onToggle = param.onToggle;
    var onKeyDown = function onKeyDown(event) {
        if (event.key === delimiter && maskWithFormat && format && !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;
                }
            default:
                {
                    break;
                }
        }
    };
    return {
        onKeyDown: onKeyDown
    };
};
