import HttpProjectScreen from '../../../src/pages/http-project/HttpProject.screen.js';
import { WebHttpClientStoreBindings } from '../../../src/bindings/web/WebHttpClientStoreBindings.js';
import { WebNavigationBindings } from '../../../src/bindings/web/WebNavigationBindings.js';
import { WebConfigurationBindings } from '../../../src/bindings/web/WebConfigurationBindings.js';
import { WebProxyBindings } from '../../../src/bindings/web/WebProxyBindings.js';
import * as MonacoLoader from '../../../src/monaco/loader.js';
import AppInfo from '../../../src/pages/http-project/AppInfo.js';
import env from '../../env.js';
import { WebStoreBindings } from '../../../src/bindings/web/WebStoreBindings.js';

const idbWorker = new URL('/src/http-client/store/IdbThread.ts', import.meta.url).toString();
const demoConfigWorker = new URL('/demo/lib/io/AppConfig.ts', import.meta.url).toString();

(async (): Promise<void> => {
  const base = `../../../node_modules/monaco-editor/`;
  MonacoLoader.createEnvironment(base);
  await MonacoLoader.loadMonaco(base);
  await MonacoLoader.monacoReady();
  
  const navigation = new WebNavigationBindings(AppInfo);
  const proxy = new WebProxyBindings(AppInfo, env.proxyUri, { authenticate: true });
  const config = new WebConfigurationBindings(AppInfo, demoConfigWorker);
  const idb = new WebHttpClientStoreBindings(AppInfo, idbWorker);
  const store = new WebStoreBindings(AppInfo, `http://localhost:8550/v1`);
  const page = new HttpProjectScreen({
    store,
    proxy,
    idb,
    config,
    navigation,
  });
  await page.initialize();
})();
