/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Widget
 */
import classnames from "classnames";
import * as React from "react";
import { ToolbarComposer } from "../toolbar/ToolbarComposer";
import { ToolWidgetComposer } from "./ToolWidgetComposer";
import { BackstageAppButton } from "./BackstageAppButton";
import { useUiVisibility } from "../hooks/useUiVisibility";
import { ToolbarOrientation, ToolbarUsage } from "../toolbar/ToolbarItem";
import { ToolbarItems } from "../tools/ToolbarItems";
/** Default Tool Widget for standard "review" applications. Provides standard tools to review, and measure elements.
 * This definition will also show a overflow button if there is not enough room to display all the toolbar buttons.
 * @public
 */
export function BasicToolWidget(props) {
    const getHorizontalToolbarItems = React.useCallback((useCategoryAndModelsContextTools) => {
        const items = [];
        if (useCategoryAndModelsContextTools) {
            items.push(ToolbarItems.createClearSelection({
                itemPriority: 10,
            }), ToolbarItems.createClearHideIsolateEmphasizeElements({
                itemPriority: 20,
            }), ToolbarItems.createHideSectionGroup({
                itemPriority: 30,
            }), ToolbarItems.createIsolateSelectionGroup({
                itemPriority: 40,
            }), ToolbarItems.createEmphasizeElements({
                itemPriority: 50,
            }));
        }
        else {
            items.push(ToolbarItems.createClearSelection({
                itemPriority: 10,
            }), ToolbarItems.createClearHideIsolateEmphasizeElements({
                itemPriority: 20,
            }), ToolbarItems.createHideElements({
                itemPriority: 30,
            }), ToolbarItems.createIsolateElements({
                itemPriority: 40,
            }), ToolbarItems.createEmphasizeElements({
                itemPriority: 50,
            }));
        }
        if (props.additionalHorizontalItems)
            items.push(...props.additionalHorizontalItems);
        return items;
    }, [props.additionalHorizontalItems]);
    const getVerticalToolbarItems = React.useCallback(() => {
        const items = [];
        items.push(ToolbarItems.createSelectElement({
            itemPriority: 10,
        }), ToolbarItems.createMeasureGroup({
            itemPriority: 20,
        }), ToolbarItems.createSectionGroup({
            itemPriority: 30,
        }));
        if (props.additionalVerticalItems)
            items.push(...props.additionalVerticalItems);
        return items;
    }, [props.additionalVerticalItems]);
    const [horizontalItems, setHorizontalItems] = React.useState(() => getHorizontalToolbarItems(!!props.showCategoryAndModelsContextTools));
    const [verticalItems, setVerticalItems] = React.useState(() => getVerticalToolbarItems());
    const isInitialMount = React.useRef(true);
    React.useEffect(() => {
        if (isInitialMount.current)
            isInitialMount.current = false;
        else {
            setHorizontalItems(getHorizontalToolbarItems(!!props.showCategoryAndModelsContextTools));
            setVerticalItems(getVerticalToolbarItems());
        }
    }, [
        props.showCategoryAndModelsContextTools,
        props.additionalHorizontalItems,
        props.additionalVerticalItems,
        getHorizontalToolbarItems,
        getVerticalToolbarItems,
    ]);
    const uiIsVisible = useUiVisibility();
    const className = classnames(!uiIsVisible && "nz-hidden");
    return (React.createElement(ToolWidgetComposer, { className: className, cornerItem: React.createElement(BackstageAppButton, { icon: props.icon }), horizontalToolbar: React.createElement(ToolbarComposer, { items: horizontalItems, usage: ToolbarUsage.ContentManipulation, orientation: ToolbarOrientation.Horizontal }), verticalToolbar: React.createElement(ToolbarComposer, { items: verticalItems, usage: ToolbarUsage.ContentManipulation, orientation: ToolbarOrientation.Vertical }) }));
}
//# sourceMappingURL=BasicToolWidget.js.map