import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef, useCallback, useContext, useMemo } from "react";
import PanelContext from "@foxglove/studio-base/components/PanelContext";
import Stack from "@foxglove/studio-base/components/Stack";
import PanelCatalogContext from "@foxglove/studio-base/context/PanelCatalogContext";
import { usePanelStateStore, } from "@foxglove/studio-base/context/PanelStateContext";
import { PanelActionsDropdown } from "./PanelActionsDropdown";
import React from "react";
const PanelToolbarControlsComponent = forwardRef((props, ref) => {
    const { additionalIcons, isUnknownPanel } = props;
    const { id: panelId, type: panelType } = useContext(PanelContext) ?? {};
    const panelCatalog = useContext(PanelCatalogContext);
    const hasSettingsSelector = useCallback((store) => (panelId ? store.settingsTrees[panelId] != undefined : false), [panelId]);
    const panelInfo = useMemo(() => (panelType != undefined ? panelCatalog?.getPanelByType(panelType) : undefined), [panelCatalog, panelType]);
    const hasSettings = usePanelStateStore(hasSettingsSelector);
    // Show the settings button so that panel title is editable, unless we have a custom
    // toolbar in which case the title wouldn't be visible.
    const showSettingsButton = panelInfo?.hasCustomToolbar !== true || hasSettings;
    return (_jsxs(Stack, { direction: "row", alignItems: "center", paddingLeft: 1, ref: ref, children: [additionalIcons, _jsx(PanelActionsDropdown, { isUnknownPanel: isUnknownPanel })] }));
});
PanelToolbarControlsComponent.displayName = "PanelToolbarControls";
// Keep controls, which don't change often, in a pure component in order to avoid re-rendering the
// whole PanelToolbar when only children change.
export const PanelToolbarControls = React.memo(PanelToolbarControlsComponent);
//# sourceMappingURL=PanelToolbarControls.js.map