import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'reflect-metadata';
import 'zone.js';
import app from './app-js';
import {
  APP_BOOTSTRAP_LISTENER,
  ApplicationRef,
  ComponentRef,
  NgModule,
} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {TranslateModule} from '@ngx-translate/core';
import {UpgradeModule} from '@angular/upgrade/static';

import {BootstrapComponent} from 'hslayers-ng/bootstrap.component';
import {HsCoreModule} from 'hslayers-ng/components/core/core.module';

import {AdjusterModule} from './adjuster';
import {AppService} from './app.service';

@NgModule({
  imports: [
    BrowserModule,
    UpgradeModule,
    HsCoreModule,
    AdjusterModule,
    TranslateModule,
  ],
  exports: [],
  declarations: [],
  providers: [
    {
      provide: APP_BOOTSTRAP_LISTENER,
      multi: true,
      useFactory: () => {
        return (component: ComponentRef<BootstrapComponent>) => {
          //When ng9 part is bootstrapped continue with AngularJs modules
          component.instance.upgrade.bootstrap(
            document.documentElement,
            [app.name],
            {strictDi: true}
          );
        };
      },
    },
    AppService,
  ],
})
export class AppModule {
  constructor() {}
  ngDoBootstrap(appRef: ApplicationRef): void {
    //First bootstrap Angular 9 app part on hs element
    appRef.bootstrap(BootstrapComponent);
  }
}
