/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
export const NAVIGATION_KEYS = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'End', 'Home'];
export class KeyManager {
    constructor(_config) {
        this._config = _config;
    }
    isNavigationKey({ key, ctrlKey, altKey, shiftKey, metaKey }) {
        if (ctrlKey || altKey || shiftKey || metaKey) {
            return false;
        }
        return NAVIGATION_KEYS.includes(key);
    }
    navigate(key, currentIndex, total) {
        const nextIndex = currentIndex + this.calculateNextIndex(key, total);
        if (!this.canNavigateAtIndex(nextIndex)) {
            return this.navigate(key, nextIndex, total);
        }
        return nextIndex;
    }
    calculateNextIndex(key, total) {
        switch (key) {
            case 'ArrowUp':
            case 'ArrowLeft':
                return -1;
            case 'ArrowDown':
            case 'ArrowRight':
                return 1;
            case 'Home':
                return 0;
            case 'End':
                return total - 1;
            default:
                return 0;
        }
    }
    canNavigateAtIndex(index) {
        var _a;
        if (typeof ((_a = this._config) === null || _a === void 0 ? void 0 : _a.canNavigateCallback) === 'function') {
            return this._config.canNavigateCallback.call(null, index);
        }
        return true;
    }
}
