"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 Item
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolInformation = void 0;
const appui_abstract_1 = require("@itwin/appui-abstract");
const ConfigurableUiControl_1 = require("../configurableui/ConfigurableUiControl");
const UiFramework_1 = require("../UiFramework");
/** Provides information about a tool with a given id, including the ToolUiProvider.
 * @public
 */
class ToolInformation {
    constructor(toolId) {
        this.toolId = toolId;
    }
    /** Get the ToolUiProvider registered for this tool */
    get toolUiProvider() {
        if (!this._toolUiProvider) {
            let provider;
            if (UiFramework_1.UiFramework.controls.isRegistered(this.toolId)) {
                provider = UiFramework_1.UiFramework.controls.create(this.toolId, this.toolId);
            }
            else {
                if (UiFramework_1.UiFramework.toolSettings.useDefaultToolSettingsProvider &&
                    this.toolId === UiFramework_1.UiFramework.toolSettings.toolIdForToolSettings)
                    provider = UiFramework_1.UiFramework.controls.create("DefaultToolSettings", this.toolId);
            }
            // istanbul ignore else
            if (provider) {
                if (provider.getType() !== ConfigurableUiControl_1.ConfigurableUiControlType.ToolUiProvider) {
                    throw new appui_abstract_1.UiError(UiFramework_1.UiFramework.loggerCategory(this), `toolUiProvider: toolId '${this.toolId}' is registered to a control that is NOT a ToolUiProvider`);
                }
                this._toolUiProvider = provider;
            }
        }
        return this._toolUiProvider;
    }
}
exports.ToolInformation = ToolInformation;
//# sourceMappingURL=ToolInformation.js.map