"use strict";
// This file was moved from the `server` package to here and `server` has `strictNullChecks` disabled.
// This code was originally written with the assumption that `widget.children` is never undefined, despite the type saying otherwise.
// So we are using `!` to assert that `widget.children` is never undefined.
// Note that `!` does not change the runtime behavior of the code so the code will work the same way as before.
Object.defineProperty(exports, "__esModule", { value: true });
exports.adjustModalCanvases = void 0;
const lodash_1 = require("lodash");
var ModalSize;
(function (ModalSize) {
    ModalSize["EXTRA_SMALL"] = "EXTRA_SMALL";
    ModalSize["SMALL"] = "SMALL";
    ModalSize["MEDIUM"] = "MEDIUM";
    ModalSize["LARGE"] = "LARGE";
    ModalSize["FULLSCREEN"] = "FULLSCREEN";
})(ModalSize || (ModalSize = {}));
const MODAL_ROWS_PRESETS_NEW = {
    [ModalSize.EXTRA_SMALL]: 13,
    [ModalSize.SMALL]: 22,
    [ModalSize.MEDIUM]: 31,
    [ModalSize.LARGE]: 47,
    [ModalSize.FULLSCREEN]: 72
};
const adjustModalCanvases = (dsl) => {
    const newDsl = (0, lodash_1.cloneDeep)(dsl);
    const adjustChildren = (widget, parent) => {
        if (parent && parent.type === 'MODAL_WIDGET') {
            const heightPreset = parent.heightPreset;
            if (widget.type === 'CANVAS_WIDGET') {
                const bottomChildRow = widget.children.reduce((max, child) => {
                    if (child.bottomRow) {
                        return Math.max(max, child.bottomRow);
                    }
                    return max;
                }, 0);
                if (bottomChildRow <= MODAL_ROWS_PRESETS_NEW[heightPreset]) {
                    widget.bottomRow = MODAL_ROWS_PRESETS_NEW[heightPreset];
                }
            }
        }
        if (Array.isArray(widget.children)) {
            for (const child of widget.children) {
                adjustChildren(child, widget);
            }
        }
    };
    adjustChildren(newDsl);
    return newDsl;
};
exports.adjustModalCanvases = adjustModalCanvases;
//# sourceMappingURL=adjustModalCanvases.js.map