import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
import { useMemo } from 'react';
import { createApplication } from '@meta-ui/core';
import { initStateAndMethod } from './utils/initStateAndMethod';
import { ImplWrapper } from './services/ImplWrapper';
import { resolveAppComponents } from './services/resolveAppComponents';
import { DebugEvent, DebugStore } from './services/DebugComponents';
export function genApp(services) {
    return (props) => {
        return _jsx(App, Object.assign({}, props, { services: services }), void 0);
    };
}
export const App = props => {
    const { options, services, componentWrapper, gridCallbacks, debugStore = true, debugEvent = true, } = props;
    const app = createApplication(options);
    initStateAndMethod(services.registry, services.stateManager, app.spec.components);
    const { topLevelComponents, slotComponentsMap } = useMemo(() => resolveAppComponents(app.spec.components, {
        services,
        app,
        componentWrapper,
        gridCallbacks,
    }), [app]);
    return (_jsxs("div", Object.assign({ className: "App" }, { children: [topLevelComponents.map(c => {
                return (_jsx(ImplWrapper, { component: c, services: services, slotsMap: slotComponentsMap.get(c.id), targetSlot: null, app: app, componentWrapper: componentWrapper, gridCallbacks: gridCallbacks }, c.id));
            }), debugStore && _jsx(DebugStore, { stateManager: services.stateManager }, void 0), debugEvent && _jsx(DebugEvent, { apiService: services.apiService }, void 0)] }), void 0));
};
//# sourceMappingURL=App.js.map