import { WebConfigurationBindings } from '../../../src/bindings/web/WebConfigurationBindings.js';
import { WebStoreBindings } from '../../../src/bindings/web/WebStoreBindings.js';
import { EventTypes } from '../../../src/events/EventTypes.js';
import AppInfo from '../../../src/pages/api-client/AppInfo.js';
import TelemetryScreen from '../../../src/pages/api-client/Telemetry.screen.js';
import { navigatePage } from '../../../src/lib/route.js';

const configUri = new URL('/demo/lib/io/AppConfig.ts', import.meta.url).toString();

(async (): Promise<void> => {
  const config = new WebConfigurationBindings(AppInfo, configUri);
  const store = new WebStoreBindings(AppInfo, `http://localhost:8550/v1`);
  const page = new TelemetryScreen({ config, store });
  await page.initialize();

  window.addEventListener(EventTypes.Config.Telemetry.State.set, () => {
    // We mimic application behavior. This is in the first run flow.
    // When this event is handled we continue to the application main page.
    const url = new URL('/demo/pages/api-client/main.html', window.location.href).toString();
    navigatePage(url);
  });
})();
