import { FOCUS_KEYS } from "../focus-visible";
import { addEventListener, removeEventListener } from "../helpers";
import { ListenerAbstract } from "../types/listener";
export class BalKeyboardListener extends ListenerAbstract {
    constructor() {
        super(...arguments);
        this.info = { keyboardFocus: false };
        this.onKeydown = (ev) => {
            this.info.keyboardFocus = FOCUS_KEYS.includes(ev.key);
            this.notify(this.info);
        };
        this.onPointerDown = () => {
            this.info.keyboardFocus = false;
            this.notify(this.info);
        };
    }
    connect(el) {
        super.connect(el);
        addEventListener(this.el, 'keydown', this.onKeydown);
        addEventListener(this.el, 'touchstart', this.onPointerDown);
        addEventListener(this.el, 'mousedown', this.onPointerDown);
    }
    disconnect() {
        super.disconnect();
        if (this.el) {
            removeEventListener(this.el, 'keydown', this.onKeydown);
            removeEventListener(this.el, 'touchstart', this.onPointerDown);
            removeEventListener(this.el, 'mousedown', this.onPointerDown);
        }
    }
}
