"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listenWheel = exports.makeWheelListener = void 0;
function makeWheelListener(listener) {
    return (component) => {
        return listenWheel(component, (event, _event) => {
            listener(event, _event);
        });
    };
}
exports.makeWheelListener = makeWheelListener;
function listenWheel(component, onWheel) {
    const { $system: { api: { document: { elementFromPoint }, }, }, $element, } = component;
    const wheelListener = (_event) => {
        const { $context, $element } = component;
        const { $x, $y, $sx, $sy } = $context;
        const { deltaX, deltaY, ctrlKey, altKey, clientX, clientY, 
        // screenX,
        // screenY,
        offsetX, offsetY, } = _event;
        if (ctrlKey) {
            return;
        }
        if (!altKey) {
            // RETURN
            // let targetElement: HTMLElement
            // const pointerElement = elementFromPoint(clientX, clientY)
            // if (pointerElement instanceof HTMLElement) {
            //   targetElement = pointerElement
            // } else {
            //   targetElement = pointerElement.parentElement
            // }
            // if (targetElement && isScrollable(targetElement)) {
            //   return
            // }
        }
        // _event.preventDefault()
        onWheel({
            deltaY,
            deltaX,
            ctrlKey,
            altKey,
            clientX: (clientX - $x) / $sx,
            clientY: (clientY - $y) / $sy,
            offsetX,
            offsetY,
            screenX: clientX,
            screenY: clientY,
        }, _event);
    };
    // $element.addEventListener('wheel', wheelListener, { passive: true })
    $element.addEventListener('wheel', wheelListener, { passive: false });
    return () => {
        $element.removeEventListener('wheel', wheelListener);
    };
}
exports.listenWheel = listenWheel;
//# sourceMappingURL=wheel.js.map