import { filter, map } from 'rxjs/operators';
import { Keyboard } from '@platform/react';
export class BindingMonitor {
    constructor(args) {
        const { grid } = args;
        const keydown$ = grid.events$.pipe(filter((e) => e.type === 'GRID/keydown'), filter((e) => grid.isReady), filter((e) => !grid.isEditing), map((e) => e.payload));
        this.grid = grid;
        this.keydown$ = keydown$;
    }
    is(command, e) {
        const binding = this.grid.keyBindings.find((binding) => binding.command === command);
        return binding ? Keyboard.matchEvent(binding.key, e) : false;
    }
    monitor(command, handler) {
        this.keydown$.pipe(filter((e) => this.is(command, e))).subscribe((e) => handler(e));
    }
}
