/**
 * DevExtreme (cjs/__internal/ui/text_box/m_utils.scroll.js)
 * Version: 24.1.7-build-24272-1937
 * Build date: Sat Sep 28 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.prepareScrollData = exports.allowScroll = void 0;
var _renderer = _interopRequireDefault(require("../../../core/renderer"));
var _index = require("../../../events/utils/index");

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}
const allowScroll = function(container, delta, shiftKey) {
    const $container = (0, _renderer.default)(container);
    const scrollTopPos = shiftKey ? $container.scrollLeft() : $container.scrollTop();
    const prop = shiftKey ? "Width" : "Height";
    const scrollSize = $container.prop(`scroll${prop}`);
    const clientSize = $container.prop(`client${prop}`);
    const scrollBottomPos = scrollSize - clientSize - scrollTopPos | 0;
    if (0 === scrollTopPos && 0 === scrollBottomPos) {
        return false
    }
    const isScrollFromTop = 0 === scrollTopPos && delta >= 0;
    const isScrollFromBottom = 0 === scrollBottomPos && delta <= 0;
    const isScrollFromMiddle = scrollTopPos > 0 && scrollBottomPos > 0;
    if (isScrollFromTop || isScrollFromBottom || isScrollFromMiddle) {
        return true
    }
};
exports.allowScroll = allowScroll;
const prepareScrollData = function(container, validateTarget) {
    const $container = (0, _renderer.default)(container);
    return {
        validate(e) {
            if ((0, _index.isDxMouseWheelEvent)(e) && (eventTarget = e.target, validateTarget ? (0, _renderer.default)(eventTarget).is(container) : true)) {
                if (allowScroll($container, -e.delta, e.shiftKey)) {
                    e._needSkipEvent = true;
                    return true
                }
                return false
            }
            var eventTarget
        }
    }
};
exports.prepareScrollData = prepareScrollData;
