"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.StandardContentToolsUiItemsProvider = void 0;
const React = require("react");
const SelectionContextItemDef_1 = require("../selection/SelectionContextItemDef");
const StatusBarItem_1 = require("../statusbar/StatusBarItem");
const StatusBarItemUtilities_1 = require("../statusbar/StatusBarItemUtilities");
const SectionsField_1 = require("../statusfields/SectionsField");
const ToolbarHelper_1 = require("../toolbar/ToolbarHelper");
const ToolbarItem_1 = require("../toolbar/ToolbarItem");
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;
}
/**
 * @beta
 */
class StandardContentToolsUiItemsProvider {
    get id() {
        return "appui-react:StandardContentToolsUiItemsProvider";
    }
    constructor(defaultContextTools) {
        this.defaultContextTools = defaultContextTools;
    }
    provideToolbarItems(_stageId, _stageUsage, toolbarUsage, toolbarOrientation, stageAppData) {
        const items = [];
        if (toolbarUsage === ToolbarItem_1.ToolbarUsage.ContentManipulation &&
            toolbarOrientation === ToolbarItem_1.ToolbarOrientation.Horizontal) {
            const clearSelectionGroupPriority = getGroupPriority(stageAppData?.defaultContentTools?.horizontal
                ?.clearSelectionGroupPriority, 10);
            const overridesGroupPriority = getGroupPriority(stageAppData?.defaultContentTools?.horizontal?.overridesGroupPriority, 20);
            if (!this.defaultContextTools ||
                !this.defaultContextTools.horizontal ||
                this.defaultContextTools.horizontal.clearSelection)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(10, CoreToolDefinitions_1.CoreTools.clearSelectionItemDef, { groupPriority: clearSelectionGroupPriority }));
            if (!this.defaultContextTools ||
                !this.defaultContextTools.horizontal ||
                this.defaultContextTools.horizontal.clearDisplayOverrides)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(20, SelectionContextItemDef_1.SelectionContextToolDefinitions.clearHideIsolateEmphasizeElementsItemDef, { groupPriority: overridesGroupPriority }));
            if (!this.defaultContextTools ||
                !this.defaultContextTools.horizontal ||
                this.defaultContextTools.horizontal.hide) {
                if (this.defaultContextTools?.horizontal?.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.defaultContextTools ||
                !this.defaultContextTools.horizontal ||
                this.defaultContextTools.horizontal.isolate) {
                if (this.defaultContextTools?.horizontal?.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.defaultContextTools ||
                !this.defaultContextTools.horizontal ||
                this.defaultContextTools.horizontal.emphasize) {
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(50, SelectionContextItemDef_1.SelectionContextToolDefinitions.emphasizeElementsItemDef, { groupPriority: overridesGroupPriority }));
            }
        } /* istanbul ignore else */
        else if (toolbarUsage === ToolbarItem_1.ToolbarUsage.ContentManipulation &&
            toolbarOrientation === ToolbarItem_1.ToolbarOrientation.Vertical) {
            const selectElementGroupPriority = getGroupPriority(stageAppData?.defaultContentTools?.vertical?.selectElementGroupPriority, 10);
            const measureGroupPriority = getGroupPriority(stageAppData?.defaultContentTools?.vertical?.measureGroupPriority, 10);
            const selectionGroupPriority = getGroupPriority(stageAppData?.defaultContentTools?.vertical?.selectionGroupPriority, 10);
            if (!this.defaultContextTools ||
                !this.defaultContextTools.vertical ||
                this.defaultContextTools.vertical.selectElement)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(10, CoreToolDefinitions_1.CoreTools.selectElementCommand, { groupPriority: selectElementGroupPriority }));
            if (!this.defaultContextTools ||
                !this.defaultContextTools.vertical ||
                this.defaultContextTools.vertical.measureGroup)
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(20, CoreToolDefinitions_1.CoreTools.measureToolGroup, { groupPriority: measureGroupPriority }));
            if (!this.defaultContextTools ||
                !this.defaultContextTools.vertical ||
                this.defaultContextTools.vertical.sectionGroup) {
                items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(30, CoreToolDefinitions_1.CoreTools.sectionToolGroup, { groupPriority: selectionGroupPriority }));
            }
        }
        return items;
    }
    provideStatusBarItems(_stageId, _stageUsage, _stageAppData) {
        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 (this.defaultContextTools?.vertical?.sectionGroup) {
            statusBarItems.push(StatusBarItemUtilities_1.StatusBarItemUtilities.createCustomItem("uifw.Sections", StatusBarItem_1.StatusBarSection.Center, 20, React.createElement(SectionsField_1.SectionsStatusField, { hideWhenUnused: true })));
        }
        return statusBarItems;
    }
}
exports.StandardContentToolsUiItemsProvider = StandardContentToolsUiItemsProvider;
//# sourceMappingURL=StandardContentToolsUiItemsProvider.js.map