/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Utilities
 */
import { Logger, ProcessDetector } from "@itwin/core-bentley";
import { IModelApp, SnapMode } from "@itwin/core-frontend";
import { Presentation } from "@itwin/presentation-frontend";
import { TelemetryEvent } from "@itwin/core-telemetry";
import { getClassName, UiAdmin, UiError, UiEvent } from "@itwin/appui-abstract";
import { LocalStateStorage, SettingsManager } from "@itwin/core-react";
import { UiIModelComponents } from "@itwin/imodel-components-react";
import { BackstageManager } from "./backstage/BackstageManager";
import { ChildWindowManager } from "./childwindow/ChildWindowManager";
import { InternalConfigurableUiManager } from "./configurableui/InternalConfigurableUiManager";
import { ConfigurableUiActionId } from "./configurableui/state";
import { SessionStateActionId } from "./redux/SessionState";
import { StateManager } from "./redux/StateManager";
import { HideIsolateEmphasizeManager } from "./selection/HideIsolateEmphasizeManager";
import { SYSTEM_PREFERRED_COLOR_THEME, TOOLBAR_OPACITY_DEFAULT, WIDGET_OPACITY_DEFAULT } from "./theme/ThemeManager";
import * as keyinPaletteTools from "./tools/KeyinPaletteTools";
import * as openSettingTools from "./tools/OpenSettingsTool";
import * as restoreLayoutTools from "./tools/RestoreLayoutTool";
import * as toolSettingTools from "./tools/ToolSettingsTools";
import { InternalUiShowHideManager, UiShowHideSettingsProvider } from "./utils/InternalUiShowHideManager";
import { WidgetManager } from "./widgets/WidgetManager";
import { InternalFrontstageManager } from "./frontstage/InternalFrontstageManager";
import { InternalContentViewManager } from "./content/InternalContentViewManager";
import { InternalModalDialogManager } from "./dialog/InternalModalDialogManager";
import { InternalModelessDialogManager } from "./dialog/InternalModelessDialogManager";
import { InternalKeyboardShortcutManager } from "./keyboardshortcut/InternalKeyboardShortcut";
import { InternalToolSettingsManager } from "./zones/toolsettings/InternalToolSettingsManager";
import { SyncUiEventDispatcher, SyncUiEventId } from "./syncui/SyncUiEventDispatcher";
/** UiVisibility Event class.
 * @public
 */
export class UiVisibilityChangedEvent extends UiEvent {
}
/** FrameworkVersion Changed Event class.
 * @internal
 */
export class FrameworkVersionChangedEvent extends UiEvent {
}
/**
 * Manages the Redux store, localization service and iModel, Project and Login services for the ui-framework package.
 * @public
 */
export class UiFramework {
    /**
     * Operation on the backstage component.
     * @beta
     */
    static get backstage() {
        // istanbul ignore next
        if (!UiFramework._backstageManager)
            throw new UiError(UiFramework.loggerCategory(this), UiFramework._complaint);
        return UiFramework._backstageManager;
    }
    /**
     * Manage access to the child windows.
     * @beta
     */
    static get childWindows() {
        return this._childWindowManager;
    }
    /**
     * Manage registered controls
     * @beta
     */
    static get controls() {
        return InternalConfigurableUiManager;
    }
    /**
     * Manage access to frontstages and related helper methods.
     * @beta
     */
    static get frontstages() {
        return InternalFrontstageManager;
    }
    /**
     * Manage access and behavior of the tool settings.
     * @beta
     */
    static get toolSettings() {
        return InternalToolSettingsManager;
    }
    /**
     * Manage content presented by the frontstages.
     * @beta
     */
    static get content() {
        return InternalContentViewManager;
    }
    /**
     * Manage displayed dialogs.
     * @beta
     */
    static get dialogs() {
        return {
            modal: InternalModalDialogManager,
            modeless: InternalModelessDialogManager,
        };
    }
    /**
     * Manages global keyboard shortcuts
     * @beta
     */
    static get keyboardShortcuts() {
        return InternalKeyboardShortcutManager;
    }
    /**
     * Manages UI visibility (Show/Hide)
     * @beta
     */
    static get visibility() {
        return InternalUiShowHideManager;
    }
    /** @public
     * @deprecated in 3.7. Use `childWindows` property, name realignment.
    */
    static get childWindowManager() {
        return UiFramework.childWindows; // eslint-disable-line deprecation/deprecation
    }
    /** Registers class that will be informed when the UserSettingsStorage location has been set or changed. This allows
     * classes to load any previously saved settings from the new storage location. Common storage locations are the browser's
     * local storage, or the iTwin Product Settings cloud storage available via the SettingsAdmin see `IModelApp.settingsAdmin`.
     * @beta
     */
    static registerUserSettingsProvider(entry) {
        if (this._uiSettingsProviderRegistry.has(entry.providerId))
            return false;
        this._uiSettingsProviderRegistry.set(entry.providerId, entry);
        return true;
    }
    /**
     * Called by the application to initialize the UiFramework. Also initializes UIIModelComponents, UiComponents, UiCore.
     * @param store The single Redux store created by the host application. If this is `undefined` then it is assumed that the [[StateManager]] is being used to provide the Redux store.
     * @param frameworkStateKey The name of the key used by the app when adding the UiFramework state into the Redux store. If not defined "frameworkState" is assumed. This value is ignored if [[StateManager]] is being used. The StateManager use "frameworkState".
     * @param startInUi1Mode Used for legacy applications to start up in the deprecated UI 1 mode. This should not set by newer applications.
     * @deprecated in 3.5. UI1.0 is deprecated. Use an overload without a `startInUi1Mode` argument instead.
     */
    static async initialize(store, frameworkStateKey, startInUi1Mode) {
        return this.initializeEx(store, frameworkStateKey, startInUi1Mode);
    }
    /**
     * Called by the application to initialize the UiFramework. Also initializes UIIModelComponents, UiComponents, UiCore.
     * @param store The single Redux store created by the host application. If this is `undefined` then it is assumed that the [[StateManager]] is being used to provide the Redux store.
     * @param frameworkStateKey The name of the key used by the app when adding the UiFramework state into the Redux store. If not defined "frameworkState" is assumed. This value is ignored if [[StateManager]] is being used. The StateManager use "frameworkState".
     * @param startInUi1Mode Used for legacy applications to start up in the deprecated UI 1 mode. This should not set by newer applications.
     *
     * @internal
     */
    static async initializeEx(store, frameworkStateKey, startInUi1Mode) {
        var _a;
        if (UiFramework._initialized) {
            Logger.logInfo(UiFramework.loggerCategory(UiFramework), `UiFramework.initialize already called`);
            return;
        }
        /* if store is undefined then the StateManager class should have been initialized by parent app and the apps default set of reducers registered with it.
          If the app has no reducers to add and does not initialize a StateManager then just initialize the StateManager with the default framework reducer now */
        if (undefined === store && !StateManager.isInitialized(true))
            new StateManager();
        UiFramework._store = store;
        // ignore setting _frameworkStateKeyInStore if not using store
        if (frameworkStateKey && store)
            UiFramework._frameworkStateKeyInStore = frameworkStateKey;
        if (startInUi1Mode)
            UiFramework.store.dispatch({ type: ConfigurableUiActionId.SetFrameworkVersion, payload: "1" }); // eslint-disable-line deprecation/deprecation
        // set up namespace and register all tools from package
        const frameworkNamespace = (_a = IModelApp.localization) === null || _a === void 0 ? void 0 : _a.registerNamespace(UiFramework.localizationNamespace);
        [
            restoreLayoutTools,
            keyinPaletteTools,
            openSettingTools,
            toolSettingTools,
        ].forEach((tool) => IModelApp.tools.registerModule(tool, this.localizationNamespace));
        UiFramework._backstageManager = new BackstageManager();
        UiFramework._hideIsolateEmphasizeActionHandler = new HideIsolateEmphasizeManager(); // this allows user to override the default HideIsolateEmphasizeManager implementation.
        UiFramework._widgetManager = new WidgetManager();
        // Initialize ui-imodel-components, ui-components, ui-core & ui-abstract
        await UiIModelComponents.initialize();
        UiFramework.settingsManager.onSettingsProvidersChanged.addListener(() => {
            SyncUiEventDispatcher.dispatchSyncUiEvent(SyncUiEventId.SettingsProvidersChanged);
        });
        // Initialize the MessagePresenter interface in UiAdmin for Editor notifications
        UiAdmin.messagePresenter = IModelApp.notifications;
        UiFramework._initialized = true;
        // initialize any standalone settings providers that don't need to have defaults set by iModelApp
        UiShowHideSettingsProvider.initialize();
        InternalConfigurableUiManager.initialize();
        return frameworkNamespace;
    }
    /** Un-registers the UiFramework internationalization service namespace */
    static terminate() {
        var _a;
        UiFramework._store = undefined;
        UiFramework._frameworkStateKeyInStore = "frameworkState";
        if (StateManager.isInitialized(true))
            StateManager.clearStore();
        // istanbul ignore next
        (_a = IModelApp.localization) === null || _a === void 0 ? void 0 : _a.unregisterNamespace(UiFramework.localizationNamespace);
        UiFramework._backstageManager = undefined;
        UiFramework._widgetManager = undefined;
        UiFramework._hideIsolateEmphasizeActionHandler = undefined;
        UiFramework._settingsManager = undefined;
        UiIModelComponents.terminate();
        InternalUiShowHideManager.terminate();
        UiFramework._initialized = false;
    }
    /** Determines if UiFramework has been initialized */
    static get initialized() { return UiFramework._initialized; }
    /** Property that returns the SettingManager used by AppUI-based applications.
     * @public
     */
    static get settingsManager() {
        if (undefined === UiFramework._settingsManager)
            UiFramework._settingsManager = new SettingsManager();
        return UiFramework._settingsManager;
    }
    /** @public */
    static get frameworkStateKey() {
        return UiFramework._frameworkStateKeyInStore;
    }
    /** The UiFramework state maintained by Redux
     * @public
     */
    static get frameworkState() {
        try {
            // eslint-disable-next-line dot-notation
            return UiFramework.store.getState()[UiFramework.frameworkStateKey];
        }
        catch (_e) {
            return undefined;
        }
    }
    /** The Redux store */
    static get store() {
        if (UiFramework._store)
            return UiFramework._store;
        // istanbul ignore else
        if (!StateManager.isInitialized(true))
            throw new UiError(UiFramework.loggerCategory(this), `Error trying to access redux store before either store or StateManager has been initialized.`);
        // istanbul ignore next
        return StateManager.store;
    }
    /** The internationalization service created by the app.
     * @internal
    */
    static get localization() {
        // istanbul ignore next
        if (!IModelApp.localization)
            throw new UiError(UiFramework.loggerCategory(this), `IModelApp.localization has not been defined.`);
        return IModelApp.localization;
    }
    /** The internationalization service namespace. */
    static get localizationNamespace() {
        return "UiFramework";
    }
    /** @public
     * @deprecated in 3.7. Use `backstage` alternate property, name realignment.
    */
    static get backstageManager() {
        return UiFramework.backstage;
    }
    /** @alpha */
    static get hideIsolateEmphasizeActionHandler() {
        // istanbul ignore next
        if (!UiFramework._hideIsolateEmphasizeActionHandler)
            throw new UiError(UiFramework.loggerCategory(this), UiFramework._complaint);
        return UiFramework._hideIsolateEmphasizeActionHandler;
    }
    /** @alpha */
    static setHideIsolateEmphasizeActionHandler(handler) {
        // istanbul ignore else
        if (handler)
            UiFramework._hideIsolateEmphasizeActionHandler = handler;
        else
            UiFramework._hideIsolateEmphasizeActionHandler = new HideIsolateEmphasizeManager();
    }
    /** @alpha */
    static get widgetManager() {
        // istanbul ignore next
        if (!UiFramework._widgetManager)
            throw new UiError(UiFramework.loggerCategory(this), UiFramework._complaint);
        return UiFramework._widgetManager;
    }
    /** Calls localization.getLocalizedString with the "UiFramework" namespace. Do NOT include the namespace in the key.
     * @internal
     */
    static translate(key) {
        return IModelApp.localization.getLocalizedString(key, { ns: UiFramework.localizationNamespace });
    }
    /** @internal */
    static get packageName() {
        return "appui-react";
    }
    /** @internal */
    static loggerCategory(obj) {
        const className = getClassName(obj);
        const category = UiFramework.packageName + (className ? `.${className}` : "");
        return category;
    }
    static dispatchActionToStore(type, payload, immediateSync = false) {
        UiFramework.store.dispatch({ type, payload });
        if (immediateSync)
            SyncUiEventDispatcher.dispatchImmediateSyncUiEvent(type);
        else
            SyncUiEventDispatcher.dispatchSyncUiEvent(type);
    }
    static setAccudrawSnapMode(snapMode) {
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.SetSnapMode, snapMode, true);
    }
    static getAccudrawSnapMode() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.snapMode : /* istanbul ignore next */ SnapMode.NearestKeypoint;
    }
    static getActiveSelectionScope() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.sessionState.activeSelectionScope : /* istanbul ignore next */ "element";
    }
    static setActiveSelectionScope(selectionScopeId) {
        // istanbul ignore else
        if (UiFramework.frameworkState) {
            const foundIndex = UiFramework.frameworkState.sessionState.availableSelectionScopes.findIndex((selectionScope) => selectionScope.id === selectionScopeId);
            if (-1 !== foundIndex) {
                const scope = UiFramework.frameworkState.sessionState.availableSelectionScopes[foundIndex];
                UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, scope.id);
                Presentation.selection.scopes.activeScope = scope.id;
            }
        }
    }
    /** @public */
    static openCursorMenu(menuData) {
        UiFramework.dispatchActionToStore(SessionStateActionId.UpdateCursorMenu, menuData);
    }
    /** @public */
    static closeCursorMenu() {
        UiFramework.dispatchActionToStore(SessionStateActionId.UpdateCursorMenu, undefined);
    }
    /** @public */
    static getCursorMenuData() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.sessionState.cursorMenuData : /* istanbul ignore next */ undefined;
    }
    static getActiveIModelId() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.sessionState.iModelId : /* istanbul ignore next */ "";
    }
    static setActiveIModelId(iModelId) {
        UiFramework.dispatchActionToStore(SessionStateActionId.SetActiveIModelId, iModelId);
    }
    static setIModelConnection(iModelConnection, immediateSync = false) {
        var _a;
        const oldConnection = UiFramework.getIModelConnection();
        if (oldConnection !== iModelConnection) {
            if (oldConnection === null || oldConnection === void 0 ? void 0 : oldConnection.iModelId)
                InternalFrontstageManager.clearFrontstageDefsForIModelId(oldConnection.iModelId);
            oldConnection && undefined === iModelConnection && SyncUiEventDispatcher.clearConnectionEvents(oldConnection);
            iModelConnection && SyncUiEventDispatcher.initializeConnectionEvents(iModelConnection);
            UiFramework.dispatchActionToStore(SessionStateActionId.SetIModelConnection, iModelConnection, immediateSync);
        }
        UiFramework.setActiveIModelId((_a = iModelConnection === null || iModelConnection === void 0 ? void 0 : iModelConnection.iModelId) !== null && _a !== void 0 ? _a : "");
    }
    static getIModelConnection() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.sessionState.iModelConnection : /* istanbul ignore next */ undefined;
    }
    /** Called by iModelApp to initialize saved UI state from registered UseSettingsProviders
     * @public
     */
    static async initializeStateFromUserSettingsProviders(immediateSync = false) {
        // let any registered providers to load values from the new storage location
        const providerKeys = [...this._uiSettingsProviderRegistry.keys()];
        for await (const key of providerKeys) {
            await this._uiSettingsProviderRegistry.get(key).loadUserSettings(UiFramework._uiStateStorage);
        }
        // istanbul ignore next
        if (immediateSync)
            SyncUiEventDispatcher.dispatchImmediateSyncUiEvent(SyncUiEventId.UiStateStorageChanged);
        else
            SyncUiEventDispatcher.dispatchSyncUiEvent(SyncUiEventId.UiStateStorageChanged);
    }
    /** @public */
    static async setUiStateStorage(storage, immediateSync = false) {
        if (UiFramework._uiStateStorage === storage)
            return;
        UiFramework._uiStateStorage = storage;
        await this.initializeStateFromUserSettingsProviders(immediateSync);
    }
    /** The UI Settings Storage is a convenient wrapper around Local Storage to assist in caching state information across user sessions.
     * It was previously used to conflate both the state information across session and the information driven directly from user explicit action,
     * which are now handled with user preferences.
     * @public
     */
    static getUiStateStorage() {
        return UiFramework._uiStateStorage;
    }
    static setDefaultIModelViewportControlId(iModelViewportControlId, immediateSync = false) {
        UiFramework.dispatchActionToStore(SessionStateActionId.SetDefaultIModelViewportControlId, iModelViewportControlId, immediateSync);
    }
    static getDefaultIModelViewportControlId() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.sessionState.defaultIModelViewportControlId : /* istanbul ignore next */ undefined;
    }
    static setDefaultViewId(viewId, immediateSync = false) {
        UiFramework.dispatchActionToStore(SessionStateActionId.SetDefaultViewId, viewId, immediateSync);
    }
    static getDefaultViewId() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.sessionState.defaultViewId : /* istanbul ignore next */ undefined;
    }
    static setDefaultViewState(viewState, immediateSync = false) {
        UiFramework.dispatchActionToStore(SessionStateActionId.SetDefaultViewState, viewState, immediateSync);
    }
    static getDefaultViewState() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.sessionState.defaultViewState : /* istanbul ignore next */ undefined;
    }
    /** @public */
    static getAvailableSelectionScopes() {
        return UiFramework.frameworkState ?
            UiFramework.frameworkState.sessionState.availableSelectionScopes :
            /* istanbul ignore next */
            [{ id: "element", label: "Element" }];
    }
    static getIsUiVisible() {
        return UiFramework.visibility.isUiVisible;
    }
    static setIsUiVisible(visible) {
        if (UiFramework.visibility.isUiVisible !== visible) {
            UiFramework.visibility.isUiVisible = visible;
            UiFramework.onUiVisibilityChanged.emit({ visible });
        }
    }
    static setColorTheme(theme) {
        if (UiFramework.getColorTheme() === theme)
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.SetTheme, theme, true);
    }
    static getColorTheme() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.theme : /* istanbul ignore next */ SYSTEM_PREFERRED_COLOR_THEME;
    }
    /** UiFramework.setToolbarOpacity() sets the non-hovered opacity to the value specified. Used by UI 2.0 and later.
     * @param opacity a value between 0 and 1. The default value is 0.5. IT IS NOT ADVISED TO USE A VALUE BELOW 0.2
     * @public
     */
    static setToolbarOpacity(opacity) {
        if (UiFramework.getToolbarOpacity() === opacity)
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.SetToolbarOpacity, opacity, true);
    }
    /** UiFramework.getToolbarOpacity() returns a number between 0 and 1 that is the non-hovered opacity for toolbars.
     * @public
     */
    static getToolbarOpacity() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.toolbarOpacity : /* istanbul ignore next */ TOOLBAR_OPACITY_DEFAULT;
    }
    static setWidgetOpacity(opacity) {
        if (UiFramework.getWidgetOpacity() === opacity)
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.SetWidgetOpacity, opacity, true);
    }
    static getWidgetOpacity() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.widgetOpacity : /* istanbul ignore next */ WIDGET_OPACITY_DEFAULT;
    }
    static isMobile() {
        return ProcessDetector.isMobileBrowser;
    }
    /** Returns the Ui Version.
     * @deprecated in 3.6. UI1.0 is deprecated.
     * @public
     */
    static get uiVersion() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.frameworkVersion : this._uiVersion; // eslint-disable-line deprecation/deprecation
    }
    /** @deprecated in 3.6. UI1.0 is deprecated. */
    static setUiVersion(version) {
        if (UiFramework.uiVersion === version) // eslint-disable-line deprecation/deprecation
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.SetFrameworkVersion, version === "1" ? "1" : "2", true); // eslint-disable-line deprecation/deprecation
    }
    static get showWidgetIcon() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.showWidgetIcon : /* istanbul ignore next */ false;
    }
    static setShowWidgetIcon(value) {
        if (UiFramework.showWidgetIcon === value)
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.SetShowWidgetIcon, value, true);
    }
    /** Animate Tool Settings on appear  */
    static get animateToolSettings() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.animateToolSettings : /* istanbul ignore next */ false;
    }
    static setAnimateToolSettings(value) {
        if (UiFramework.animateToolSettings === value)
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.AnimateToolSettings, value, true);
    }
    /** Use Tool Name As Tool Settings Widget Tab Label */
    static get useToolAsToolSettingsLabel() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.useToolAsToolSettingsLabel : /* istanbul ignore next */ false;
    }
    static setUseToolAsToolSettingsLabel(value) {
        if (UiFramework.useToolAsToolSettingsLabel === value)
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.UseToolAsToolSettingsLabel, value, true);
    }
    /** @alpha */
    static get autoCollapseUnpinnedPanels() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.autoCollapseUnpinnedPanels : /* istanbul ignore next */ false;
    }
    /** Method used to enable the automatic closing of an unpinned widget panel as soon as the
     * mouse leaves the widget panel. The default behavior is to require a mouse click outside
     * the panel before it is closed.
     * @alpha */
    static setAutoCollapseUnpinnedPanels(value) {
        if (UiFramework.autoCollapseUnpinnedPanels === value)
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.AutoCollapseUnpinnedPanels, value, true);
    }
    static get useDragInteraction() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.useDragInteraction : false;
    }
    static setUseDragInteraction(useDragInteraction) {
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.SetDragInteraction, useDragInteraction, true);
    }
    /** Returns the variable controlling whether the overlay is displayed in a Viewport
     * @public
     */
    static get viewOverlayDisplay() {
        return UiFramework.frameworkState ? UiFramework.frameworkState.configurableUiState.viewOverlayDisplay : /* istanbul ignore next */ true;
    }
    /** Set the variable that controls display of the view overlay. Applies to all viewports in the app
   * @public
   */
    static setViewOverlayDisplay(display) {
        if (UiFramework.viewOverlayDisplay === display)
            return;
        UiFramework.dispatchActionToStore(ConfigurableUiActionId.SetViewOverlayDisplay, display);
    }
    /** Send logging message to the telemetry system
     * @internal
     */
    // istanbul ignore next
    static async postTelemetry(eventName, eventId, iTwinId, iModeId, changeSetId, time, additionalProperties) {
        var _a;
        if (!IModelApp.authorizationClient)
            return;
        try {
            const activity = {
                sessionId: IModelApp.sessionId,
                activityId: "",
                applicationId: IModelApp.applicationId,
                applicationVersion: IModelApp.applicationVersion,
                accessToken: (_a = (await IModelApp.authorizationClient.getAccessToken())) !== null && _a !== void 0 ? _a : "",
            };
            const telemetryEvent = new TelemetryEvent(eventName, eventId, iTwinId, iModeId, changeSetId, time, additionalProperties);
            await IModelApp.telemetry.postTelemetry(activity, telemetryEvent);
        }
        catch { }
    }
    /** Determines whether a ContextMenu is open
     * @alpha
     * */
    static get isContextMenuOpen() {
        const contextMenu = document.querySelector("div.core-context-menu-opened");
        return contextMenu !== null && contextMenu !== undefined;
    }
}
UiFramework._initialized = false;
UiFramework._complaint = "UiFramework not initialized";
UiFramework._frameworkStateKeyInStore = "frameworkState"; // default name
UiFramework._uiVersion = "2"; // eslint-disable-line deprecation/deprecation
/** this provides a default state storage handler */
UiFramework._uiStateStorage = new LocalStateStorage();
UiFramework._uiSettingsProviderRegistry = new Map();
UiFramework._childWindowManager = new ChildWindowManager(); // eslint-disable-line deprecation/deprecation
UiFramework.useDefaultPopoutUrl = false;
/** Get Show Ui event.
 * @public
 */
UiFramework.onUiVisibilityChanged = new UiVisibilityChangedEvent();
//# sourceMappingURL=UiFramework.js.map