/*---------------------------------------------------------------------------------------------
 * 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 { EmphasizeElements } from "@itwin/core-frontend";
import { ViewUtilities } from "../utils/ViewUtilities";
/** SavedView class. Used to serialize/deserialize a ViewState.
 * @public
 */
export class ViewStateHelper {
    /** Create a ViewState from the SavedView */
    static async viewStateFromProps(iModelConnection, savedViewProps) {
        const className = savedViewProps.viewDefinitionProps.classFullName;
        const ctor = (await iModelConnection.findClassFor(className, undefined));
        if (undefined === ctor)
            throw new Error(`Invalid ViewState class name of [${className}]`);
        const viewState = ctor.createFromProps(savedViewProps, iModelConnection);
        await viewState.load(); // loads models for ModelSelector
        return viewState;
    }
    /** Apply EmphasizeElements from the SavedView */
    static emphasizeElementsFromProps(vp, savedViewProps) {
        let changed = false;
        if (savedViewProps.emphasizeElementsProps) {
            const emphasizeElements = new EmphasizeElements();
            changed = emphasizeElements.fromJSON(savedViewProps.emphasizeElementsProps, vp);
        }
        return changed;
    }
    /** Create props for a ViewState */
    static viewStateToProps(viewState) {
        const savedViewProps = viewState.toProps();
        savedViewProps.bisBaseClass = ViewUtilities.getBisBaseClass(viewState.classFullName);
        return savedViewProps;
    }
    /** Create props for an EmphasizeElements and store in SavedViewProps */
    static emphasizeElementsToProps(vp, savedViewProps) {
        const ee = EmphasizeElements.get(vp);
        const emphasizeElementsProps = ee ? ee.toJSON(vp) : undefined;
        savedViewProps.emphasizeElementsProps = emphasizeElementsProps;
    }
}
//# sourceMappingURL=ViewStateHelper.js.map