/**
 * DevExtreme (esm/renovation/ui/grids/data_grid_next/master_detail/master_detail_row.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/
 */
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
var _excluded = ["row", "rowIndex"];
import {
    createVNode,
    createComponentVNode
} from "inferno";
import {
    InfernoEffect,
    InfernoComponent
} from "@devextreme/runtime/inferno";
import {
    PluginsContext
} from "../../../../utils/plugin/context";
import {
    RowBase,
    RowClassesGetter
} from "../widgets/row_base";
import {
    MasterDetailTemplate
} from "./plugins";
import {
    VisibleColumns
} from "../plugins";
import CLASSES from "../classes";
export var viewFunction = viewModel => {
    var {
        colSpan: colSpan,
        masterDetailRowTemplate: MasterDetailRowTemplate
    } = viewModel;
    var {
        row: row,
        rowIndex: rowIndex
    } = viewModel.props;
    return createComponentVNode(2, RowBase, {
        row: row,
        children: createVNode(1, "td", "dx-cell-focus-disabled dx-master-detail-cell", MasterDetailRowTemplate && createComponentVNode(2, MasterDetailRowTemplate, {
            row: row,
            rowIndex: rowIndex
        }), 0, {
            colSpan: colSpan
        })
    })
};
export var MasterDetailRowProps = {
    row: Object.freeze({
        data: {},
        rowType: "data"
    }),
    rowIndex: 0
};
export class MasterDetailRow extends InfernoComponent {
    constructor(props) {
        super(props);
        this.state = {
            template: void 0,
            colSpan: 1
        };
        this.updateColSpan = this.updateColSpan.bind(this);
        this.updateTemplate = this.updateTemplate.bind(this);
        this.extendMasterDetailRowClasses = this.extendMasterDetailRowClasses.bind(this)
    }
    get plugins() {
        if ("PluginsContext" in this.context) {
            return this.context.PluginsContext
        }
        return PluginsContext
    }
    createEffects() {
        return [new InfernoEffect(this.updateColSpan, [this.plugins]), new InfernoEffect(this.updateTemplate, [this.plugins]), new InfernoEffect(this.extendMasterDetailRowClasses, [this.plugins])]
    }
    updateEffects() {
        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])
    }
    updateColSpan() {
        return this.plugins.watch(VisibleColumns, columns => {
            this.setState(__state_argument => ({
                colSpan: columns.length
            }))
        })
    }
    updateTemplate() {
        return this.plugins.watch(MasterDetailTemplate, template => {
            this.setState(__state_argument => ({
                template: template
            }))
        })
    }
    extendMasterDetailRowClasses() {
        return this.plugins.extend(RowClassesGetter, 1, base => row => {
            if ("detail" === row.rowType) {
                return _extends({}, base(row), {
                    [CLASSES.masterDetailRow]: true
                })
            }
            return base(row)
        })
    }
    get masterDetailRowTemplate() {
        return this.state.template
    }
    get restAttributes() {
        var _this$props = this.props,
            restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
        return restProps
    }
    render() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props),
            template: this.state.template,
            colSpan: this.state.colSpan,
            plugins: this.plugins,
            masterDetailRowTemplate: this.masterDetailRowTemplate,
            restAttributes: this.restAttributes
        })
    }
}
MasterDetailRow.defaultProps = MasterDetailRowProps;
