/**
 * DevExtreme (esm/__internal/scheduler/r1/components/base/group_panel_horizontal.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import _extends from "@babel/runtime/helpers/esm/extends";
import {
    createFragment,
    createComponentVNode
} from "inferno";
import {
    BaseInfernoComponent
} from "@devextreme/runtime/inferno";
import {
    getTemplate
} from "../../../../core/r1/utils/index";
import {
    GroupPanelHorizontalRow
} from "./group_panel_horizontal_row";
import {
    GroupPanelBaseDefaultProps
} from "./group_panel_props";
export class GroupPanelHorizontal extends BaseInfernoComponent {
    constructor() {
        super(...arguments);
        this._groupPanelItems = null
    }
    getGroupPanelItems() {
        if (null !== this._groupPanelItems) {
            return this._groupPanelItems
        }
        var {
            groupPanelData: {
                baseColSpan: baseColSpan,
                groupPanelItems: groupPanelItems
            }
        } = this.props;
        var colSpans = groupPanelItems.reduceRight((currentColSpans, groupsRow, idx) => {
            var nextColSpans = currentColSpans;
            var currentLevelGroupCount = groupsRow.length;
            var previousColSpan = idx === groupPanelItems.length - 1 ? baseColSpan : currentColSpans[idx + 1];
            var previousLevelGroupCount = idx === groupPanelItems.length - 1 ? currentLevelGroupCount : groupPanelItems[idx + 1].length;
            var groupCountDiff = previousLevelGroupCount / currentLevelGroupCount;
            nextColSpans[idx] = groupCountDiff * previousColSpan;
            return nextColSpans
        }, [...new Array(groupPanelItems.length)]);
        this._groupPanelItems = groupPanelItems.map((groupsRenderRow, index) => {
            var colSpan = colSpans[index];
            return groupsRenderRow.map(groupItem => _extends(_extends({}, groupItem), {
                colSpan: colSpan
            }))
        });
        return this._groupPanelItems
    }
    componentWillUpdate(nextProps) {
        if (this.props.groupPanelData !== nextProps.groupPanelData) {
            this._groupPanelItems = null
        }
    }
    render() {
        var {
            resourceCellTemplate: resourceCellTemplate
        } = this.props;
        var groupPanelItems = this.getGroupPanelItems();
        var ResourceCellTemplateComponent = getTemplate(resourceCellTemplate);
        return createFragment(groupPanelItems.map(group => createComponentVNode(2, GroupPanelHorizontalRow, {
            groupItems: group,
            cellTemplate: ResourceCellTemplateComponent
        }, group[0].key)), 0)
    }
}
GroupPanelHorizontal.defaultProps = GroupPanelBaseDefaultProps;
