"use strict";
/*---------------------------------------------------------------------------------------------
* 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
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ViewStateHelper = void 0;
const core_frontend_1 = require("@itwin/core-frontend");
const ViewUtilities_1 = require("../utils/ViewUtilities");
/** SavedView class. Used to serialize/deserialize a ViewState.
 * @public
 */
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);
        // istanbul ignore next
        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 core_frontend_1.EmphasizeElements();
            changed = emphasizeElements.fromJSON(savedViewProps.emphasizeElementsProps, vp);
        }
        return changed;
    }
    /** Create props for a ViewState */
    static viewStateToProps(viewState) {
        const savedViewProps = viewState.toProps();
        savedViewProps.bisBaseClass = ViewUtilities_1.ViewUtilities.getBisBaseClass(viewState.classFullName);
        return savedViewProps;
    }
    /** Create props for an EmphasizeElements and store in SavedViewProps */
    static emphasizeElementsToProps(vp, savedViewProps) {
        const ee = core_frontend_1.EmphasizeElements.get(vp);
        const emphasizeElementsProps = ee ? ee.toJSON(vp) : undefined;
        savedViewProps.emphasizeElementsProps = emphasizeElementsProps;
    }
}
exports.ViewStateHelper = ViewStateHelper;
//# sourceMappingURL=ViewStateHelper.js.map