import { ListenerAbstract } from "../types/listener";
import { rOnLoad } from "../helpers";
export class BalSwipeListener extends ListenerAbstract {
    async connect(el) {
        super.connect(el);
        await this.loadLib();
        if (this.PointerListenerLib) {
            this.pointerListener = new this.PointerListenerLib(el, { handleTouchEvents: false });
            this.pointerListener.on('swipeleft', () => this.notify({ left: true, right: false }));
            this.pointerListener.on('swiperight', () => this.notify({ left: false, right: true }));
        }
    }
    disconnect() {
        var _a;
        super.disconnect();
        (_a = this.pointerListener) === null || _a === void 0 ? void 0 : _a.destroy();
    }
    async loadLib() {
        return new Promise((resolve, reject) => {
            rOnLoad(async () => {
                import(/* @vite-ignore */ 'contactjs')
                    .then(module => {
                    this.PointerListenerLib = module.PointerListener;
                    resolve();
                })
                    .catch(reject);
            });
        });
    }
}
