﻿$(document).ready(function () {
    var $notificationWrp = ("#NotificationInHdr")
    if ($notificationWrp.length != 0) {
        var appNotifications = angular.module("NotificationApp", ['ngRoute']);

        appNotifications.controller("NotificationController", ["$scope", "$window", "$http", function ($scope, $window, $http) {

            $scope.FriendsRequestCount = 0;
            $scope.ShowFriendsNotification = 0;
            $scope.FriendsLargeNumberCss = '';

            $scope.MailCount = 0;
            $scope.ShowMailNotification = 0;
            $scope.MailLargeNumberCss = '';

            $scope.init = function (memberId) {
                $scope.memberId = memberId;
                $http.get('/api/notification/GetFriendsRegusts?memberId=' + $scope.memberId).success(function (data, status, headers, config) {
                    $scope.FriendsRequestCount = data;
                    if ($scope.FriendsRequestCount > 0) {
                        if ($scope.FriendsRequestCount > 99) {
                            $scope.FriendsRequestCount = '99+';
                            $scope.FriendsLargeNumberCss = 'btn_count_large';
                        }

                        $scope.ShowFriendsNotification = 1;
                    }
                    else {
                        $scope.ShowFriendsNotification = 0;
                    }
                }).error(function (data, status, headers, config) {
                    console.log("Error with notification data: /api/notification/GetFriendsRegustse")
                });

              
                $http.get('/api/notification/GetMailCount?memberId=' + $scope.memberId).success(function (data, status, headers, config) {
                    $scope.MailCount = data;

                    if ($scope.MailCount > 0) {
                        if ($scope.MailCount > 99) {
                           $scope.MailCount = '99+'
                           $scope.MailLargeNumberCss = 'btn_count_large';                          
                        }
                        $scope.ShowMailNotification = 1;
                    }
                    else {
                        $scope.ShowMailNotification = 0;
                    }
                }).error(function (data, status, headers, config) {
                    console.log("Error with notification  data: /api/notification/GetFriendsRegustse")
                });
            };



        }]);

        angular.bootstrap(document.getElementById("NotificationInHdr"), ['NotificationApp']);
    }
});