/**
 * DevExtreme (renovation/ui/scroll_view/scrollable.js)
 * Version: 21.1.0 (build 21016-0316)
 * Build date: Sat Jan 16 2021
 *
 * Copyright (c) 2012 - 2021 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";

function _typeof(obj) {
    if ("function" === typeof Symbol && "symbol" === typeof Symbol.iterator) {
        _typeof = function(obj) {
            return typeof obj
        }
    } else {
        _typeof = function(obj) {
            return obj && "function" === typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
        }
    }
    return _typeof(obj)
}
exports.defaultOptions = defaultOptions;
exports.Scrollable = exports.defaultOptionRules = exports.viewFunction = void 0;
var _combine_classes = require("../../utils/combine_classes");
var _scrollable_props = require("./scrollable_props");
var _scrollable_native = require("./scrollable_native");
var _scrollable_simulated = require("./scrollable_simulated");
var _utils = require("../../../core/options/utils");
var _devices = _interopRequireDefault(require("../../../core/devices"));
var _browser = _interopRequireDefault(require("../../../core/utils/browser"));
var _support = require("../../../core/utils/support");
var Preact = _interopRequireWildcard(require("preact"));
var _hooks = require("preact/hooks");
var _compat = require("preact/compat");

function _getRequireWildcardCache() {
    if ("function" !== typeof WeakMap) {
        return null
    }
    var cache = new WeakMap;
    _getRequireWildcardCache = function() {
        return cache
    };
    return cache
}

function _interopRequireWildcard(obj) {
    if (obj && obj.__esModule) {
        return obj
    }
    if (null === obj || "object" !== _typeof(obj) && "function" !== typeof obj) {
        return {
            default: obj
        }
    }
    var cache = _getRequireWildcardCache();
    if (cache && cache.has(obj)) {
        return cache.get(obj)
    }
    var newObj = {};
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc)
            } else {
                newObj[key] = obj[key]
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj)
    }
    return newObj
}

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}

function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter((function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable
            }))
        }
        keys.push.apply(keys, symbols)
    }
    return keys
}

function _objectSpread(target) {
    for (var i = 1; i < arguments.length; i++) {
        var source = null != arguments[i] ? arguments[i] : {};
        if (i % 2) {
            ownKeys(Object(source), true).forEach((function(key) {
                _defineProperty(target, key, source[key])
            }))
        } else if (Object.getOwnPropertyDescriptors) {
            Object.defineProperties(target, Object.getOwnPropertyDescriptors(source))
        } else {
            ownKeys(Object(source)).forEach((function(key) {
                Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key))
            }))
        }
    }
    return target
}

function _defineProperty(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        })
    } else {
        obj[key] = value
    }
    return obj
}

function _extends() {
    _extends = Object.assign || function(target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments[i];
            for (var key in source) {
                if (Object.prototype.hasOwnProperty.call(source, key)) {
                    target[key] = source[key]
                }
            }
        }
        return target
    };
    return _extends.apply(this, arguments)
}

function _objectWithoutProperties(source, excluded) {
    if (null == source) {
        return {}
    }
    var target = _objectWithoutPropertiesLoose(source, excluded);
    var key, i;
    if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
        for (i = 0; i < sourceSymbolKeys.length; i++) {
            key = sourceSymbolKeys[i];
            if (excluded.indexOf(key) >= 0) {
                continue
            }
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) {
                continue
            }
            target[key] = source[key]
        }
    }
    return target
}

function _objectWithoutPropertiesLoose(source, excluded) {
    if (null == source) {
        return {}
    }
    var target = {};
    var sourceKeys = Object.keys(source);
    var key, i;
    for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) {
            continue
        }
        target[key] = source[key]
    }
    return target
}
var viewFunction = function(viewModel) {
    var cssClasses = viewModel.cssClasses,
        _viewModel$props = viewModel.props,
        pulledDownText = _viewModel$props.pulledDownText,
        pullingDownText = _viewModel$props.pullingDownText,
        pushBackValue = _viewModel$props.pushBackValue,
        reachBottomText = _viewModel$props.reachBottomText,
        refreshingText = _viewModel$props.refreshingText,
        useNative = _viewModel$props.useNative,
        scrollableProps = _objectWithoutProperties(_viewModel$props, ["pulledDownText", "pullingDownText", "pushBackValue", "reachBottomText", "refreshingText", "useNative"]),
        restAttributes = viewModel.restAttributes,
        scrollableNativeRef = viewModel.scrollableNativeRef,
        scrollableSimulatedRef = viewModel.scrollableSimulatedRef;
    return Preact.h(Preact.Fragment, null, useNative && Preact.h(_scrollable_native.ScrollableNative, _extends({
        ref: scrollableNativeRef,
        classes: cssClasses
    }, scrollableProps, restAttributes, {
        pushBackValue: pushBackValue,
        pulledDownText: pulledDownText,
        pullingDownText: pullingDownText,
        refreshingText: refreshingText,
        reachBottomText: reachBottomText
    })), !useNative && Preact.h(_scrollable_simulated.ScrollableSimulated, _extends({
        ref: scrollableSimulatedRef,
        classes: cssClasses
    }, scrollableProps, restAttributes, {
        pulledDownText: pulledDownText,
        pullingDownText: pullingDownText,
        refreshingText: refreshingText,
        reachBottomText: reachBottomText
    })))
};
exports.viewFunction = viewFunction;
var defaultOptionRules = (0, _utils.createDefaultOptionRules)([{
    device: function(_device) {
        return !_devices.default.isSimulator() && "desktop" === _devices.default.real().deviceType && "generic" === _device.platform
    },
    options: {
        bounceEnabled: false,
        scrollByContent: _support.touch,
        scrollByThumb: true,
        showScrollbar: "onHover"
    }
}, {
    device: function() {
        return !_support.nativeScrolling
    },
    options: {
        useNative: true
    }
}, {
    device: function() {
        return _support.nativeScrolling && "android" === _devices.default.real().platform && !_browser.default.mozilla
    },
    options: {
        useSimulatedScrollbar: true
    }
}]);
exports.defaultOptionRules = defaultOptionRules;
var Scrollable = (0, _compat.forwardRef)((function(props, ref) {
    var __scrollableNativeRef = (0, _hooks.useRef)();
    var __scrollableSimulatedRef = (0, _hooks.useRef)();
    var __cssClasses = (0, _hooks.useCallback)((function() {
        var classes = props.classes;
        return (0, _combine_classes.combineClasses)(_defineProperty({}, "".concat(classes), !!classes))
    }), [props.classes]);
    var __scrollableRef = (0, _hooks.useCallback)((function() {
        return __scrollableNativeRef.current || __scrollableSimulatedRef.current
    }), []);
    var __restAttributes = (0, _hooks.useCallback)((function() {
        props.bounceEnabled, props.children, props.classes, props.direction, props.disabled, props.forceGeneratePockets, props.height, props.inertiaEnabled, props.needScrollViewContentWrapper, props.onScroll, props.pulledDownText, props.pullingDownText, props.pushBackValue, props.reachBottomText, props.refreshingText, props.rtlEnabled, props.scrollByContent, props.scrollByThumb, props.showScrollbar, props.updateManually, props.useKeyboard, props.useNative, props.useSimulatedScrollbar, props.width;
        var restProps = _objectWithoutProperties(props, ["bounceEnabled", "children", "classes", "direction", "disabled", "forceGeneratePockets", "height", "inertiaEnabled", "needScrollViewContentWrapper", "onScroll", "pulledDownText", "pullingDownText", "pushBackValue", "reachBottomText", "refreshingText", "rtlEnabled", "scrollByContent", "scrollByThumb", "showScrollbar", "updateManually", "useKeyboard", "useNative", "useSimulatedScrollbar", "width"]);
        return restProps
    }), [props]);
    var __content = (0, _hooks.useCallback)((function() {
        return __scrollableRef().content()
    }), []);
    var __scrollBy = (0, _hooks.useCallback)((function(distance) {
        __scrollableRef().scrollBy(distance)
    }), []);
    var __scrollTo = (0, _hooks.useCallback)((function(targetLocation) {
        __scrollableRef().scrollTo(targetLocation)
    }), []);
    var __scrollToElement = (0, _hooks.useCallback)((function(element, offset) {
        __scrollableRef().scrollToElement(element, offset)
    }), []);
    var __scrollHeight = (0, _hooks.useCallback)((function() {
        return __scrollableRef().scrollHeight()
    }), []);
    var __scrollWidth = (0, _hooks.useCallback)((function() {
        return __scrollableRef().scrollWidth()
    }), []);
    var __scrollOffset = (0, _hooks.useCallback)((function() {
        return __scrollableRef().scrollOffset()
    }), []);
    var __scrollTop = (0, _hooks.useCallback)((function() {
        return __scrollableRef().scrollTop()
    }), []);
    var __scrollLeft = (0, _hooks.useCallback)((function() {
        return __scrollableRef().scrollLeft()
    }), []);
    var __clientHeight = (0, _hooks.useCallback)((function() {
        return __scrollableRef().clientHeight()
    }), []);
    var __clientWidth = (0, _hooks.useCallback)((function() {
        return __scrollableRef().clientWidth()
    }), []);
    (0, _hooks.useImperativeHandle)(ref, (function() {
        return {
            content: __content,
            scrollBy: __scrollBy,
            scrollTo: __scrollTo,
            scrollToElement: __scrollToElement,
            scrollHeight: __scrollHeight,
            scrollWidth: __scrollWidth,
            scrollOffset: __scrollOffset,
            scrollTop: __scrollTop,
            scrollLeft: __scrollLeft,
            clientHeight: __clientHeight,
            clientWidth: __clientWidth
        }
    }), [__content, __scrollBy, __scrollTo, __scrollToElement, __scrollHeight, __scrollWidth, __scrollOffset, __scrollTop, __scrollLeft, __clientHeight, __clientWidth]);
    return viewFunction({
        props: _objectSpread({}, props),
        scrollableNativeRef: __scrollableNativeRef,
        scrollableSimulatedRef: __scrollableSimulatedRef,
        cssClasses: __cssClasses(),
        scrollableRef: __scrollableRef(),
        restAttributes: __restAttributes()
    })
}));
exports.Scrollable = Scrollable;

function __createDefaultProps() {
    return _objectSpread(_objectSpread({}, _scrollable_props.ScrollablePropsType), (0, _utils.convertRulesToOptions)(defaultOptionRules))
}
Scrollable.defaultProps = __createDefaultProps();
var __defaultOptionRules = [];

function defaultOptions(rule) {
    __defaultOptionRules.push(rule);
    Scrollable.defaultProps = _objectSpread(_objectSpread({}, __createDefaultProps()), (0, _utils.convertRulesToOptions)(__defaultOptionRules))
}
