// (C) 2021-2026 GoodData Corporation
import { LIB_VERSION } from "../__version.js";
import { Dashboard } from "../presentation/dashboard/Dashboard.js";
import { DashboardCustomizationBuilder } from "./customizationApis/customizationBuilder.js";
import { DefaultDashboardEventHandling } from "./customizationApis/dashboardEventHandling.js";
import { pluginDebugStr } from "./customizationApis/pluginUtils.js";
/**
 * A factory function to obtain an instance of {@link IDashboardEngine}.
 *
 * @remarks
 * This is the main, well-known entry point to the Dashboard Engine that is used during both static and dynamic
 * loading of the dashboard engine instances by the DashboardLoader.
 *
 * @public
 */
export function newDashboardEngine() {
    return {
        version: LIB_VERSION,
        initializePlugins(ctx, plugins) {
            const customizationBuilder = new DashboardCustomizationBuilder();
            const eventRegistration = new DefaultDashboardEventHandling();
            // eslint-disable-next-line no-console
            console.debug(`DashboardEngine ${this.version} initializing with plugins: ${plugins
                .map(pluginDebugStr)
                .join(", ")}`);
            customizationBuilder.setWidgetOverlays(ctx.config?.widgetsOverlay);
            for (const plugin of plugins) {
                customizationBuilder.onBeforePluginRegister(plugin);
                try {
                    plugin.register(ctx, customizationBuilder, eventRegistration);
                    customizationBuilder.onAfterPluginRegister();
                }
                catch (e) {
                    customizationBuilder.onPluginRegisterError(e);
                }
            }
            const extensionProps = customizationBuilder.build();
            const eventingProps = eventRegistration.getDashboardEventing();
            return {
                ...extensionProps,
                ...eventingProps,
            };
        },
        getDashboardComponent() {
            return Dashboard;
        },
    };
}
//# sourceMappingURL=engine.js.map