import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { getWidgetName, getContainerFromCurrentScript, createConfig } from 'widget'
import { configureAjaxHelper } from 'ajax_helper';
import { setPolicy } from 'policy';

let widgetName = getWidgetName(__dirname)
let scriptTagContainer = getContainerFromCurrentScript(widgetName)
let ajaxConfig = createConfig(scriptTagContainer.scriptParams, widgetName).ajaxHelper

configureAjaxHelper(ajaxConfig)

setPolicy()

ReactDOM.render(<App />, scriptTagContainer.reactContainer);

@@ -251,16 +251,375 @@
 licy';%0A%0A
+const createNewConfig = (widgetName, scriptParams) =%3E %7B%0A  // // document is not loaded yet -%3E create a new Promise and resolve it as soon%0A  // // as document is loaded.%0A  return new Promise((resolve, reject) =%3E %7B%0A    document.addEventListener('DOMContentLoaded', () =%3E %7B%0A      resolve(createConfig(widgetName, scriptTagContainer.scriptParams))%0A    %7D)%0A  %7D)%0A%7D%0A%0A
 let widg
@@ -723,38 +723,36 @@
 me)%0A
-let ajaxConfig = 
 create
+New
 Config(
+widgetName, 
 scri
@@ -782,80 +782,99 @@
 rams
-, widgetName).ajaxHelper%0A%0AconfigureAjaxHelper(ajaxConfig)%0A%0AsetPolicy()%0A%0A
+).then((config) =%3E %7B%0A  configureAjaxHelper(config.ajaxHelper)%0A  setPolicy(config.policy)%0A  
 Reac
@@ -930,8 +930,11 @@
 ainer);%0A
+%7D)%0A

load policy once the document is ready (#667)