/**
 * Application entry point.
 *
 * This file includes `goog.require`'s for all the components/directives used
 * by the HTML page and the controller to provide the configuration.
 */

import angular from 'angular';
import gmfControllersAbstractMobileController, {AbstractMobileController} from 'gmf/controllers/AbstractMobileController.js';
import './sass/mobile_alt.scss';
import appBase from '../appmodule.js';
import EPSG2056 from '@geoblocks/proj/src/EPSG_2056.js';
import EPSG21781 from '@geoblocks/proj/src/EPSG_21781.js';
import olStyleFill from 'ol/style/Fill.js';
import olStyleRegularShape from 'ol/style/RegularShape.js';
import olStyleStroke from 'ol/style/Stroke.js';
import olStyleStyle from 'ol/style/Style.js';
import Raven from 'raven-js/src/raven.js';
import RavenPluginsAngular from 'raven-js/plugins/angular.js';

if (!window.requestAnimationFrame) {
  alert('Your browser is not supported, please update it or use another one. You will be redirected.\n\n'
    + 'Votre navigateur n\'est pas supporté, veuillez le mettre à jour ou en utiliser un autre. Vous allez être redirigé.\n\n'
    + 'Ihr Browser wird nicht unterstützt, bitte aktualisieren Sie ihn oder verwenden Sie einen anderen. Sie werden weitergeleitet.');
  window.location = 'http://geomapfish.org/';
}

class Controller extends AbstractMobileController {
  /**
   * @param {angular.IScope} $scope Scope.
   * @param {angular.auto.IInjectorService} $injector Main injector.
   * @ngInject
   */
  constructor($scope, $injector) {
    super({
      autorotate: true,
      mapPixelRatio: 1,
      srid: 21781,
      mapViewConfig: {
        center: [632464, 185457],
        zoom: 3,
        resolutions: [250, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.25, 0.1, 0.05]
      }
    }, $scope, $injector);

    /**
     * @type {Array.<import("gmf/mobile/measure.js").default.pointComponent.LayerConfig>}
     * @export
     */
    this.elevationLayersConfig = [
      {name: 'aster', unit: 'm'},
      {name: 'srtm', unit: 'm'}
    ];

    /**
     * @type {number}
     * @export
     */
    this.searchDelay = 50;

    /**
     * @type {Array.<string>}
     * @export
     */
    this.searchCoordinatesProjections = [EPSG21781, EPSG2056, 'EPSG:4326'];


    /**
     * @type {import("ol/style/Style.js").default}
     * @export
     */
    this.customMeasureStyle = new olStyleStyle({
      fill: new olStyleFill({
        color: 'rgba(255, 128, 128, 0.2)'
      }),
      stroke: new olStyleStroke({
        color: 'rgba(255, 0, 0, 0.5)',
        lineDash: [10, 10],
        width: 2
      }),
      image: new olStyleRegularShape({
        stroke: new olStyleStroke({
          color: 'rgba(255, 0, 0, 0.7)',
          width: 2
        }),
        points: 4,
        radius: 8,
        radius2: 0,
        angle: 0
      })
    });

    if ($injector.has('sentryUrl')) {
      const options = $injector.has('sentryOptions') ? $injector.get('sentryOptions') : undefined;
      const raven = new Raven();
      raven.config($injector.get('sentryUrl'), options)
        .addPlugin(RavenPluginsAngular)
        .install();
    }
  }
}

const module = angular.module('Appmobile_alt', [
  appBase.name,
  gmfControllersAbstractMobileController.name,
]);

module.controller('AlternativeMobileController', Controller);

export default module;
