import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';

import {APP_CONFIG, AppConfig} from './config/app.config';

import {AppRoutingModule} from './app-routing.module';
import {SharedModule} from './shared/modules/shared.module';
import {CoreModule} from './core/core.module';
import {HashLocationStrategy, LocationStrategy} from '@angular/common';

import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';

import {AppComponent} from './app.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {HTTP_INTERCEPTORS, HttpClient, HttpClientModule} from '@angular/common/http';
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {HttpLoaderFactory} from './app.translate.factory';
import {LoginComponent} from './login/login.component';
import {HomeComponent} from './home/home.component';
import {CategoriesComponent} from './categories/categories.component';
import {PasswordComponent} from './password/password.component';
import {ProductsComponent} from './products/products.component';
import {ProductComponent} from './products/product.component';
import {ToolbarComponent} from './core/toolbar/toolbar.component';
import {CartComponent} from './cart/cart.component';
import {SpecialsComponent} from './specials/specials.component';
import {SearchComponent} from './search/search.component';
import {ListsComponent} from './lists/lists.component';
import {ListComponent} from './lists/list.component';
import {CartService} from './core/cart.service';
import {AlertService} from './core/alert.service';
import {AuthenticationService} from './core/authentication.service';
import {ProgressBarService} from './core/progress-bar.service';
import {ProgressInterceptor} from './shared/interceptors/progress.interceptor';
import {TimingInterceptor} from './shared/interceptors/timing.interceptor';
import {
    MatTableModule, MatToolbarModule,
    MatSidenavModule, MatTabsModule, MatSelectModule,
    MatCheckboxModule, MatDatepickerModule, MatNativeDateModule
} from '@angular/material';
import {AuthGuard} from './core/guards/auth.guard';
import {AlertComponent} from './directives/alert.component';
import {AutofocusDirective} from './directives/autofocus';

AppConfig.relativeURL = window.location.pathname;

// See the Moment.js docs for the meaning of these formats:
// https://momentjs.com/docs/#/displaying/format/
export const MY_FORMATS = {
    parse: {
        dateInput: 'Y-MM-DD',
    },
    display: {
        dateInput: 'Y-MM-DD',
        monthYearLabel: 'YYYY MMM',
        dateA11yLabel: 'LL',
        monthYearA11yLabel: 'YYYY MMMM',
    },
};

@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        FormsModule,
        HttpClientModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: HttpLoaderFactory,
                deps: [HttpClient]
            }
        }),
        SharedModule.forRoot(),
        CoreModule,
        MatTableModule,
        MatToolbarModule,
        MatSidenavModule,
        MatTabsModule,
        MatSelectModule,
        MatCheckboxModule,
        MatDatepickerModule,
        MatNativeDateModule,
        AppRoutingModule
    ],
    declarations: [
        AlertComponent,
        AppComponent,
        LoginComponent,
        ToolbarComponent,
        HomeComponent,
        CartComponent,
        SpecialsComponent,
        SearchComponent,
        ProductsComponent,
        ProductComponent,
        CategoriesComponent,
        ListsComponent,
        ListComponent,
        PasswordComponent,
        AutofocusDirective
    ],
    providers: [
        AuthGuard,
        AlertService,
        AuthenticationService,
        CartService,
        {provide: APP_CONFIG, useValue: AppConfig},
        {provide: HTTP_INTERCEPTORS, useClass: ProgressInterceptor, multi: true, deps: [ProgressBarService]},
        {provide: HTTP_INTERCEPTORS, useClass: TimingInterceptor, multi: true},
        {provide: LocationStrategy, useClass: HashLocationStrategy},
        {provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
        {provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
    ],
    entryComponents: [
        AlertComponent,
    ],
    bootstrap: [AppComponent]
})

export class AppModule {
}
