/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module ContentView
 */
import { ViewStateHelper } from "./ViewStateHelper.js";
/** StageContentLayout class. Used to serialize/deserialize a View Layout with Saved Views.
 * @public
 */
export class StageContentLayout {
    /** Create props for a View Layout */
    static viewLayoutToProps(contentLayoutDef, contentGroup, emphasizeElements = false, contentCallback) {
        const contentLayoutProps = contentLayoutDef.toJSON();
        // update layout in contentGroup to contain latest values from contentLayoutDef this way we don't need to save both.
        const contentGroupProps = {
            ...contentGroup.toJSON(contentCallback),
            layout: contentLayoutProps,
        };
        const viewStateProps = new Array();
        const viewports = contentGroup.getViewports();
        for (const viewport of viewports) {
            if (viewport) {
                const savedViewProps = ViewStateHelper.viewStateToProps(viewport.view);
                if (emphasizeElements)
                    ViewStateHelper.emphasizeElementsToProps(viewport, savedViewProps);
                viewStateProps.push(savedViewProps);
            }
        }
        const savedViewLayoutProps = {
            contentGroupProps,
            viewStateProps,
        };
        return savedViewLayoutProps;
    }
    /** Create an array of ViewStates from the StageContentLayout */
    static async viewStatesFromProps(iModelConnection, savedProps) {
        const viewStates = new Array();
        if (savedProps.viewStateProps) {
            for (const savedViewProps of savedProps.viewStateProps) {
                const viewState = await ViewStateHelper.viewStateFromProps(iModelConnection, savedViewProps);
                viewStates.push(viewState);
            }
        }
        return viewStates;
    }
    /** Apply EmphasizeElements from the SavedView */
    static emphasizeElementsFromProps(contentGroup, savedProps) {
        const changedList = new Array();
        const viewports = contentGroup.getViewports();
        let index = 0;
        for (const savedViewProps of savedProps.viewStateProps) {
            const viewport = viewports[index];
            if (viewport) {
                const changed = ViewStateHelper.emphasizeElementsFromProps(viewport, savedViewProps);
                changedList.push(changed);
            }
            index++;
        }
        return changedList.some((changed) => changed);
    }
}
//# sourceMappingURL=StageContentLayout.js.map