import { NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { environment } from '../environments/environment';

import { registerLocaleData } from '@angular/common';
import zh from '@angular/common/locales/zh';
registerLocaleData(zh);

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { NgCortexService, NgCortexModule } from '@ng-cortex/core';
import { NcRegisterComponent } from './nc-register/nc-register.component';
import { NcLoginComponent } from './nc-login/nc-login.component';
import { NcE403Component } from './nc-e403/nc-e403.component';
import { NcE404Component } from './nc-e404/nc-e404.component';
import { NcE500Component } from './nc-e500/nc-e500.component';
import { NcLayoutComponent } from './nc-layout/nc-layout.component';
import { NcHeadComponent } from './nc-head/nc-head.component';
import { NcSideComponent } from './nc-side/nc-side.component';
import { NcReuseTabComponent } from './nc-reuse-tab/nc-reuse-tab.component';
import { NcHomeComponent } from './nc-home/nc-home.component';
import { NcAppListComponent } from './nc-app-list/nc-app-list.component';
import { NcAccountComponent } from './nc-account/nc-account.component';
import { NcBridgeComponent } from './nc-bridge/nc-bridge.component';
import { NcMenuFormatPipe } from './nc-menu-format.pipe';
import { NcSafeUrlPipe } from './nc-safe-url.pipe';

@NgModule({
  declarations: [
    AppComponent,
    NcRegisterComponent,
    NcLoginComponent,
    NcE403Component,
    NcE404Component,
    NcE500Component,
    NcLayoutComponent,
    NcHeadComponent,
    NcSideComponent,
    NcReuseTabComponent,
    NcHomeComponent,
    NcAppListComponent,
    NcAccountComponent,
    NcBridgeComponent,
    NcMenuFormatPipe,
    NcSafeUrlPipe
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    BrowserAnimationsModule,
    AppRoutingModule,
    NgCortexModule.forRoot()
  ],
  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: (ncSrv: NgCortexService) => () => ncSrv.init(environment.configUrl).toPromise(),
      deps: [NgCortexService],
      multi: true
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
