import { Obj } from '@ephox/katamari';
import * as KeyboardBranches from '../../behaviour/keyboard/KeyboardBranches';
import * as KeyingState from '../../behaviour/keyboard/KeyingState';
import * as Behaviour from './Behaviour';
const isFlatgridState = (keyState) => Obj.hasNonNullableKey(keyState, 'setGridSize');
const Keying = Behaviour.createModes({
    branchKey: 'mode',
    branches: KeyboardBranches,
    name: 'keying',
    active: {
        events: (keyingConfig, keyingState) => {
            const handler = keyingConfig.handler;
            return handler.toEvents(keyingConfig, keyingState);
        }
    },
    apis: {
        focusIn: (component, keyConfig, keyState) => {
            // If we have a custom sendFocusIn function, use that.
            // Otherwise, we just trigger focus on the outer element.
            keyConfig.sendFocusIn(keyConfig).fold(() => {
                component.getSystem().triggerFocus(component.element, component.element);
            }, (sendFocusIn) => {
                sendFocusIn(component, keyConfig, keyState);
            });
        },
        // These APIs are going to be interesting because they are not
        // available for all keying modes
        setGridSize: (component, keyConfig, keyState, numRows, numColumns) => {
            if (!isFlatgridState(keyState)) {
                // eslint-disable-next-line no-console
                console.error('Layout does not support setGridSize');
            }
            else {
                keyState.setGridSize(numRows, numColumns);
            }
        }
    },
    state: KeyingState
});
export { Keying };
//# sourceMappingURL=Keying.js.map