'use strict';

var ContactController = angular.module('pages.controllers.contact', [
    'system'
])
    .controller('ContactController', [
        '$scope',
        '$timeout',
        '$location',
        '$route',
        '$locale',
        '$window',
        'Config',
        'System',
        'Global',
        '$routeParams',
        'PageService',
        'ContentService',
        '$sce',
        'NewslettersService',
        function ($scope, $timeout, $location, $window, $locale, $route, Config, System, Global, $routeParams, PageService, ContentService, $sce, NewslettersService) {
            System.Page.title("Contact");
            $scope.ui = {};
            $scope.newsletter = {};
            $scope.formp = {};
            $scope.init = function() {
                $scope.initialize('44.907110', '17.303310');
                $scope.formp = {};
            };

            $scope.initialize = function (la, lo) {
                if (la == null && lo == null) {
                    var lat = "44.907110";
                    var lon = "17.303310";
                }
                else
                {
                    lat = la;
                    lon = lo;
                }

                var styles = [
          {
              featureType: 'road.highway',
              elementType: 'geometry',
              stylers: [
                { hue: '#ff0022' },
                { saturation: 60 },
                { lightness: -20 }
              ]
          }, {
              featureType: 'road.arterial',
              elementType: 'all',
              stylers: [
                { hue: '#2200ff' },
                { lightness: -40 },
                { visibility: 'simplified' },
                { saturation: 30 }
              ]
          }, {
              featureType: 'road.local',
              elementType: 'all',
              stylers: [
                { hue: '#f6ff00' },
                { saturation: 50 },
                { gamma: 0.7 },
                { visibility: 'simplified' }
              ]
          }, {
              featureType: 'water',
              elementType: 'geometry',
              stylers: [
                { saturation: 40 },
                { lightness: 40 }
              ]
          }, {
              featureType: 'road.highway',
              elementType: 'labels',
              stylers: [
                { visibility: 'on' },
                { saturation: 98 }
              ]
          }, {
              featureType: 'administrative.locality',
              elementType: 'labels',
              stylers: [
                { hue: '#0022ff' },
                { saturation: 50 },
                { lightness: -10 },
                { gamma: 0.90 }
              ]
          }, {
              featureType: 'transit.line',
              elementType: 'geometry',
              stylers: [
                { hue: '#ff0000' },
                { visibility: 'on' },
                { lightness: -70 }
              ]
          }
                ];

                var options = {
                    mapTypeControlOptions: {
                        mapTypeIds: ['Styled']
                    },
                    center: new google.maps.LatLng(lat,lon),
                    zoom: 16,
                    disableDefaultUI: true,
                    mapTypeId: 'Styled'
                };
                var div = document.getElementById('map');
                var map = new google.maps.Map(div, options);
                var styledMapType = new google.maps.StyledMapType(styles, { name: 'Styled' });
                map.mapTypes.set('Styled', styledMapType);
                var iconBase = 'http://www.laktasi.net/Areas/cms/Style/images/';
                var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(lat,lon),
                    map: map,
                    icon: iconBase + 'marker.png',
                    shadow: iconBase + 'marker.png',
                    size: new google.maps.Size(5, 5)

                });

              
                var message = '<h5 style="padding:0px 0px 10px 0px !important;">Opština Laktaši</h5>' +
                    '<div style="width: 100%; height:100%;color:#25282A;">' +
                    '<p><b>Adresa:</b>Karađorđeva 56<br />' +
                    '<b>Grad:</b> Laktaši <br />' +
                    '<b>Oblast/Država:</b> Republika Srpska - Bosna i Hercegovina<br />' +
                   '</p><p>' +
                   '<b>Telefon:</b> Info - 051/334-200<br />' +
                    '</p>' +
                    '<a class="see-all" href="http://www.laktasi.net">' +
                   '<h5 style="color:#25282A;">web:http://www.laktasi.net</h5></a> ' +
                    '</div>';
                var infowindow = new google.maps.InfoWindow({ content: message });
                google.maps.event.addListener(marker, 'click', function () {
                    infowindow.open(marker.get('map'), marker);
                    google.maps.event.trigger(map, 'resize')
                });

            };

            
            System.Message.on($scope, function (e, message) {
                $scope.ui.alert = { type: message.type, text: message.value };
                $timeout(function () {
                    $scope.ui.alert = null;
                }, 10000);
            });
         

            $scope.sendMessage = function () {
                NewslettersService.sendMessage($scope.formp).then(function (response) {
                    if (response.Errors) {
                        $scope.errors = response.Errors;
                        System.Message.error('There was an error./Došlo je do greške');
                    } else {                 
                        System.Message.success('Successfully sent mail./Poruka uspješno poslana.');
                        $scope.init();
                    }
                });
            };
  
            $scope.init();
        }
    ]);