import { needFullMonth } from "../utils/dateHelper";
export const keys = {
    Space: 'Space',
    Escape: 'Escape'
};
export const useKeyNavigation = ({ isCalendarOpen, closeOnEsc, format, maskWithFormat, delimiter, onToggle })=>{
    const 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
    };
};
