/**
 * DevExtreme (renovation/ui/grids/data_grid_next/scrolling/virtual_content.js)
 * Version: 22.1.3 (build 22180-0310)
 * Build date: Wed Jun 29 2022
 *
 * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.viewFunction = exports.VirtualContentProps = exports.VirtualContent = void 0;
var _inferno = require("inferno");
var _inferno2 = require("@devextreme/runtime/inferno");
var _context = require("../../../../utils/plugin/context");
var _placeholder_extender = require("../../../../utils/plugin/placeholder_extender");
var _table_content = require("../views/table_content");
var _plugins = require("./plugins");
var _virtual_row = require("./virtual_row");
var _plugins2 = require("../plugins");
var _getter_extender = require("../../../../utils/plugin/getter_extender");

function _extends() {
    _extends = Object.assign ? Object.assign.bind() : 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 _defineProperties(target, props) {
    for (var i = 0; i < props.length; i++) {
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) {
            descriptor.writable = true
        }
        Object.defineProperty(target, descriptor.key, descriptor)
    }
}

function _createClass(Constructor, protoProps, staticProps) {
    if (protoProps) {
        _defineProperties(Constructor.prototype, protoProps)
    }
    if (staticProps) {
        _defineProperties(Constructor, staticProps)
    }
    Object.defineProperty(Constructor, "prototype", {
        writable: false
    });
    return Constructor
}

function _assertThisInitialized(self) {
    if (void 0 === self) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
    }
    return self
}

function _inheritsLoose(subClass, superClass) {
    subClass.prototype = Object.create(superClass.prototype);
    subClass.prototype.constructor = subClass;
    _setPrototypeOf(subClass, superClass)
}

function _setPrototypeOf(o, p) {
    _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
        o.__proto__ = p;
        return o
    };
    return _setPrototypeOf(o, p)
}
var viewFunction = function(_ref) {
    var bottomHeight = _ref.bottomHeight,
        cellClasses = _ref.cellClasses,
        topHeight = _ref.topHeight;
    return (0, _inferno.createFragment)([(0, _inferno.createComponentVNode)(2, _getter_extender.GetterExtender, {
        type: _plugins.TopVirtualRowHeightValue,
        order: 0,
        value: _plugins.CalculateTopVirtualRowHeight
    }), (0, _inferno.createComponentVNode)(2, _getter_extender.GetterExtender, {
        type: _plugins.BottomVirtualRowHeightValue,
        order: 0,
        value: _plugins.CalculateBottomVirtualRowHeight
    }), topHeight > 0 && (0, _inferno.createComponentVNode)(2, _placeholder_extender.PlaceholderExtender, {
        type: _table_content.TopRowPlaceholder,
        order: 1,
        template: function() {
            return (0, _inferno.createComponentVNode)(2, _virtual_row.VirtualRow, {
                height: topHeight,
                cellClasses: cellClasses,
                rowKey: -1
            })
        }
    }), bottomHeight > 0 && (0, _inferno.createComponentVNode)(2, _placeholder_extender.PlaceholderExtender, {
        type: _table_content.BottomRowPlaceholder,
        order: 1,
        template: function() {
            return (0, _inferno.createComponentVNode)(2, _virtual_row.VirtualRow, {
                height: bottomHeight,
                cellClasses: cellClasses,
                rowKey: -2
            })
        }
    })], 0)
};
exports.viewFunction = viewFunction;
var VirtualContentProps = {};
exports.VirtualContentProps = VirtualContentProps;
var VirtualContent = function(_InfernoComponent) {
    _inheritsLoose(VirtualContent, _InfernoComponent);

    function VirtualContent(props) {
        var _this;
        _this = _InfernoComponent.call(this, props) || this;
        _this.state = {
            topHeight: 0,
            bottomHeight: 0,
            cellClasses: []
        };
        _this.watchVisibleColumns = _this.watchVisibleColumns.bind(_assertThisInitialized(_this));
        _this.watchTopVirtualRowHeight = _this.watchTopVirtualRowHeight.bind(_assertThisInitialized(_this));
        _this.watchBottomVirtualRowHeight = _this.watchBottomVirtualRowHeight.bind(_assertThisInitialized(_this));
        return _this
    }
    var _proto = VirtualContent.prototype;
    _proto.createEffects = function() {
        return [new _inferno2.InfernoEffect(this.watchVisibleColumns, [this.plugins]), new _inferno2.InfernoEffect(this.watchTopVirtualRowHeight, [this.plugins]), new _inferno2.InfernoEffect(this.watchBottomVirtualRowHeight, [this.plugins])]
    };
    _proto.updateEffects = function() {
        var _this$_effects$, _this$_effects$2, _this$_effects$3;
        null === (_this$_effects$ = this._effects[0]) || void 0 === _this$_effects$ ? void 0 : _this$_effects$.update([this.plugins]);
        null === (_this$_effects$2 = this._effects[1]) || void 0 === _this$_effects$2 ? void 0 : _this$_effects$2.update([this.plugins]);
        null === (_this$_effects$3 = this._effects[2]) || void 0 === _this$_effects$3 ? void 0 : _this$_effects$3.update([this.plugins])
    };
    _proto.watchVisibleColumns = function() {
        var _this2 = this;
        return this.plugins.watch(_plugins2.VisibleColumns, (function(visibleColumns) {
            _this2.setState((function(__state_argument) {
                return {
                    cellClasses: Array(visibleColumns.length).fill("").map((function(_, index) {
                        var _visibleColumns$index;
                        return null !== (_visibleColumns$index = visibleColumns[index].headerCssClass) && void 0 !== _visibleColumns$index ? _visibleColumns$index : ""
                    }))
                }
            }))
        }))
    };
    _proto.watchTopVirtualRowHeight = function() {
        var _this3 = this;
        return this.plugins.watch(_plugins.TopVirtualRowHeightValue, (function(height) {
            _this3.setState((function(__state_argument) {
                return {
                    topHeight: height
                }
            }))
        }))
    };
    _proto.watchBottomVirtualRowHeight = function() {
        var _this4 = this;
        return this.plugins.watch(_plugins.BottomVirtualRowHeightValue, (function(height) {
            _this4.setState((function(__state_argument) {
                return {
                    bottomHeight: height
                }
            }))
        }))
    };
    _proto.render = function() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props),
            topHeight: this.state.topHeight,
            bottomHeight: this.state.bottomHeight,
            cellClasses: this.state.cellClasses,
            plugins: this.plugins,
            restAttributes: this.restAttributes
        })
    };
    _createClass(VirtualContent, [{
        key: "plugins",
        get: function() {
            if ("PluginsContext" in this.context) {
                return this.context.PluginsContext
            }
            return _context.PluginsContext
        }
    }, {
        key: "restAttributes",
        get: function() {
            var restProps = _extends({}, this.props);
            return restProps
        }
    }]);
    return VirtualContent
}(_inferno2.InfernoComponent);
exports.VirtualContent = VirtualContent;
VirtualContent.defaultProps = VirtualContentProps;
