export interface WidgetDefinition {
    name: string;
    component: any;
}

export function getWidgetDefinition(
    window: any = globalThis.window
): WidgetDefinition {
    const widgetNames = Object.keys(window).filter(
        name =>
            name.match(/integration\//) && window[name].hasOwnProperty("Widget")
    );

    if (widgetNames.length) {
        const name: string = widgetNames[0];
        return {
            name: name.substring(name.lastIndexOf("/") + 1),
            component: window[name].Widget
        };
    }

    throw new Error("widget definition not found");
}
