/**
 * DevExtreme (cjs/events/core/wheel.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.name = void 0;
var _renderer = _interopRequireDefault(require("../../core/renderer"));
var _events_engine = _interopRequireDefault(require("../../events/core/events_engine"));
var _event_registrator = _interopRequireDefault(require("./event_registrator"));
var _index = require("../utils/index");

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}
const EVENT_NAME = "dxmousewheel";
exports.name = EVENT_NAME;
const EVENT_NAMESPACE = "dxWheel";
const NATIVE_EVENT_NAME = "wheel";
const PIXEL_MODE = 0;
const DELTA_MUTLIPLIER = 30;
const wheel = {
    setup: function(element) {
        const $element = (0, _renderer.default)(element);
        _events_engine.default.on($element, (0, _index.addNamespace)("wheel", "dxWheel"), wheel._wheelHandler.bind(wheel))
    },
    teardown: function(element) {
        _events_engine.default.off(element, ".".concat("dxWheel"))
    },
    _wheelHandler: function(e) {
        const {
            deltaMode: deltaMode,
            deltaY: deltaY,
            deltaX: deltaX,
            deltaZ: deltaZ
        } = e.originalEvent;
        (0, _index.fireEvent)({
            type: EVENT_NAME,
            originalEvent: e,
            delta: this._normalizeDelta(deltaY, deltaMode),
            deltaX: deltaX,
            deltaY: deltaY,
            deltaZ: deltaZ,
            deltaMode: deltaMode,
            pointerType: "mouse"
        });
        e.stopPropagation()
    },
    _normalizeDelta(delta) {
        let deltaMode = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
        if (0 === deltaMode) {
            return -delta
        } else {
            return -30 * delta
        }
    }
};
(0, _event_registrator.default)(EVENT_NAME, wheel);
