import { jsx as _jsx } from "react/jsx-runtime";
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import React from "react";
import { Panel, useDetections } from "../components/Panel.js";
import { createRenderDelaySampler } from "../components/measure-render-delay";
import { constructKeyForTopicRenderMetrics, globalRenderMetricsManager, } from "../utils/metrics-manager";
const ImagePanelComponent = React.lazy(async () => await import("@foxglove/studio-base/panels/Image"));
const ImagePanelBody = ({ topic, frameRenderedEvent, annotationReceivedEventHandler, handleOnClick, handleCursorPositionUpdate, registerRendered, unregisterRendered, customOverlay, }) => {
    const { detections } = useDetections();
    const defaultConfig = React.useMemo(() => ({
        imageMode: {
            imageTopic: topic,
            synchronize: true,
            annotations: Object.fromEntries(detections.map((detection) => [
                detection.name, //
                { visible: detection.enabled },
            ])),
            colorMode: "colormap",
        },
    }), [detections, topic]);
    return (_jsx(ImagePanelComponent, { overrideConfig: defaultConfig, frameRenderedEvent: frameRenderedEvent, annotationReceivedEventHandler: annotationReceivedEventHandler, handleOnClick: handleOnClick, handleCursorPositionUpdate: handleCursorPositionUpdate, registerRendered: registerRendered, unregisterRendered: unregisterRendered, customOverlay: customOverlay }));
};
export const ImagePanel = React.memo(function ImagePanel(props) {
    const { averageFrameDelay, addFrameTime } = createRenderDelaySampler();
    const [renderMetricsKey, annotationsMetricsKey] = React.useMemo(() => {
        return [
            constructKeyForTopicRenderMetrics("renderImageFrame", props.topic),
            constructKeyForTopicRenderMetrics("renderAnnotationsFrame", props.topic),
        ];
    }, [props.topic]);
    const handleFrameRendered = (frameTime) => {
        globalRenderMetricsManager.registerEvent(renderMetricsKey);
        addFrameTime(frameTime);
    };
    return (_jsx(Panel, { kind: "image", ...props, toggleTopic: props.toggleTopic, toggleFullscreen: props.toggleFullscreen, renderDelay: averageFrameDelay, canMoveUp: props.canMoveUp, moveUp: props.moveUp, canMoveDown: props.canMoveDown, moveDown: props.moveDown, panelToolbarActions: props.panelToolbarActions, children: _jsx(ImagePanelBody, { topic: props.topic, frameRenderedEvent: handleFrameRendered, annotationReceivedEventHandler: () => {
                globalRenderMetricsManager.registerEvent(annotationsMetricsKey);
            }, handleOnClick: props.handleOnClick, handleCursorPositionUpdate: props.handleCursorPositionUpdate, registerRendered: props.registerRendered, unregisterRendered: props.unregisterRendered, customOverlay: props.customOverlay }) }));
});
//# sourceMappingURL=ImagePanel.js.map