"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.BasicNavigationWidget = 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 ToolbarComposer_1 = require("../toolbar/ToolbarComposer");
const ToolbarHelper_1 = require("../toolbar/ToolbarHelper");
const useUiVisibility_1 = require("../hooks/useUiVisibility");
const NavigationWidgetComposer_1 = require("./NavigationWidgetComposer");
/** Basic Navigation Widget that provides standard tools to manipulate views containing element data.
 * Supports the specification of additional horizontal and vertical toolbar items through props.
 * @public
 */
function BasicNavigationWidget(props) {
    const getHorizontalToolbarItems = React.useCallback(() => {
        const items = ToolbarHelper_1.ToolbarHelper.createToolbarItemsFromItemDefs([
            CoreToolDefinitions_1.CoreTools.rotateViewCommand,
            CoreToolDefinitions_1.CoreTools.panViewCommand,
            CoreToolDefinitions_1.CoreTools.fitViewCommand,
            CoreToolDefinitions_1.CoreTools.windowAreaCommand,
            CoreToolDefinitions_1.CoreTools.viewUndoCommand,
            CoreToolDefinitions_1.CoreTools.viewRedoCommand,
        ]);
        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.walkViewCommand), ToolbarHelper_1.ToolbarHelper.createToolbarItemFromItemDef(20, CoreToolDefinitions_1.CoreTools.toggleCameraViewCommand));
        if (props.additionalVerticalItems)
            items.push(...props.additionalVerticalItems);
        return items;
    }, [props.additionalVerticalItems]);
    const [horizontalItems, setHorizontalItems] = React.useState(() => getHorizontalToolbarItems());
    const [verticalItems, setVerticalItems] = React.useState(() => getVerticalToolbarItems());
    const isInitialMount = React.useRef(true);
    React.useEffect(() => {
        if (isInitialMount.current)
            isInitialMount.current = false;
        else {
            setHorizontalItems(getHorizontalToolbarItems());
            setVerticalItems(getVerticalToolbarItems());
        }
    }, [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(NavigationWidgetComposer_1.NavigationWidgetComposer, { className: className, horizontalToolbar: React.createElement(ToolbarComposer_1.ToolbarComposer, { items: horizontalItems, usage: appui_abstract_1.ToolbarUsage.ViewNavigation, orientation: appui_abstract_1.ToolbarOrientation.Horizontal }), verticalToolbar: React.createElement(ToolbarComposer_1.ToolbarComposer, { items: verticalItems, usage: appui_abstract_1.ToolbarUsage.ViewNavigation, orientation: appui_abstract_1.ToolbarOrientation.Vertical }) }));
}
exports.BasicNavigationWidget = BasicNavigationWidget;
//# sourceMappingURL=BasicNavigationWidget.js.map