"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 StandardUiItemsProvider
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.StandardContentToolsProvider = void 0;
const React = require("react");
const core_frontend_1 = require("@itwin/core-frontend");
const appui_abstract_1 = require("@itwin/appui-abstract");
const SelectionContextItemDef_1 = require("../selection/SelectionContextItemDef");
const StatusBarItemUtilities_1 = require("../statusbar/StatusBarItemUtilities");
const withStatusFieldProps_1 = require("../statusbar/withStatusFieldProps");
const SectionsField_1 = require("../statusfields/SectionsField");
const ToolbarHelper_1 = require("../toolbar/ToolbarHelper");
const CoreToolDefinitions_1 = require("../tools/CoreToolDefinitions");
function getGroupPriority(potentialId, defaultValue) {
    if (undefined === potentialId)
        return defaultValue;
    // istanbul ignore else
    if (typeof potentialId === "number") {
        return potentialId;
    }
    // istanbul ignore next
    return defaultValue;
}
/**
 * Provide standard tools for the ContentManipulationWidgetComposer.
 * @public
 */
class StandardContentToolsProvider extends appui_abstract_1.BaseUiItemsProvider {
    constructor(providerId, defaultContentTools, isSupportedStage) {
        super(providerId, isSupportedStage);
        this.defaultContentTools = defaultContentTools;
    }
    /**
     * static function to register the StandardContentToolsProvider
     * @param providerId - unique identifier for this instance of the provider.  This is required in case separate packages want
     * to set up custom stage with their own subset of standard tools.
     * @param defaultContentTools - if undefined all available tools are provided to stage. If defined only those
     * specific tool buttons are shown.
     * @param isSupportedStage - optional function that will be called to determine if tools should be added to current stage. If not set and
     * the current stage's `usage` is set to `StageUsage.General` then the provider will add items to frontstage.
     */
    static register(providerId, defaultContentTools, isSupportedStage) {
        const provider = new StandardContentToolsProvider(providerId, defaultContentTools, isSupportedStage);
        appui_abstract_1.UiItemsManager.register(provider);
        // register core commands not automatically registered
        core_frontend_1.ViewClipByPlaneTool.register();
        return provider;
    }
    provideToolbarButtonItemsInternal(_stageId, _stageUsage, toolbarUsage, toolbarOrientation, stageAppData) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
        const items = [];
        if (toolbarUsage === appui_abstract_1.ToolbarUsage.ContentManipulation && toolbarOrientation === appui_abstract_1.ToolbarOrientation.Horizontal) {
            const clearSelectionGroupPriority = getGroupPriority((_b = (_a = stageAppData === null || stageAppData === void 0 ? void 0 : stageAppData.defaultContentTools) === null || _a === void 0 ? void 0 : _a.horizontal) === null || _b === void 0 ? void 0 : _b.clearSelectionGroupPriority, 10);
            const overridesGroupPriority = getGroupPriority((_d = (_c = stageAppData === null || stageAppData === void 0 ? void 0 : stageAppData.defaultContentTools) === null || _c === void 0 ? void 0 : _c.horizontal) === null || _d === void 0 ? void 0 : _d.overridesGroupPriority, 20);
            if (!this.defaultContentTools || !this.defaultContentTools.horizontal || this.defaultContentTools.horizontal.clearSelection)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(10, CoreToolDefinitions_1.CoreTools.clearSelectionItemDef, { groupPriority: clearSelectionGroupPriority }));
            if (!this.defaultContentTools || !this.defaultContentTools.horizontal || this.defaultContentTools.horizontal.clearDisplayOverrides)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(20, SelectionContextItemDef_1.SelectionContextToolDefinitions.clearHideIsolateEmphasizeElementsItemDef, { groupPriority: overridesGroupPriority }));
            if (!this.defaultContentTools || !this.defaultContentTools.horizontal || this.defaultContentTools.horizontal.hide) {
                if (((_f = (_e = this.defaultContentTools) === null || _e === void 0 ? void 0 : _e.horizontal) === null || _f === void 0 ? void 0 : _f.hide) === "group")
                    items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(30, SelectionContextItemDef_1.SelectionContextToolDefinitions.hideSectionToolGroup, { groupPriority: overridesGroupPriority }));
                else
                    items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(30, SelectionContextItemDef_1.SelectionContextToolDefinitions.hideElementsItemDef, { groupPriority: overridesGroupPriority }));
            }
            if (!this.defaultContentTools || !this.defaultContentTools.horizontal || this.defaultContentTools.horizontal.isolate) {
                if (((_h = (_g = this.defaultContentTools) === null || _g === void 0 ? void 0 : _g.horizontal) === null || _h === void 0 ? void 0 : _h.isolate) === "group")
                    items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(40, SelectionContextItemDef_1.SelectionContextToolDefinitions.isolateSelectionToolGroup, { groupPriority: overridesGroupPriority }));
                else
                    items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(40, SelectionContextItemDef_1.SelectionContextToolDefinitions.isolateElementsItemDef, { groupPriority: overridesGroupPriority }));
            }
            if (!this.defaultContentTools || !this.defaultContentTools.horizontal || this.defaultContentTools.horizontal.emphasize) {
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(50, SelectionContextItemDef_1.SelectionContextToolDefinitions.emphasizeElementsItemDef, { groupPriority: overridesGroupPriority }));
            }
        }
        else /* istanbul ignore else */ if (toolbarUsage === appui_abstract_1.ToolbarUsage.ContentManipulation && toolbarOrientation === appui_abstract_1.ToolbarOrientation.Vertical) {
            const selectElementGroupPriority = getGroupPriority((_k = (_j = stageAppData === null || stageAppData === void 0 ? void 0 : stageAppData.defaultContentTools) === null || _j === void 0 ? void 0 : _j.vertical) === null || _k === void 0 ? void 0 : _k.selectElementGroupPriority, 10);
            const measureGroupPriority = getGroupPriority((_m = (_l = stageAppData === null || stageAppData === void 0 ? void 0 : stageAppData.defaultContentTools) === null || _l === void 0 ? void 0 : _l.vertical) === null || _m === void 0 ? void 0 : _m.measureGroupPriority, 10);
            const selectionGroupPriority = getGroupPriority((_p = (_o = stageAppData === null || stageAppData === void 0 ? void 0 : stageAppData.defaultContentTools) === null || _o === void 0 ? void 0 : _o.vertical) === null || _p === void 0 ? void 0 : _p.selectionGroupPriority, 10);
            if (!this.defaultContentTools || !this.defaultContentTools.vertical || this.defaultContentTools.vertical.selectElement)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(10, CoreToolDefinitions_1.CoreTools.selectElementCommand, { groupPriority: selectElementGroupPriority }));
            if (!this.defaultContentTools || !this.defaultContentTools.vertical || this.defaultContentTools.vertical.measureGroup)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(20, CoreToolDefinitions_1.CoreTools.measureToolGroup, { groupPriority: measureGroupPriority }));
            if (!this.defaultContentTools || !this.defaultContentTools.vertical || this.defaultContentTools.vertical.sectionGroup)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(30, CoreToolDefinitions_1.CoreTools.sectionToolGroup, { groupPriority: selectionGroupPriority }));
        }
        return items;
    }
    provideStatusBarItemsInternal(_stageId, _stageUsage, _stageAppData) {
        var _a, _b;
        const statusBarItems = [];
        // if the sectionGroup tools are to be shown then we want the status field added to allow clearing or manipulation the section
        if ((_b = (_a = this.defaultContentTools) === null || _a === void 0 ? void 0 : _a.vertical) === null || _b === void 0 ? void 0 : _b.sectionGroup) {
            // eslint-disable-next-line deprecation/deprecation
            const Sections = (0, withStatusFieldProps_1.withStatusFieldProps)(SectionsField_1.SectionsStatusField);
            statusBarItems.push(StatusBarItemUtilities_1.StatusBarItemUtilities.createStatusBarItem("uifw.Sections", appui_abstract_1.StatusBarSection.Center, 20, React.createElement(Sections, { hideWhenUnused: true })));
        }
        return statusBarItems;
    }
}
exports.StandardContentToolsProvider = StandardContentToolsProvider;
//# sourceMappingURL=StandardContentToolsProvider.js.map