import { NgModule } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { PipesModule } from '@shared/pipes/pipes.module';
import { ToolkitModule } from '@toolkit/toolkit.module';
import {
    TranslateModule,
    TranslateLoader,
    TranslatePipe,
} from '@ngx-translate/core';

import { TranslateHttpLoaderFactory } from '@shared/factories';
import {
    TzOffsetPipe,
    DurationPipe,
    DayChangePipe,
    AirportTerminalPipe,
    CodesharingPipe,
    FlightNumberPipe,
    TransferTypePipe,
    StationChangePipe,
    LegDurationPipe,
} from './pipes-legacy';
import {
    ScrollContainerDirective,
    ScrollToDirective,
    ScrollUpDirective,
} from './scroll-to/scroll-to.directive';
import { LocalisationReadyDirective } from './localisation-ready/localisation-ready.directive';
import { MetaTagsDirective } from './seo';

const pipes = [
    TzOffsetPipe,
    DurationPipe,
    DayChangePipe,
    AirportTerminalPipe,
    CodesharingPipe,
    FlightNumberPipe,
    TransferTypePipe,
    StationChangePipe,
    LegDurationPipe,
];

const directives = [
    ScrollContainerDirective,
    ScrollToDirective,
    ScrollUpDirective,
    LocalisationReadyDirective,
    MetaTagsDirective,
];

@NgModule({
    declarations: [...directives, ...pipes],
    imports: [
        CommonModule,
        FormsModule,
        ReactiveFormsModule,
        RouterModule,
        TranslateModule.forChild({
            loader: {
                provide: TranslateLoader,
                useFactory: TranslateHttpLoaderFactory,
                deps: [HttpClient],
            },
            isolate: false,
        }),
        ToolkitModule,
        PipesModule,
    ],
    exports: [TranslateModule, ...directives, ...pipes, PipesModule],
    providers: [TranslatePipe, DurationPipe],
})
export class SharedModule {}
