import * as React from 'react';
import { getWidgetDefinition } from './widget-definition';
import { WidgetContainer } from '@talentsoft-opensource/integration-widget-component';
import { getAppService } from './app-service';

export function WidgetHost() {
    const params: Record<string, string> = getQueryStringParams();
    const definition = getWidgetDefinition(window);
    const appService = getAppService(definition);
    
    return <WidgetContainer
        appService={appService}
        appid={definition.name}
        bodyComponent={definition.component}
        isMobile={false}
        name={definition.name}
        params={params}
    />
}


function getQueryStringParams() {
    const params: Record<string, string> = {};
    const urlParams = new URLSearchParams(window.location.search);
    urlParams.forEach((v, k) => {
        params[k] = v;
    });
    return params;
}
