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

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { FitNavigationComponent } from './components/fit-navigation/fit-navigation.component';
import { FitSlidesComponent } from './components/fit-slides/fit-slides.component';
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
import {CollapseModule, TypeaheadModule} from "ngx-bootstrap";
import { HomeComponent } from './pages/home/home.component';
import { LoginComponent } from './pages/login/login.component';
import { ProfileComponent } from './pages/profile/profile.component';
import { JwtInterceptor, ErrorInterceptor } from './_helpers';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import {ReactiveFormsModule} from "@angular/forms";
import { EventsComponent } from './pages/events/events.component';
import { FitEventTypesComponent } from './components/fit-event-types/fit-event-types.component';

import {APP_BASE_HREF, PlatformLocation, registerLocaleData} from '@angular/common';
import localeHu from '@angular/common/locales/hu';
import {FontAwesomeModule} from "@fortawesome/angular-fontawesome";
import { library } from '@fortawesome/fontawesome-svg-core';

import { faUserPlus , faUserMinus } from '@fortawesome/free-solid-svg-icons';
import { FitWeekdaySelectorComponent } from './components/fit-weekday-selector/fit-weekday-selector.component';
import { MonthCalendarComponent } from './components/month-calendar/month-calendar.component';
import { MonthCalendarDayComponent } from './components/month-calendar-day/month-calendar-day.component';
import { MonthCalendarEventComponent } from './components/month-calendar-event/month-calendar-event.component';
import { EventDetailsComponent } from './pages/event-details/event-details.component';
import { RegistrationsComponent } from './pages/registrations/registrations.component';
import { RegistrationComponent } from './pages/registration/registration.component';
import { GuestLayoutComponent } from './layout/guest-layout/guest-layout.component';
import { SecuredLayoutComponent } from './layout/secured-layout/secured-layout.component';
import { PasswordChangeComponent } from './pages/password-change/password-change.component';
import {ToastrModule} from "ngx-toastr";
import {NgxsModule} from "@ngxs/store";
import {environment} from "../environments/environment";
import {AppState} from "./state/app.state";
import {NgxsReduxDevtoolsPluginModule} from "@ngxs/devtools-plugin";
import {NgxsLoggerPluginModule} from "@ngxs/logger-plugin";
import { EventDatePipe } from './pipes/event-time.pipe';



// the second parameter 'fr' is optional
registerLocaleData(localeHu, 'hu');


@NgModule({
  declarations: [
    AppComponent,
    FitNavigationComponent,
    FitSlidesComponent,
    HomeComponent,
    LoginComponent,
    ProfileComponent,
    EventsComponent,
    FitEventTypesComponent,
    FitWeekdaySelectorComponent,
    MonthCalendarComponent,
    MonthCalendarDayComponent,
    MonthCalendarEventComponent,
    EventDetailsComponent,
    RegistrationsComponent,
    RegistrationComponent,
    GuestLayoutComponent,
    SecuredLayoutComponent,
    PasswordChangeComponent,
    EventDatePipe,
  ],
  imports: [

    BrowserModule,
    AppRoutingModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    CollapseModule.forRoot(),
    HttpClientModule,
    TypeaheadModule.forRoot(),
    FontAwesomeModule,
    BrowserAnimationsModule, // required animations module
    ToastrModule.forRoot(), // ToastrModule added

    NgxsModule.forRoot([AppState], {
      developmentMode: !environment.production
    }),
    NgxsReduxDevtoolsPluginModule.forRoot(),
    NgxsLoggerPluginModule.forRoot({disabled: true})
  ],
  providers: [
    { provide: LOCALE_ID, useValue: "hu-hu" },
    { provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
    { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
    {
      provide: APP_BASE_HREF,
      useFactory: getBaseHref,
      deps: [PlatformLocation]
    }
    // provider used to create fake backend
    // fakeBackendProvider
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
  constructor(){
    library.add(faUserPlus);
    library.add(faUserMinus);
  }

}

export function getBaseHref(platformLocation: PlatformLocation): string {
  return platformLocation.getBaseHrefFromDOM();
}
