"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.NavigationWidget = void 0;
require("./NavigationWidget.scss");
const React = require("react");
const itwinui_react_1 = require("@itwin/itwinui-react");
const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
const AddWidgetButton_1 = require("./AddWidgetButton");
const NineZone_1 = require("../../layout/base/NineZone");
const LayoutStore_1 = require("../../layout/base/LayoutStore");
const Panel_1 = require("../../layout/widget-panels/Panel");
/** Displays a dropdown button to un-hide widgets in the bottom-right corner of the navigation widget area.
 * @internal
 */
function NavigationWidget({ children }) {
    const dispatch = React.useContext(NineZone_1.NineZoneDispatchContext);
    const tabs = (0, AddWidgetButton_1.useUserControlledHiddenTabs)();
    const hasWidgets = useHasWidgets();
    const showAdd = tabs.length > 0 && !hasWidgets;
    return (React.createElement("div", { className: "uifw-preview-navigationWidget" },
        children,
        React.createElement("div", null, showAdd && (React.createElement(itwinui_react_1.DropdownButton, { className: "uifw-preview-navigationWidget_add", startIcon: React.createElement(itwinui_icons_react_1.SvgAdd, null), menuItems: (close) => tabs.map((tab) => {
                return (React.createElement(itwinui_react_1.MenuItem, { key: tab.id, onClick: () => {
                        dispatch({
                            type: "WIDGET_TAB_SHOW",
                            id: tab.id,
                        });
                        close();
                    } }, tab.label));
            }) }, AddWidgetButton_1.label)))));
}
exports.NavigationWidget = NavigationWidget;
/** Returns `false` if there are no floating widgets or panel sections. */
function useHasWidgets() {
    return (0, LayoutStore_1.useLayout)((state) => {
        if (state.floatingWidgets.allIds.length > 0)
            return true;
        for (const side of Panel_1.panelSides) {
            const panel = state.panels[side];
            if (panel.widgets.length > 0) {
                return true;
            }
        }
        return false;
    });
}
//# sourceMappingURL=NavigationWidget.js.map