import AppInfo from '../../../src/pages/api-client/AppInfo.js';
import AuthenticateScreen from '../../../src/pages/api-client/Authenticate.screen.js';
import { WebStoreBindings } from '../../../src/bindings/web/WebStoreBindings.js';
import { WebConfigurationBindings } from '../../../src/bindings/web/WebConfigurationBindings.js';
import { EventTypes } from '../../../src/events/EventTypes.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 store = new WebStoreBindings(AppInfo, `http://localhost:8550/v1`);
  const config = new WebConfigurationBindings(AppInfo, configUri);

  const page = new AuthenticateScreen({
    store,
    config,
  });
  await page.initialize();

  window.addEventListener(EventTypes.Config.Environment.State.created, () => {
    // We mimic application behavior. This is in the first run flow.
    // We continue to the analytics consent screen.
    const url = new URL('/demo/pages/api-client/AnalyticsConsent.html', window.location.href).toString();
    navigatePage(url);
  });
})();
