import {BrowserModule} from '@angular/platform-browser';
import {ErrorHandler, LOCALE_ID, NgModule} from '@angular/core';

import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MatToolbarModule} from "@angular/material/toolbar";
import {FlexLayoutModule} from "@angular/flex-layout";
import {MatButtonModule} from "@angular/material/button";
import {AppLoginComponent, AppLoginRecoverDialogComponent} from "./app.login.component";
import {AppIndexComponent} from "./app.index.component";
import {MatCardModule} from "@angular/material/card";
import {MAT_SNACK_BAR_DEFAULT_OPTIONS, MatSnackBarModule} from "@angular/material/snack-bar";
import {registerLocaleData} from "@angular/common";
import localeRu from '@angular/common/locales/ru'
import {HTTP_INTERCEPTORS, HttpClientModule} from "@angular/common/http";
import {MatFormFieldModule} from "@angular/material/form-field";
import {MatInputModule} from "@angular/material/input";
import {FormsModule} from "@angular/forms";
import {MatIconModule} from "@angular/material/icon";
import {PersonService} from "./person/person.service";
import {JwtModule} from "@auth0/angular-jwt";
import {NgxInitModule} from "ngx-init";
import {PersonCreditDialogComponent, PersonDebitDialogComponent, PersonFirstRunDialogComponent, PersonPageComponent} from "./person/person.page.component";
import {MatListModule} from "@angular/material/list";
import {AccountService} from "./bank/account/account.service";
import {MatProgressBarModule} from "@angular/material/progress-bar";
import {BankService} from "./bank/bank.service";
import {MAT_TOOLTIP_SCROLL_STRATEGY, MatTooltipModule} from "@angular/material/tooltip";
import {NoopScrollStrategy} from "@angular/cdk/overlay";
import {MatDialogModule} from "@angular/material/dialog";
import {MatSelectModule} from "@angular/material/select";
import {MatSliderModule} from "@angular/material/slider";
import {MatRadioModule} from "@angular/material/radio";
import {MatCheckboxModule} from "@angular/material/checkbox";
import {DefaultErrorHandler} from "./misc/default.error.handler";
import {PendingIndicator, PendingSnackBar} from "./misc/pending.indicator";
import {OrgService} from "./org/org.service";
import {TextMaskModule} from 'angular2-text-mask';
import {RxStompService} from "@stomp/ng2-stompjs";
import {PrivotalPageComponent} from "./org/privotal.page.component";
import {LabeledComponent} from "./misc/labeled.component";
import {ElsePipe} from "./misc/else.pipe";
import * as _ from "underscore";

registerLocaleData(localeRu);

export function jwtTokenGetter() {
  return localStorage.token
}

@NgModule({
  declarations: [
    AppComponent, AppLoginComponent, AppIndexComponent, PersonPageComponent, PersonDebitDialogComponent, PendingSnackBar, PersonCreditDialogComponent, PrivotalPageComponent, LabeledComponent, ElsePipe, PersonFirstRunDialogComponent, AppLoginRecoverDialogComponent
  ],
  entryComponents: [
    PersonDebitDialogComponent, PendingSnackBar, PersonCreditDialogComponent, PersonFirstRunDialogComponent, AppLoginRecoverDialogComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    MatToolbarModule,
    FormsModule,
    FlexLayoutModule,
    MatButtonModule,
    MatCardModule,
    HttpClientModule,
    MatSnackBarModule,
    MatFormFieldModule,
    MatInputModule,
    MatIconModule,
    NgxInitModule,
    TextMaskModule,
    JwtModule.forRoot({
      config: {
        tokenGetter: jwtTokenGetter,
        whitelistedDomains: ["127.0.0.1", "localhost", "77.244.213.167"],
        blacklistedRoutes: [],
      },
    }),
    MatListModule,
    MatProgressBarModule,
    MatTooltipModule,
    MatDialogModule,
    MatSelectModule,
    MatSliderModule,
    MatRadioModule,
    MatCheckboxModule,
  ],
  providers: [
    PersonService,
    AccountService,
    BankService,
    OrgService,
    {provide: ErrorHandler, useClass: DefaultErrorHandler},
    {provide: LOCALE_ID, useValue: "ru-RU"},
    {provide: MAT_SNACK_BAR_DEFAULT_OPTIONS, useValue: {duration: 2500}},
    {provide: MAT_TOOLTIP_SCROLL_STRATEGY, useValue: () => new NoopScrollStrategy()},
    {
      provide: HTTP_INTERCEPTORS,
      useClass: PendingIndicator,
      multi: true
    },
    {
      provide: "_",
      useValue: _
    },
    RxStompService
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}
