/*---------------------------------------------------------------------------------------------
* 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
 */
import * as React from "react";
import { ViewClipByPlaneTool } from "@itwin/core-frontend";
import { StatusBarSection, ToolbarOrientation, ToolbarUsage, } from "@itwin/appui-abstract";
import { SelectionContextToolDefinitions } from "../selection/SelectionContextItemDef";
import { StatusBarItemUtilities } from "../statusbar/StatusBarItemUtilities";
import { withStatusFieldProps } from "../statusbar/withStatusFieldProps";
import { SectionsStatusField } from "../statusfields/SectionsField";
import { ToolbarHelper } from "../toolbar/ToolbarHelper";
import { CoreTools } from "../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
 */
export class StandardContentToolsUiItemsProvider {
    constructor(defaultContextTools) {
        this.defaultContextTools = defaultContextTools;
        this._isClipToolRegistered = false;
    }
    get id() { return "appui-react:StandardContentToolsUiItemsProvider"; }
    provideToolbarButtonItems(_stageId, _stageUsage, toolbarUsage, toolbarOrientation, stageAppData) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
        const items = [];
        if (toolbarUsage === ToolbarUsage.ContentManipulation && toolbarOrientation === 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.defaultContextTools || !this.defaultContextTools.horizontal || this.defaultContextTools.horizontal.clearSelection)
                items.push(ToolbarHelper.createToolbarItemFromItemDef(10, CoreTools.clearSelectionItemDef, { groupPriority: clearSelectionGroupPriority }));
            if (!this.defaultContextTools || !this.defaultContextTools.horizontal || this.defaultContextTools.horizontal.clearDisplayOverrides)
                items.push(ToolbarHelper.createToolbarItemFromItemDef(20, SelectionContextToolDefinitions.clearHideIsolateEmphasizeElementsItemDef, { groupPriority: overridesGroupPriority }));
            if (!this.defaultContextTools || !this.defaultContextTools.horizontal || this.defaultContextTools.horizontal.hide) {
                if (((_f = (_e = this.defaultContextTools) === null || _e === void 0 ? void 0 : _e.horizontal) === null || _f === void 0 ? void 0 : _f.hide) === "group")
                    items.push(ToolbarHelper.createToolbarItemFromItemDef(30, SelectionContextToolDefinitions.hideSectionToolGroup, { groupPriority: overridesGroupPriority }));
                else
                    items.push(ToolbarHelper.createToolbarItemFromItemDef(30, SelectionContextToolDefinitions.hideElementsItemDef, { groupPriority: overridesGroupPriority }));
            }
            if (!this.defaultContextTools || !this.defaultContextTools.horizontal || this.defaultContextTools.horizontal.isolate) {
                if (((_h = (_g = this.defaultContextTools) === null || _g === void 0 ? void 0 : _g.horizontal) === null || _h === void 0 ? void 0 : _h.isolate) === "group")
                    items.push(ToolbarHelper.createToolbarItemFromItemDef(40, SelectionContextToolDefinitions.isolateSelectionToolGroup, { groupPriority: overridesGroupPriority }));
                else
                    items.push(ToolbarHelper.createToolbarItemFromItemDef(40, SelectionContextToolDefinitions.isolateElementsItemDef, { groupPriority: overridesGroupPriority }));
            }
            if (!this.defaultContextTools || !this.defaultContextTools.horizontal || this.defaultContextTools.horizontal.emphasize) {
                items.push(ToolbarHelper.createToolbarItemFromItemDef(50, SelectionContextToolDefinitions.emphasizeElementsItemDef, { groupPriority: overridesGroupPriority }));
            }
        }
        else /* istanbul ignore else */ if (toolbarUsage === ToolbarUsage.ContentManipulation && toolbarOrientation === 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.defaultContextTools || !this.defaultContextTools.vertical || this.defaultContextTools.vertical.selectElement)
                items.push(ToolbarHelper.createToolbarItemFromItemDef(10, CoreTools.selectElementCommand, { groupPriority: selectElementGroupPriority }));
            if (!this.defaultContextTools || !this.defaultContextTools.vertical || this.defaultContextTools.vertical.measureGroup)
                items.push(ToolbarHelper.createToolbarItemFromItemDef(20, CoreTools.measureToolGroup, { groupPriority: measureGroupPriority }));
            if (!this.defaultContextTools || !this.defaultContextTools.vertical || this.defaultContextTools.vertical.sectionGroup) {
                if (!this._isClipToolRegistered) {
                    // register core commands not automatically registered
                    ViewClipByPlaneTool.register();
                    this._isClipToolRegistered = true;
                }
                items.push(ToolbarHelper.createToolbarItemFromItemDef(30, CoreTools.sectionToolGroup, { groupPriority: selectionGroupPriority }));
            }
        }
        return items;
    }
    provideStatusBarItems(_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.defaultContextTools) === null || _a === void 0 ? void 0 : _a.vertical) === null || _b === void 0 ? void 0 : _b.sectionGroup) {
            // eslint-disable-next-line deprecation/deprecation
            const Sections = withStatusFieldProps(SectionsStatusField);
            statusBarItems.push(StatusBarItemUtilities.createStatusBarItem("uifw.Sections", StatusBarSection.Center, 20, React.createElement(Sections, { hideWhenUnused: true })));
        }
        return statusBarItems;
    }
}
//# sourceMappingURL=StandardContentToolsUiItemsProvider.js.map