"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 Widget
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasicToolWidget = void 0;
const classnames_1 = require("classnames");
const React = require("react");
const appui_abstract_1 = require("@itwin/appui-abstract");
const CoreToolDefinitions_1 = require("../tools/CoreToolDefinitions");
const SelectionContextItemDef_1 = require("../selection/SelectionContextItemDef");
const ToolbarComposer_1 = require("../toolbar/ToolbarComposer");
const ToolbarHelper_1 = require("../toolbar/ToolbarHelper");
const ToolWidgetComposer_1 = require("./ToolWidgetComposer");
const BackstageAppButton_1 = require("./BackstageAppButton");
const useUiVisibility_1 = require("../hooks/useUiVisibility");
/** 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
 */
function BasicToolWidget(props) {
    const getHorizontalToolbarItems = React.useCallback((useCategoryAndModelsContextTools) => {
        const items = [];
        if (useCategoryAndModelsContextTools) {
            items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(10, CoreToolDefinitions_1.CoreTools.clearSelectionItemDef), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(20, SelectionContextItemDef_1.SelectionContextToolDefinitions.clearHideIsolateEmphasizeElementsItemDef), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(30, SelectionContextItemDef_1.SelectionContextToolDefinitions.hideSectionToolGroup), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(40, SelectionContextItemDef_1.SelectionContextToolDefinitions.isolateSelectionToolGroup), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(50, SelectionContextItemDef_1.SelectionContextToolDefinitions.emphasizeElementsItemDef));
        }
        else {
            items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(10, CoreToolDefinitions_1.CoreTools.clearSelectionItemDef), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(20, SelectionContextItemDef_1.SelectionContextToolDefinitions.clearHideIsolateEmphasizeElementsItemDef), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(30, SelectionContextItemDef_1.SelectionContextToolDefinitions.hideElementsItemDef), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(40, SelectionContextItemDef_1.SelectionContextToolDefinitions.isolateElementsItemDef), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(50, SelectionContextItemDef_1.SelectionContextToolDefinitions.emphasizeElementsItemDef));
        }
        if (props.additionalHorizontalItems)
            items.push(...props.additionalHorizontalItems);
        return items;
    }, [props.additionalHorizontalItems]);
    const getVerticalToolbarItems = React.useCallback(() => {
        const items = [];
        items.push(ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(10, CoreToolDefinitions_1.CoreTools.selectElementCommand), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(20, CoreToolDefinitions_1.CoreTools.measureToolGroup), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(30, CoreToolDefinitions_1.CoreTools.sectionToolGroup));
        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 = (0, useUiVisibility_1.useUiVisibility)();
    // istanbul ignore next
    const className = (0, classnames_1.default)(!uiIsVisible && "nz-hidden");
    return (React.createElement(ToolWidgetComposer_1.ToolWidgetComposer, { className: className, cornerItem: React.createElement(BackstageAppButton_1.BackstageAppButton, { icon: props.icon }), horizontalToolbar: React.createElement(ToolbarComposer_1.ToolbarComposer, { items: horizontalItems, usage: appui_abstract_1.ToolbarUsage.ContentManipulation, orientation: appui_abstract_1.ToolbarOrientation.Horizontal }), verticalToolbar: React.createElement(ToolbarComposer_1.ToolbarComposer, { items: verticalItems, usage: appui_abstract_1.ToolbarUsage.ContentManipulation, orientation: appui_abstract_1.ToolbarOrientation.Vertical }) }));
}
exports.BasicToolWidget = BasicToolWidget;
//# sourceMappingURL=BasicToolWidget.js.map