"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 Tools
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreTools = void 0;
const React = require("react"); // cSpell:ignore keyinbrowser
const core_frontend_1 = require("@itwin/core-frontend");
const appui_abstract_1 = require("@itwin/appui-abstract");
const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
const SelectionContextItemDef_1 = require("../selection/SelectionContextItemDef");
const CommandItemDef_1 = require("../shared/CommandItemDef");
const ToolItemDef_1 = require("../shared/ToolItemDef");
const SyncUiEventDispatcher_1 = require("../syncui/SyncUiEventDispatcher");
const GroupItem_1 = require("../toolbar/GroupItem");
const RestoreLayoutTool_1 = require("./RestoreLayoutTool");
const UiFramework_1 = require("../UiFramework");
const gyroscope_svg_1 = require("@bentley/icons-generic/icons/gyroscope.svg");
const rotate_left_svg_1 = require("@bentley/icons-generic/icons/rotate-left.svg");
const section_tool_svg_1 = require("@bentley/icons-generic/icons/section-tool.svg");
const selection_clear_svg_1 = require("@bentley/icons-generic/icons/selection-clear.svg");
const itwinui_icons_react_2 = require("@itwin/itwinui-icons-react");
const core_react_1 = require("@itwin/core-react");
/* eslint-disable deprecation/deprecation */
/** Utility Class that provides definitions of tools provided by the ($core-frontend) core. These definitions can be used to populate the UI.
 * @public
 * @deprecated in 4.15.0. Use {@link ToolbarItems} instead.
 */
class CoreTools {
    static get keyinPaletteButtonItemDef() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: "uif:keyinpalette",
            iconSpec: React.createElement(itwinui_icons_react_2.SvgProcess, null),
            labelKey: "UiFramework:keyinbrowser.label",
            execute: () => {
                UiFramework_1.UiFramework.showKeyinPalette(core_frontend_1.IModelApp.tools.getToolList().map((tool) => ({ value: tool.keyin })));
            },
        });
    }
    static get fitViewCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.FitViewTool.toolId,
            iconSpec: core_frontend_1.FitViewTool.iconSpec,
            label: core_frontend_1.FitViewTool.flyover,
            description: core_frontend_1.FitViewTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.FitViewTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView, true),
        });
    }
    static get windowAreaCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.WindowAreaTool.toolId,
            iconSpec: core_frontend_1.WindowAreaTool.iconSpec,
            label: core_frontend_1.WindowAreaTool.flyover,
            description: core_frontend_1.WindowAreaTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.WindowAreaTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
        });
    }
    static get zoomViewCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.ZoomViewTool.toolId,
            iconSpec: core_frontend_1.ZoomViewTool.iconSpec,
            label: core_frontend_1.ZoomViewTool.flyover,
            description: core_frontend_1.ZoomViewTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.ZoomViewTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
        });
    }
    static get panViewCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.PanViewTool.toolId,
            iconSpec: core_frontend_1.PanViewTool.iconSpec,
            label: core_frontend_1.PanViewTool.flyover,
            description: core_frontend_1.PanViewTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.PanViewTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
        });
    }
    static get rotateViewCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.RotateViewTool.toolId,
            iconSpec: new appui_abstract_1.ConditionalStringValue(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                if (activeContentControl?.viewport?.view.is2d())
                    return rotate_left_svg_1.default;
                return gyroscope_svg_1.default;
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
            label: core_frontend_1.RotateViewTool.flyover,
            description: core_frontend_1.RotateViewTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.RotateViewTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
        });
    }
    static get walkViewCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.WalkViewTool.toolId,
            iconSpec: core_frontend_1.WalkViewTool.iconSpec,
            label: core_frontend_1.WalkViewTool.flyover,
            description: core_frontend_1.WalkViewTool.description,
            isHidden: new appui_abstract_1.ConditionalBooleanValue(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                return !!activeContentControl?.viewport?.view.is2d();
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.WalkViewTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
        });
    }
    static get selectElementCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.SelectionTool.toolId,
            iconSpec: core_frontend_1.SelectionTool.iconSpec,
            label: core_frontend_1.SelectionTool.flyover,
            description: core_frontend_1.SelectionTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.SelectionTool.toolId),
        });
    }
    static get setupCameraWalkTool() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.SetupWalkCameraTool.toolId,
            iconSpec: core_frontend_1.SetupWalkCameraTool.iconSpec,
            label: core_frontend_1.SetupWalkCameraTool.flyover,
            description: core_frontend_1.SetupWalkCameraTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.SetupWalkCameraTool.toolId),
        });
    }
    static get toggleCameraViewCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.ViewToggleCameraTool.toolId,
            iconSpec: new core_react_1.ConditionalIconItem(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                if (activeContentControl?.viewport?.view.is3d() &&
                    activeContentControl?.viewport?.isCameraOn) {
                    return React.createElement(itwinui_icons_react_1.SvgCameraAnimation, null);
                }
                return React.createElement(itwinui_icons_react_1.SvgCameraAnimationDisabled, null);
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
            label: new appui_abstract_1.ConditionalStringValue(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                if (activeContentControl?.viewport?.view.is3d() &&
                    activeContentControl?.viewport?.isCameraOn) {
                    return UiFramework_1.UiFramework.translate("tools.View.ToggleCamera.turnOffFlyover");
                }
                return UiFramework_1.UiFramework.translate("tools.View.ToggleCamera.turnOnFlyover");
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
            description: core_frontend_1.ViewToggleCameraTool.description,
            isHidden: new appui_abstract_1.ConditionalBooleanValue(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                return !(activeContentControl?.viewport?.view.is3d() &&
                    activeContentControl?.viewport?.view.supportsCamera());
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.ViewToggleCameraTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
        });
    }
    static get flyViewCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.FlyViewTool.toolId,
            iconSpec: core_frontend_1.FlyViewTool.iconSpec,
            label: core_frontend_1.FlyViewTool.flyover,
            description: core_frontend_1.FlyViewTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.FlyViewTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
        });
    }
    // TODO - Need to provide a sync message that is fired when the Undo/Redo button needs to be refreshed in the
    // active view.
    static get viewUndoCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.ViewUndoTool.toolId,
            isDisabled: new appui_abstract_1.ConditionalBooleanValue(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                if (activeContentControl && activeContentControl.viewport)
                    return !activeContentControl.viewport.isUndoPossible;
                return false;
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
            iconSpec: core_frontend_1.ViewUndoTool.iconSpec,
            label: core_frontend_1.ViewUndoTool.flyover,
            description: core_frontend_1.ViewUndoTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.ViewUndoTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
        });
    }
    static get viewRedoCommand() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.ViewRedoTool.toolId,
            iconSpec: core_frontend_1.ViewRedoTool.iconSpec,
            label: core_frontend_1.ViewRedoTool.flyover,
            description: core_frontend_1.ViewRedoTool.description,
            execute: async () => core_frontend_1.IModelApp.tools.run(core_frontend_1.ViewRedoTool.toolId, core_frontend_1.IModelApp.viewManager.selectedView),
            isDisabled: new appui_abstract_1.ConditionalBooleanValue(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                if (activeContentControl && activeContentControl.viewport)
                    return !activeContentControl.viewport.isRedoPossible;
                return false;
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
        });
    }
    static turnOnClipVolume() {
        const vp = core_frontend_1.IModelApp.viewManager.selectedView;
        if (!vp || !vp.view.is3d())
            return;
        // Turn on clip volume flag for section tools
        vp.viewFlags = vp.viewFlags.with("clipVolume", true);
    }
    // note current ViewClipByPlaneTool is not automatically registered so the app must call ViewClipByPlaneTool.register();
    static get sectionByPlaneCommandItemDef() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.ViewClipByPlaneTool.toolId,
            iconSpec: core_frontend_1.ViewClipByPlaneTool.iconSpec,
            label: core_frontend_1.ViewClipByPlaneTool.flyover,
            description: core_frontend_1.ViewClipByPlaneTool.description,
            execute: async () => {
                this.turnOnClipVolume();
                return core_frontend_1.IModelApp.tools.run(core_frontend_1.ViewClipByPlaneTool.toolId, core_frontend_1.ViewClipDecorationProvider.create());
            },
        });
    }
    // note current ViewClipByElementTool is not automatically registered so the app must call ViewClipByElementTool.register();
    static get sectionByElementCommandItemDef() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.ViewClipByElementTool.toolId,
            iconSpec: core_frontend_1.ViewClipByElementTool.iconSpec,
            label: core_frontend_1.ViewClipByElementTool.flyover,
            description: core_frontend_1.ViewClipByElementTool.description,
            execute: async () => {
                this.turnOnClipVolume();
                return core_frontend_1.IModelApp.tools.run(core_frontend_1.ViewClipByElementTool.toolId, core_frontend_1.ViewClipDecorationProvider.create());
            },
        });
    }
    // note current ViewClipByRangeTool is not automatically registered so the app must call ViewClipByRangeTool.register();
    static get sectionByRangeCommandItemDef() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.ViewClipByRangeTool.toolId,
            iconSpec: core_frontend_1.ViewClipByRangeTool.iconSpec,
            label: core_frontend_1.ViewClipByRangeTool.flyover,
            description: core_frontend_1.ViewClipByRangeTool.description,
            execute: async () => {
                this.turnOnClipVolume();
                return core_frontend_1.IModelApp.tools.run(core_frontend_1.ViewClipByRangeTool.toolId, core_frontend_1.ViewClipDecorationProvider.create());
            },
        });
    }
    // note current ViewClipByShapeTool is not automatically registered so the app must call ViewClipByShapeTool.register();
    static get sectionByShapeCommandItemDef() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.ViewClipByShapeTool.toolId,
            iconSpec: core_frontend_1.ViewClipByShapeTool.iconSpec,
            label: core_frontend_1.ViewClipByShapeTool.flyover,
            description: core_frontend_1.ViewClipByShapeTool.description,
            execute: async () => {
                this.turnOnClipVolume();
                return core_frontend_1.IModelApp.tools.run(core_frontend_1.ViewClipByShapeTool.toolId, core_frontend_1.ViewClipDecorationProvider.create());
            },
        });
    }
    static get sectionToolGroup() {
        core_frontend_1.ViewClipByElementTool.register();
        core_frontend_1.ViewClipByPlaneTool.register();
        core_frontend_1.ViewClipByRangeTool.register();
        core_frontend_1.ViewClipByShapeTool.register();
        return new GroupItem_1.GroupItemDef({
            groupId: "sectionTools-group",
            labelKey: "UiFramework:tools.sectionTools",
            iconSpec: section_tool_svg_1.default,
            isHidden: new appui_abstract_1.ConditionalBooleanValue(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                return !!activeContentControl?.viewport?.view.is2d();
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
            items: [
                this.sectionByPlaneCommandItemDef,
                this.sectionByElementCommandItemDef,
                this.sectionByRangeCommandItemDef,
                this.sectionByShapeCommandItemDef,
            ],
            itemsInColumn: 4,
        });
    }
    static get sectionToolGroupWithPanel() {
        core_frontend_1.ViewClipByElementTool.register();
        core_frontend_1.ViewClipByPlaneTool.register();
        core_frontend_1.ViewClipByRangeTool.register();
        core_frontend_1.ViewClipByShapeTool.register();
        return new GroupItem_1.GroupItemDef({
            groupId: "sectionTools-group-with-panel",
            labelKey: "UiFramework:tools.sectionTools",
            panelLabelKey: "UiFramework:tools.sectionPanelLabel",
            iconSpec: section_tool_svg_1.default,
            isHidden: new appui_abstract_1.ConditionalBooleanValue(() => {
                const activeContentControl = UiFramework_1.UiFramework.content.getActiveContentControl();
                return !!activeContentControl?.viewport?.view.is2d();
            }, [
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveContentChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ActiveViewportChanged,
                SyncUiEventDispatcher_1.SyncUiEventId.ViewStateChanged,
            ]),
            items: [
                new ToolItemDef_1.ToolItemDef({
                    ...this.sectionByPlaneCommandItemDef,
                    labelKey: "UiFramework:tools.sectionByPlane",
                }),
                new ToolItemDef_1.ToolItemDef({
                    ...this.sectionByElementCommandItemDef,
                    labelKey: "UiFramework:tools.sectionByElement",
                }),
                new ToolItemDef_1.ToolItemDef({
                    ...this.sectionByRangeCommandItemDef,
                    labelKey: "UiFramework:tools.sectionByRange",
                }),
                new ToolItemDef_1.ToolItemDef({
                    ...this.sectionByShapeCommandItemDef,
                    labelKey: "UiFramework:tools.sectionByShape",
                }),
            ],
            itemsInColumn: 4,
        });
    }
    // note current MeasureDistanceTool is not automatically registered so the app must call MeasureDistanceTool.register();
    static get measureDistanceToolItemDef() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.MeasureDistanceTool.toolId,
            iconSpec: core_frontend_1.MeasureDistanceTool.iconSpec,
            label: core_frontend_1.MeasureDistanceTool.flyover,
            description: core_frontend_1.MeasureDistanceTool.description,
            execute: async () => {
                return core_frontend_1.IModelApp.tools.run(core_frontend_1.MeasureDistanceTool.toolId);
            },
        });
    }
    // note current MeasureLocationTool is not automatically registered so the app must call MeasureLocationTool.register();
    static get measureLocationToolItemDef() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: core_frontend_1.MeasureLocationTool.toolId,
            iconSpec: core_frontend_1.MeasureLocationTool.iconSpec,
            label: core_frontend_1.MeasureLocationTool.flyover,
            description: core_frontend_1.MeasureLocationTool.description,
            execute: async () => {
                return core_frontend_1.IModelApp.tools.run(core_frontend_1.MeasureLocationTool.toolId);
            },
        });
    }
    static get measureToolGroup() {
        core_frontend_1.MeasureDistanceTool.register();
        core_frontend_1.MeasureLocationTool.register();
        return new GroupItem_1.GroupItemDef({
            groupId: "measureTools-group",
            labelKey: "UiFramework:tools.measureTools",
            iconSpec: React.createElement(itwinui_icons_react_2.SvgMeasure, null),
            items: [this.measureDistanceToolItemDef, this.measureLocationToolItemDef],
            itemsInColumn: 2,
        });
    }
    static get clearSelectionItemDef() {
        return new CommandItemDef_1.CommandItemDef({
            commandId: "UiFramework.ClearSelection",
            iconSpec: selection_clear_svg_1.default,
            labelKey: "UiFramework:buttons.clearSelection",
            isHidden: (0, SelectionContextItemDef_1.getIsHiddenIfSelectionNotActive)(),
            execute: async () => {
                const iModelConnection = UiFramework_1.UiFramework.getIModelConnection();
                if (iModelConnection) {
                    iModelConnection.selectionSet.emptyAll();
                }
                const tool = core_frontend_1.IModelApp.toolAdmin.primitiveTool;
                if (tool)
                    await tool.onRestartTool();
                else
                    await core_frontend_1.IModelApp.toolAdmin.startDefaultTool();
            },
        });
    }
    static get restoreFrontstageLayoutCommandItemDef() {
        return new ToolItemDef_1.ToolItemDef({
            toolId: RestoreLayoutTool_1.RestoreFrontstageLayoutTool.toolId,
            iconSpec: RestoreLayoutTool_1.RestoreFrontstageLayoutTool.iconSpec,
            label: RestoreLayoutTool_1.RestoreFrontstageLayoutTool.flyover,
            description: RestoreLayoutTool_1.RestoreFrontstageLayoutTool.description,
            execute: async () => {
                return core_frontend_1.IModelApp.tools.run(RestoreLayoutTool_1.RestoreFrontstageLayoutTool.toolId);
            },
        });
    }
}
exports.CoreTools = CoreTools;
//# sourceMappingURL=CoreToolDefinitions.js.map