import * as _angular_ from 'angular';

declare global {
  const angular: typeof _angular_;
}

//
// NEEDED CHANGES FOR WEBPACK
//
// 1. Remove external files
// 2. Use pathes relative to node_modules
//

import 'angular-i18n/angular-locale_de-de.js'
import 'angular-animate/angular-animate.min.js';
import 'angular-youtube-embed/dist/angular-youtube-embed.min.js';
// import 'https://www.youtube.com/iframe_api';
import 'angular-spinkit/build/angular-spinkit.min.js';
// import 'angular-route/angular-route.min.js';
// import 'angular-material/angular-material.min.js';
import 'angular-material/modules/js/core/core.js';
import 'angular-material/modules/js/backdrop/backdrop.js';
import 'angular-material/modules/js/sidenav/sidenav.js';
import 'angular-material/modules/js/icon/icon.js';
import 'angular-material/modules/js/tabs/tabs.js';
import 'angular-utils-pagination/dirPagination.js';

import { MainController } from './core/main.controller';

//
// IMPORT MODULES INSTEAD OF SINGLE DEPENDENCIES
// =============================================================================
//
import { APPLICATION_ENV } from './core/environment';
import { SearchModule } from './search/search.module';
import { PictureModule } from './picture/picture.module';
import { WidgetsModule } from './widgets/widgets.module';
import { ButtonModule } from './button/button.module';
import { BrowserSupportModule } from './browser-support/browser-support.module';
import { TileModule } from './tile/tile.module';
import { CarouselModule } from './carousel/carousel.module';
import { IconModule } from './icon/icon.module';
import { ToolbarModule } from './toolbar/toolbar.module';
import { NewsModule } from './news/news.module';
import { SparepartsModule } from './spareparts/spareparts.module';
import { DownloadsModule } from './downloads/downloads.module';
import { PaginationModule } from './pagination/pagination.module';
import { DealerModule } from './dealer/dealer.module';

//
// LAZYSIZES INIT
// =============================================================================
//
import { Lazysizes } from './config/Lazysizes';
Lazysizes.configure();

window['APPLICATION_ENV'] = APPLICATION_ENV;

//
// DEFINE ANGULAR MODULE
// =============================================================================
//
export const MODULE_COMPONENTS = angular
  .module('beyer-components', [
    'ngAnimate',
    // 'ngRoute',
    'material.components.sidenav',
    'material.components.tabs',
    'angular-spinkit',
    'youtube-embed',
    'angularUtils.directives.dirPagination',
    SearchModule.name,
    PictureModule.name,
    WidgetsModule.name,
    ButtonModule.name,
    TileModule.name,
    CarouselModule.name,
    IconModule.name,
    ToolbarModule.name,
    NewsModule.name,
    SparepartsModule.name,
    DownloadsModule.name,
    PaginationModule.name,
    DealerModule.name,
    BrowserSupportModule.name
  ])
  .controller('MainController', MainController)
  .filter('trustedUrl', ['$sce', function ($sce) {
    return function(url) {
      return $sce.trustAsResourceUrl(url);
    };
  }])
  .filter('trustedHtml', ['$sce', function ($sce) {
    return function(html) {
      return $sce.trustAsHtml(html);
    };
  }])
  .value('API_URL', (window['APPLICATION_ENV'] === 'development') ? 'https://stage.beyer-testsystem.de' : `//${location.hostname}/`)
  .value('API_PRODUCTS_ENDPOINT', (window['APPLICATION_ENV'] === 'development') ? 'rest/V1/productList' : 'rest/V1/productList')
;
