/*---------------------------------------------------------------------------------------------
 * 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 { StatusBarSection } from "../statusbar/StatusBarItem.js";
import { StatusBarItemUtilities } from "../statusbar/StatusBarItemUtilities.js";
import { SectionsStatusField } from "../statusfields/SectionsField.js";
import { ToolbarOrientation, ToolbarUsage } from "../toolbar/ToolbarItem.js";
import { ToolbarItems } from "../tools/ToolbarItems.js";
function getGroupPriority(potentialId, defaultValue) {
    if (undefined === potentialId)
        return defaultValue;
    if (typeof potentialId === "number") {
        return potentialId;
    }
    return defaultValue;
}
/** Provides standard content manipulation items.
 * @public
 */
export class StandardContentToolsUiItemsProvider {
    defaultContextTools;
    get id() {
        return "appui-react:StandardContentToolsUiItemsProvider";
    }
    constructor(defaultContextTools) {
        this.defaultContextTools = defaultContextTools;
    }
    /** @deprecated in 4.17.0. Property of a deprecated interface {@link UiItemsProvider.provideToolbarItems}. */
    provideToolbarItems(_stageId, _stageUsage, toolbarUsage, toolbarOrientation, stageAppData) {
        const allItems = getAllToolbarItems(this.defaultContextTools, stageAppData);
        return allItems.filter((item) => item.layouts?.standard?.usage === toolbarUsage &&
            item.layouts?.standard?.orientation === toolbarOrientation);
    }
    getToolbarItems() {
        return getAllToolbarItems(this.defaultContextTools, undefined);
    }
    /** @deprecated in 4.17.0. Property of a deprecated interface {@link UiItemsProvider.provideStatusBarItems}. */
    provideStatusBarItems(_stageId, _stageUsage, _stageAppData) {
        return this.getStatusBarItems();
    }
    getStatusBarItems() {
        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.createCustomItem({
                id: "uifw.Sections",
                section: StatusBarSection.Center,
                itemPriority: 20,
                content: React.createElement(SectionsStatusField, { hideWhenUnused: true }),
            }));
        }
        return statusBarItems;
    }
}
// Extracted due to discontinued `stageAppData` usage, until `provideToolbarItems` is removed.
function getAllToolbarItems(defaultContextTools, stageAppData) {
    const items = [];
    const clearSelectionGroupPriority = getGroupPriority(stageAppData?.defaultContentTools?.horizontal?.clearSelectionGroupPriority, 10);
    const overridesGroupPriority = getGroupPriority(stageAppData?.defaultContentTools?.horizontal?.overridesGroupPriority, 20);
    const horizontal = {
        standard: {
            usage: ToolbarUsage.ContentManipulation,
            orientation: ToolbarOrientation.Horizontal,
        },
    };
    if (!defaultContextTools ||
        !defaultContextTools.horizontal ||
        defaultContextTools.horizontal.clearSelection)
        items.push(ToolbarItems.createClearSelection({
            itemPriority: 10,
            groupPriority: clearSelectionGroupPriority,
            layouts: horizontal,
        }));
    if (!defaultContextTools ||
        !defaultContextTools.horizontal ||
        defaultContextTools.horizontal.clearDisplayOverrides)
        items.push(ToolbarItems.createClearHideIsolateEmphasizeElements({
            itemPriority: 20,
            groupPriority: overridesGroupPriority,
            layouts: horizontal,
        }));
    if (!defaultContextTools ||
        !defaultContextTools.horizontal ||
        defaultContextTools.horizontal.hide) {
        if (defaultContextTools?.horizontal?.hide === "group")
            items.push(ToolbarItems.createHideSectionGroup({
                itemPriority: 30,
                groupPriority: overridesGroupPriority,
                layouts: horizontal,
            }));
        else
            items.push(ToolbarItems.createHideElements({
                itemPriority: 30,
                groupPriority: overridesGroupPriority,
                layouts: horizontal,
            }));
    }
    if (!defaultContextTools ||
        !defaultContextTools.horizontal ||
        defaultContextTools.horizontal.isolate) {
        if (defaultContextTools?.horizontal?.isolate === "group")
            items.push(ToolbarItems.createIsolateSelectionGroup({
                itemPriority: 40,
                groupPriority: overridesGroupPriority,
                layouts: horizontal,
            }));
        else
            items.push(ToolbarItems.createIsolateElements({
                itemPriority: 40,
                groupPriority: overridesGroupPriority,
                layouts: horizontal,
            }));
    }
    if (!defaultContextTools ||
        !defaultContextTools.horizontal ||
        defaultContextTools.horizontal.emphasize) {
        items.push(ToolbarItems.createEmphasizeElements({
            itemPriority: 50,
            groupPriority: overridesGroupPriority,
            layouts: horizontal,
        }));
    }
    const vertical = {
        standard: {
            usage: ToolbarUsage.ContentManipulation,
            orientation: 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 (!defaultContextTools ||
        !defaultContextTools.vertical ||
        defaultContextTools.vertical.selectElement)
        items.push(ToolbarItems.createSelectElement({
            itemPriority: 10,
            groupPriority: selectElementGroupPriority,
            layouts: vertical,
        }));
    if (!defaultContextTools ||
        !defaultContextTools.vertical ||
        defaultContextTools.vertical.measureGroup)
        items.push(ToolbarItems.createMeasureGroup({
            itemPriority: 20,
            groupPriority: measureGroupPriority,
            layouts: vertical,
        }));
    if (!defaultContextTools ||
        !defaultContextTools.vertical ||
        defaultContextTools.vertical.sectionGroup) {
        items.push(ToolbarItems.createSectionGroup({
            itemPriority: 30,
            groupPriority: selectionGroupPriority,
            layouts: vertical,
        }));
    }
    return items;
}
//# sourceMappingURL=StandardContentToolsUiItemsProvider.js.map