import { jsx as _jsx } from "@emotion/react/jsx-runtime";
import React from 'react';
import { ImplWrapper } from './ImplWrapper';
export function resolveAppComponents(components, params) {
    var _a, _b, _c, _d;
    const topLevelComponents = [];
    const slotComponentsMap = new Map();
    for (const c of components) {
        const slotTrait = c.traits.find(t => t.parsedType.name === 'slot');
        if (slotTrait) {
            const { id, slot } = slotTrait.properties.container;
            if (!slotComponentsMap.has(id)) {
                slotComponentsMap.set(id, new Map());
            }
            if (!((_a = slotComponentsMap.get(id)) === null || _a === void 0 ? void 0 : _a.has(slot))) {
                (_b = slotComponentsMap.get(id)) === null || _b === void 0 ? void 0 : _b.set(slot, []);
            }
            const component = React.forwardRef((props, ref) => (_jsx(ImplWrapper, Object.assign({ component: c, slotsMap: slotComponentsMap.get(c.id), targetSlot: { id, slot } }, params, props, { ref: ref }), void 0)));
            component.displayName = c.parsedType.name;
            (_d = (_c = slotComponentsMap.get(id)) === null || _c === void 0 ? void 0 : _c.get(slot)) === null || _d === void 0 ? void 0 : _d.push({
                component,
                id: c.id,
            });
        }
        !slotTrait && topLevelComponents.push(c);
    }
    return {
        topLevelComponents,
        slotComponentsMap,
    };
}
//# sourceMappingURL=resolveAppComponents.js.map