/**
 * DevExtreme (esm/__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/
 */
import $ from "../../../core/renderer";
import {
    isDxMouseWheelEvent
} from "../../../events/utils/index";
const allowScroll = function(container, delta, shiftKey) {
    const $container = $(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
    }
};
const prepareScrollData = function(container, validateTarget) {
    const $container = $(container);
    return {
        validate(e) {
            if (isDxMouseWheelEvent(e) && (eventTarget = e.target, validateTarget ? $(eventTarget).is(container) : true)) {
                if (allowScroll($container, -e.delta, e.shiftKey)) {
                    e._needSkipEvent = true;
                    return true
                }
                return false
            }
            var eventTarget
        }
    }
};
export {
    allowScroll,
    prepareScrollData
};
