/**
 * DevExtreme (renovation/ui/grids/data_grid_next/selection/select_all_checkbox.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.SelectAllCheckboxProps = exports.SelectAllCheckbox = void 0;
var _inferno = require("inferno");
var _inferno2 = require("@devextreme/runtime/inferno");
var _context = require("../../../../utils/plugin/context");
var _check_box = require("../../../editors/check_box/check_box");
var _plugins = require("./plugins");
var _classes = _interopRequireDefault(require("../classes"));

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

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(viewModel) {
    return (0, _inferno.createComponentVNode)(2, _check_box.CheckBox, {
        className: "".concat(_classes.default.selectCheckbox, " ").concat(_classes.default.checkboxSize),
        value: viewModel.value,
        valueChange: viewModel.onValueChange
    })
};
exports.viewFunction = viewFunction;
var SelectAllCheckboxProps = {};
exports.SelectAllCheckboxProps = SelectAllCheckboxProps;
var SelectAllCheckbox = function(_InfernoComponent) {
    _inheritsLoose(SelectAllCheckbox, _InfernoComponent);

    function SelectAllCheckbox(props) {
        var _this;
        _this = _InfernoComponent.call(this, props) || this;
        _this.state = {
            selectedCount: 0,
            selectableCount: 0
        };
        _this.updateSelectableCount = _this.updateSelectableCount.bind(_assertThisInitialized(_this));
        _this.updateSelectedCount = _this.updateSelectedCount.bind(_assertThisInitialized(_this));
        _this.onValueChange = _this.onValueChange.bind(_assertThisInitialized(_this));
        return _this
    }
    var _proto = SelectAllCheckbox.prototype;
    _proto.createEffects = function() {
        return [new _inferno2.InfernoEffect(this.updateSelectableCount, [this.plugins]), new _inferno2.InfernoEffect(this.updateSelectedCount, [this.plugins])]
    };
    _proto.updateEffects = function() {
        var _this$_effects$, _this$_effects$2;
        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])
    };
    _proto.updateSelectableCount = function() {
        var _this2 = this;
        return this.plugins.watch(_plugins.SelectableCount, (function(count) {
            _this2.setState((function(__state_argument) {
                return {
                    selectableCount: count
                }
            }))
        }))
    };
    _proto.updateSelectedCount = function() {
        var _this3 = this;
        return this.plugins.watch(_plugins.SelectedCount, (function(count) {
            _this3.setState((function(__state_argument) {
                return {
                    selectedCount: count
                }
            }))
        }))
    };
    _proto.onValueChange = function(value) {
        if (value) {
            this.plugins.callAction(_plugins.SelectAll)
        } else {
            this.plugins.callAction(_plugins.ClearSelection)
        }
    };
    _proto.render = function() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props),
            selectedCount: this.state.selectedCount,
            selectableCount: this.state.selectableCount,
            plugins: this.plugins,
            value: this.value,
            onValueChange: this.onValueChange,
            restAttributes: this.restAttributes
        })
    };
    _createClass(SelectAllCheckbox, [{
        key: "plugins",
        get: function() {
            if ("PluginsContext" in this.context) {
                return this.context.PluginsContext
            }
            return _context.PluginsContext
        }
    }, {
        key: "value",
        get: function() {
            if (0 === this.state.selectedCount) {
                return false
            }
            if (this.state.selectedCount === this.state.selectableCount) {
                return true
            }
            return null
        }
    }, {
        key: "restAttributes",
        get: function() {
            var restProps = _extends({}, this.props);
            return restProps
        }
    }]);
    return SelectAllCheckbox
}(_inferno2.InfernoComponent);
exports.SelectAllCheckbox = SelectAllCheckbox;
SelectAllCheckbox.defaultProps = SelectAllCheckboxProps;
