import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from "react";
import { getAllComponentInstances } from "../componentTreeHelper";
import { useEditContext } from "../client/editContext";
import { FrameMenu } from "./FrameMenu";
export function FrameMenus({ compareView, pageViewContext, }) {
    const editContext = useEditContext();
    const selection = editContext?.selection;
    const components = useMemo(() => {
        if (!pageViewContext.page)
            return [];
        const comps = selection
            ? selection
                .flatMap((id) => getAllComponentInstances(id, pageViewContext.page))
                .filter((c) => c !== undefined)
            : [];
        // Defensive de-duplication in case selection expansion returns overlaps.
        const uniqueById = new Map();
        for (const component of comps) {
            if (!uniqueById.has(component.id)) {
                uniqueById.set(component.id, component);
            }
        }
        return Array.from(uniqueById.values());
    }, [selection, pageViewContext.page]);
    return (_jsxs(_Fragment, { children: [components.map((c, index) => (_jsx(FrameMenu, { component: c, compareView: compareView, pageViewContext: pageViewContext }, c.id + index))), " "] }));
}
//# sourceMappingURL=FrameMenus.js.map