/**
 * DevExtreme (renovation/ui/scroll_view/scroll_view.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.ScrollView = exports.viewFunction = void 0;
var _themes = _interopRequireDefault(require("../../../ui/themes"));
var _type = require("../../../core/utils/type");
var _scrollable = require("./scrollable");
var _combine_classes = require("../../utils/combine_classes");
var _scroll_view_props = require("./scroll_view_props");
var _utils = require("../../../core/options/utils");
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 _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
}

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)
}
var viewFunction = function(viewModel) {
    var cssClasses = viewModel.cssClasses,
        props = viewModel.props,
        pulledDownText = viewModel.pulledDownText,
        pullingDownText = viewModel.pullingDownText,
        reachBottomText = viewModel.reachBottomText,
        refreshingText = viewModel.refreshingText,
        restAttributes = viewModel.restAttributes,
        scrollableRef = viewModel.scrollableRef;
    return Preact.h(_scrollable.Scrollable, _extends({
        classes: cssClasses,
        ref: scrollableRef
    }, props, restAttributes, {
        pulledDownText: pulledDownText,
        pullingDownText: pullingDownText,
        refreshingText: refreshingText,
        reachBottomText: reachBottomText,
        forceGeneratePockets: true,
        needScrollViewContentWrapper: true
    }))
};
exports.viewFunction = viewFunction;
var ScrollView = (0, _compat.forwardRef)((function(props, ref) {
    var __scrollableRef = (0, _hooks.useRef)();
    var __cssClasses = (0, _hooks.useCallback)((function() {
        return (0, _combine_classes.combineClasses)({
            "dx-scrollview": true
        })
    }), []);
    var __pullingDownText = (0, _hooks.useCallback)((function() {
        var pullingDownText = props.pullingDownText;
        if ((0, _type.isDefined)(pullingDownText)) {
            return pullingDownText
        }
        return _themes.default.isMaterial(_themes.default.current()) ? "" : void 0
    }), [props.pullingDownText]);
    var __pulledDownText = (0, _hooks.useCallback)((function() {
        var pulledDownText = props.pulledDownText;
        if ((0, _type.isDefined)(pulledDownText)) {
            return pulledDownText
        }
        return _themes.default.isMaterial(_themes.default.current()) ? "" : void 0
    }), [props.pulledDownText]);
    var __refreshingText = (0, _hooks.useCallback)((function() {
        var refreshingText = props.refreshingText;
        if ((0, _type.isDefined)(refreshingText)) {
            return refreshingText
        }
        return _themes.default.isMaterial(_themes.default.current()) ? "" : void 0
    }), [props.refreshingText]);
    var __reachBottomText = (0, _hooks.useCallback)((function() {
        var reachBottomText = props.reachBottomText;
        if ((0, _type.isDefined)(reachBottomText)) {
            return reachBottomText
        }
        return _themes.default.isMaterial(_themes.default.current()) ? "" : void 0
    }), [props.reachBottomText]);
    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.current.content()
    }), []);
    var __scrollBy = (0, _hooks.useCallback)((function(distance) {
        __scrollableRef.current.scrollBy(distance)
    }), []);
    var __scrollTo = (0, _hooks.useCallback)((function(targetLocation) {
        __scrollableRef.current.scrollTo(targetLocation)
    }), []);
    var __scrollToElement = (0, _hooks.useCallback)((function(element, offset) {
        __scrollableRef.current.scrollToElement(element, offset)
    }), []);
    var __scrollHeight = (0, _hooks.useCallback)((function() {
        return __scrollableRef.current.scrollHeight()
    }), []);
    var __scrollWidth = (0, _hooks.useCallback)((function() {
        return __scrollableRef.current.scrollWidth()
    }), []);
    var __scrollOffset = (0, _hooks.useCallback)((function() {
        return __scrollableRef.current.scrollOffset()
    }), []);
    var __scrollTop = (0, _hooks.useCallback)((function() {
        return __scrollableRef.current.scrollTop()
    }), []);
    var __scrollLeft = (0, _hooks.useCallback)((function() {
        return __scrollableRef.current.scrollLeft()
    }), []);
    var __clientHeight = (0, _hooks.useCallback)((function() {
        return __scrollableRef.current.clientHeight()
    }), []);
    var __clientWidth = (0, _hooks.useCallback)((function() {
        return __scrollableRef.current.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),
        scrollableRef: __scrollableRef,
        cssClasses: __cssClasses(),
        pullingDownText: __pullingDownText(),
        pulledDownText: __pulledDownText(),
        refreshingText: __refreshingText(),
        reachBottomText: __reachBottomText(),
        restAttributes: __restAttributes()
    })
}));
exports.ScrollView = ScrollView;

function __createDefaultProps() {
    return _objectSpread(_objectSpread({}, _scroll_view_props.ScrollViewPropsType), (0, _utils.convertRulesToOptions)(_scrollable.defaultOptionRules))
}
ScrollView.defaultProps = __createDefaultProps();
var __defaultOptionRules = [];

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