import {NgModule, ModuleWithProviders} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {RouterModule} from '@angular/router';
import {TranslateModule} from '@ngx-translate/core';
import {ToastrModule} from 'ngx-toastr';

import {AccordionModule} from 'ngx-bootstrap/accordion';
import {AlertModule} from 'ngx-bootstrap/alert';
import {ButtonsModule} from 'ngx-bootstrap/buttons';
import {CarouselModule} from 'ngx-bootstrap/carousel';
import {CollapseModule} from 'ngx-bootstrap/collapse';
import {BsDropdownModule} from 'ngx-bootstrap/dropdown';
import {ModalModule} from 'ngx-bootstrap/modal';
import {PaginationModule} from 'ngx-bootstrap/pagination';
import {ProgressbarModule} from 'ngx-bootstrap/progressbar';
import {RatingModule} from 'ngx-bootstrap/rating';
import {TabsModule} from 'ngx-bootstrap/tabs';
import {TimepickerModule} from 'ngx-bootstrap/timepicker';
import {TooltipModule} from 'ngx-bootstrap/tooltip';
import {PopoverModule} from 'ngx-bootstrap/popover';
import {TypeaheadModule} from 'ngx-bootstrap/typeahead';
import {DatepickerModule} from 'ngx-bootstrap/datepicker';
import {BsDatepickerModule} from 'ngx-bootstrap/datepicker';

import {ColorsService} from './colors/colors.service';
import {CheckallDirective} from './directives/checkall/checkall.directive';
import {NowDirective} from './directives/now/now.directive';
import {NgxLoadingModule} from "ngx-loading";
import {FrameAjax} from "../core/frame/ajax/frame-ajax/frame-ajax";
import {FramePager} from "../core/frame/pager/frame-pager/frame-pager";
import {FrameDictPipe} from "./pipes/frame.dict";
import {FrameStatusPipe} from "./pipes/frame.status";
import {FrameStylePipe} from "./pipes/frame-style.pipe";
import {NumberArrayPipe} from "./pipes/number-array.pipe";
import {FrameStatusCustomPipe} from "./pipes/frame-status-custom.pipe";
import {FrameSumPipe} from "./pipes/frame-sum.pipe";
import {ArrayFilterPipe} from "./pipes/array-filter.pipe";
import {AttrFilterPipe} from "./pipes/attr-filter.pipe";
import {SecurityHtmlPipe} from "./pipes/security.html";
import {FormValid} from "../core/frame/valid/form-valid";
import {NgxSelectModule} from "ngx-select-ex";
import {TreeModule} from "@circlon/angular-tree-component";
import {FrameRoleDirective} from "./directives/frame/role/frame.role";
import {FrameDictDirective} from "./directives/frame/dict/frame.dict";
import {FrameUpload} from "../core/frame/upload/frame-upload/frame-upload";
import {FileUploadModule} from "ng2-file-upload";
import {NgxEchartsModule} from "ngx-echarts";
import {ColorPickerModule} from "ngx-color-picker";
import { NgxViewerModule } from 'ngx-viewer';

// https://angular.io/styleguide#!#04-10
@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    TranslateModule,
    AccordionModule.forRoot(),
    AlertModule.forRoot(),
    ButtonsModule.forRoot(),
    CarouselModule.forRoot(),
    CollapseModule.forRoot(),
    DatepickerModule.forRoot(),
    BsDatepickerModule.forRoot(),
    BsDropdownModule.forRoot(),
    ModalModule.forRoot(),
    PaginationModule.forRoot(),
    ProgressbarModule.forRoot(),
    RatingModule.forRoot(),
    TabsModule.forRoot(),
    TimepickerModule.forRoot(),
    TooltipModule.forRoot(),
    PopoverModule.forRoot(),
    TypeaheadModule.forRoot(),
    ColorPickerModule,
    ToastrModule.forRoot({
      positionClass: 'toast-bottom-right',
      autoDismiss: true,
      closeButton: true,
      timeOut: 3000,
      maxOpened: 3
    }),
    NgxLoadingModule.forRoot({}),
    NgxSelectModule,
    FileUploadModule,
    NgxViewerModule,
    NgxEchartsModule.forRoot({
      echarts: () => import('echarts')
    })

  ],
  providers: [
    ColorsService
  ],
  declarations: [
    CheckallDirective,
    NowDirective,
    FrameRoleDirective,
    FrameDictDirective,
    // Pipe
    FrameDictPipe,
    FrameStatusPipe,
    FrameStylePipe,
    NumberArrayPipe,
    FrameStatusCustomPipe,
    FrameSumPipe,
    ArrayFilterPipe,
    AttrFilterPipe,
    SecurityHtmlPipe,

    // Ajax
    FrameAjax,
    FramePager,
    FrameUpload,
    FormValid
  ],
  exports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    TranslateModule,
    RouterModule,
    AccordionModule,
    AlertModule,
    ButtonsModule,
    CarouselModule,
    CollapseModule,
    DatepickerModule,
    BsDatepickerModule,
    BsDropdownModule,
    ModalModule,
    PaginationModule,
    ProgressbarModule,
    RatingModule,
    TabsModule,
    TimepickerModule,
    TooltipModule,
    PopoverModule,
    TypeaheadModule,
    ToastrModule,
    NgxSelectModule,
    TreeModule,
    FileUploadModule,
    NgxEchartsModule,
    ColorPickerModule,

    CheckallDirective,
    NowDirective,
    FrameRoleDirective,

    // Pipe
    FrameDictPipe,
    FrameStatusPipe,
    FrameStylePipe,
    NumberArrayPipe,
    FrameStatusCustomPipe,
    FrameSumPipe,
    ArrayFilterPipe,
    AttrFilterPipe,
    SecurityHtmlPipe,
    FrameDictDirective,

    FrameAjax,
    FramePager,
    FrameUpload,
    FormValid,
    NgxViewerModule
  ]
})

// https://github.com/ocombe/ng2-translate/issues/209
export class SharedModule {
  static forRoot(): ModuleWithProviders<any> {
    return {
      ngModule: SharedModule
    };
  }
}
