import {BrowserModule, DomSanitizer} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {RouterModule} from '@angular/router';
import {NgModule, ViewContainerRef} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {HttpClientModule, HttpClient} from '@angular/common/http';
import {HttpModule} from '@angular/http';
import {CookieService} from 'ngx-cookie-service';
import {NgxJsonapiModule} from 'ngx-jsonapi';
import {
  MatAutocompleteModule, MatDatepickerModule,
  MatDialogModule,
  MatIconRegistry,
  MatInputModule, MatNativeDateModule
} from '@angular/material';
import {ReactiveFormsModule} from '@angular/forms';
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {PerfectScrollbarModule} from 'ngx-perfect-scrollbar';
import {PERFECT_SCROLLBAR_CONFIG} from 'ngx-perfect-scrollbar';
import {PerfectScrollbarConfigInterface} from 'ngx-perfect-scrollbar';

import {
  MatSidenavModule,
  MatCardModule,
  MatMenuModule,
  MatCheckboxModule,
  MatIconModule,
  MatButtonModule,
  MatToolbarModule,
  MatTabsModule,
  MatListModule,
  MatSlideToggleModule,
  MatSelectModule,
  MatProgressBarModule,
  MatGridListModule
} from '@angular/material';
import {FlexLayoutModule} from '@angular/flex-layout';
import {BidiModule} from '@angular/cdk/bidi';
import {
  MenuComponent,
  HeaderComponent,
  SidebarComponent,
  NotificationComponent,
  OptionsComponent,
  AdminLayoutComponent,
  AuthLayoutComponent,
  AccordionAnchorDirective,
  AccordionLinkDirective,
  AccordionDirective
} from './core';
import {AppRoutes} from './app.routing';
import {AppComponent} from './app.component';
import {AuthService} from './classes/auth.service';
import {ListComponent} from './classes/base_components/list/list.component';
import {DialogComponent} from './classes/base_components/dialog/dialog.component' ;
import {Dialog} from './classes/dialog';
import {NgxSpinnerService} from 'ngx-spinner';
import {LoadingModule} from 'ngx-loading';
import {EditUsersComponent} from './components/user/users/edit-users/edit-users.component';
import {UsersService} from './components/user/users/users.service';
import {RolesService} from './components/user/roles/roles.service';
import {EditRolesComponent} from './components/user/roles/edit-roles/edit-roles.component';
import {EditComponent} from './classes/base_components/edit/edit.component';
import {PermissionGroupsService, PermissionsService} from './components/user/permissions/permissions.service';
import {ServicesService} from './components/basic/services/services.service';
import {ProductsService} from './components/basic/products/products.service';
import {TypesService} from './components/basic/types/types.service';
import {EditProductComponent} from './components/basic/products/edit-product/edit-product.component';
import {EditServicesComponent} from './components/basic/services/edit-services/edit-services.component';
import {EditTypesComponent} from './components/basic/types/edit-types/edit-types.component';
import {EditPermissionsComponent} from './components/user/permissions/edit-permissions/edit-permissions.component';
import {AgmCoreModule} from '@agm/core';
import {DocService} from './classes/doc.service';
import {MatRadioModule} from '@angular/material/radio';
import {MatChipsModule} from '@angular/material/chips';
import {NgxDatatableModule} from '@swimlane/ngx-datatable';
import {GlobalService} from './classes/global.service';
import {environment} from '../environments/environment';
import {SelectedComponent} from './components/auth/selected/selected.component';
import {MatTooltipModule} from '@angular/material/tooltip';
import {ToasterModule, ToasterService} from 'angular5-toaster/dist';
import {AngularFireModule} from '@angular/fire';
import {AngularFireDatabaseModule} from '@angular/fire/database';
import {AngularFireAuthModule} from '@angular/fire/auth';
import {NumberPickerModule} from '@retailify/ngx-mat-numberpicker';
import {MessageService} from './classes/message.service';
import {CentersService} from './classes/center.service';
import {AppsService} from './classes/apps.service';
import {MessagingService} from './classes/messaging.service';

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
  suppressScrollX: true,
  wheelSpeed: 2,
  wheelPropagation: true,
  minScrollbarLength: 20
};

@NgModule({
  declarations: [
    SelectedComponent,
    EditPermissionsComponent,
    EditTypesComponent,
    EditServicesComponent,
    EditProductComponent,
    EditComponent,
    EditRolesComponent,
    EditUsersComponent,
    AppComponent,
    HeaderComponent,
    SidebarComponent,
    NotificationComponent,
    OptionsComponent,
    MenuComponent,
    AdminLayoutComponent,
    AuthLayoutComponent,
    AccordionAnchorDirective,
    AccordionLinkDirective,
    AccordionDirective,
    ListComponent,
    DialogComponent,
  ],
  imports: [
    MatGridListModule,
    NumberPickerModule,
    MatNativeDateModule,
    MatDatepickerModule,
    BrowserAnimationsModule,
    ToasterModule,
    AngularFireModule.initializeApp({
      apiKey: 'AIzaSyCzrKn-mozOkz3Eh1dm9K1iZbO2A8RxWLU',
      authDomain: 'hpennurse.firebaseapp.com',
      databaseURL: 'https://hpennurse.firebaseio.com',
      projectId: 'hpennurse',
      storageBucket: 'hpennurse.appspot.com',
      messagingSenderId: '628214501041'
    }),
    AngularFireDatabaseModule,
    AngularFireAuthModule,
    LoadingModule.forRoot({
      backdropBackgroundColour: 'rgba(0,0,0,0.1)',
      backdropBorderRadius: '4px',
      primaryColour: '#0000ff',
      secondaryColour: '#0000ff',
      tertiaryColour: '#0000ff'
    }),
    NgxDatatableModule,
    MatAutocompleteModule,
    MatChipsModule,
    MatRadioModule,
    AgmCoreModule.forRoot({apiKey: 'AIzaSyDwvNEVZT6CNth_aJEM0uhTf8ksbDjNQIw'}),
    LoadingModule,
    ReactiveFormsModule,
    MatInputModule,
    MatDialogModule,
    HttpModule,
    NgxJsonapiModule.forRoot({
      url: environment.app_url,
    }),
    BrowserModule,
    RouterModule.forRoot(AppRoutes),
    FormsModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    }),
    MatSidenavModule,
    MatCardModule,
    MatMenuModule,
    MatCheckboxModule,
    MatIconModule,
    MatButtonModule,
    MatToolbarModule,
    MatTabsModule,
    MatListModule,
    MatSlideToggleModule,
    MatSelectModule,
    MatProgressBarModule,
    FlexLayoutModule,
    BidiModule,
    PerfectScrollbarModule,
    MatTooltipModule,
  ],
  providers: [
    MessagingService,
    AppsService,
    CentersService,
    MessageService,
    ToasterService,
    DocService,
    GlobalService,
    UsersService,
    CookieService,
    AuthService,
    NgxSpinnerService,
    Dialog,
    RolesService,
    PermissionsService,
    PermissionGroupsService,
    TypesService,
    ProductsService,
    ServicesService,
    {
      provide: PERFECT_SCROLLBAR_CONFIG,
      useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG,

    },
  ],

  bootstrap: [AppComponent],
  entryComponents: [
    SelectedComponent,
    EditPermissionsComponent,
    EditTypesComponent,
    EditServicesComponent,
    DialogComponent,
    EditComponent,
    EditUsersComponent,
    EditRolesComponent,
    EditProductComponent,
  ]
})
export class AppModule {
  url;

  constructor(matIconRegistry: MatIconRegistry, domSanitizer: DomSanitizer, private global: GlobalService) {
    matIconRegistry.addSvgIconSet(domSanitizer.bypassSecurityTrustResourceUrl('./assets/mdi.svg'));
    // Or whatever path you placed mdi.svg at\
  }
}
