/**
 * Created by k.danovsky on 13.05.2016.
 */

(function () {
  'use strict';

  angular.module('Monitour.theme')
    .config(config);

  /** @ngInject */
  function config(baConfigProvider, $translateProvider, $httpProvider, $locationProvider, colorHelper, $provide, cfpLoadingBarProvider) {
      $locationProvider.html5Mode(true);
      $translateProvider
          .useLocalStorage()
          .useStaticFilesLoader({
              prefix: 'assets/language/',
              suffix: '.json'
          })
          .useSanitizeValueStrategy('sanitize')
          .preferredLanguage('en_US')
          .fallbackLanguage(['en_US',  'ar'])
          .determinePreferredLanguage();
      $translateProvider.forceAsyncReload(true);

      // remember language
      $translateProvider.useLocalStorage();

	  $httpProvider.defaults.useXDomain = true;

	  delete $httpProvider.defaults.headers.common['X-Requested-With'];



     $provide.decorator('$uiViewScroll', uiViewScrollDecorator);


    cfpLoadingBarProvider.includeSpinner = false;
    cfpLoadingBarProvider.latencyThreshold = 1;
  }

  /** @ngInject */
  function uiViewScrollDecorator($delegate, $anchorScroll, baUtil) {
    return function (uiViewElement) {
      if (baUtil.hasAttr(uiViewElement, "autoscroll-body-top")) {
        $anchorScroll();
      } else {
        $delegate(uiViewElement);
      }
    };
  }
})();
