require( ["SHARED/jquery", "ticketMenuControllers"], function ( $,  ticketMenuControllers)
{   function initializeCustomerRateListener() {
        var rateIndicator = document.getElementsByClassName("rateIndic");
        var switchdiv = document.getElementsByClassName('switch')[0];
        if( rateIndicator != null ){
		  for(var i=0; i < rateIndicator.length ; i++) {
			rateIndicator[i].addEventListener("click", function() {
			  if(switchdiv != null) {
			  document.getElementById('ticketMenu').scrollIntoView();
			  switchdiv.style.animation='pulse 1s infinite';
			  setTimeout(function() { switchdiv.style.animation=null; },5000);
			}
		 });
		  }
        }

        if ( window.location.href.includes("#csrate")) {
            if(switchdiv != null) {
                document.getElementById('ticketMenu').scrollIntoView();
                switchdiv.style.animation='pulse 1s infinite';
                setTimeout(function() { switchdiv.style.animation=null; },5000);
            }
            history.pushState({}, null, window.location.href.replace(/#csrate$/,""));
        }
    }

    $( document ).ready(function() {
        var ticketMenuAppRoot = $('#ticketMenu');
        var ticketMenuApp = angular.module('ticketsChartsApp', ['ngSanitize']);
        ticketMenuApp.filter('decodeStr', function($sce) {
                        return function (str) {
                        if( str == null ){
                        return $sce.trustAsHtml("");
                        }
                        var textArea = document.createElement('textarea');
                        textArea.innerHTML = str;
                        return $sce.trustAsHtml(textArea.innerText);
                        }
                        });
        try {
            ticketMenuApp.controller('ticketMenuCtrl', ticketMenuControllers);
            angular.bootstrap(ticketMenuAppRoot, ['ticketsChartsApp']);
        } catch(e) {
            console.log(e);
        }
        initializeCustomerRateListener();
});
});
