(function(){
    angular.module("app.collect")
        .controller("collectCtrl",["$rootScope","$scope","$state","ToolService","$timeout",collectCtrl]);

    function collectCtrl($rootScope,$scope,$state,ToolService,$timeout){
        var meauTree = {
            "analysis":["campaigninfo","channeleffect","attribute","effectevaluate","roi","keyword","packageinfo"],
            "decisionsupport":["paymentinsight","potentialusergroup","device"],
            "campaignmanager":["campaign","campgroup","datacb","onelink","sublink","subpackage"],
            "export":["logexport","logdump","logtool","report","subcampaign"],
            "eventmanage":["event","profile"]
        };
        $scope.getSubMenu = function(menu){
            if(menu == 'custommenu'){
                if($rootScope.isSuper && $scope.ctmMenuList.length == 0){
                    ToolService.showAlp();
                    $rootScope.tipCustom = true;
                    return false;
                }
            }
           
            if($scope.subflag == menu && $state.current && $state.current.name!=menu){
                $scope.subflag = "";
            }else{
                $scope.subflag = menu;
            }
            $rootScope.custID = "";
            
            // $timeout(function(){
            //     $(".leftSidebar").perfectScrollbar("update");
            // },100);
        }

        $scope.closeTip = function(){
            $rootScope.tipCustom = false;
            ToolService.hideAlp();
        }
        $scope.okCust = function(){
            $scope.goPage('collect.custommenu');
            $scope.closeTip();
        }
        
        $rootScope.$watch("pagePath",function(n){
            if(angular.isDefined(n)){
                $scope.subflag = "";
                var idx = n.indexOf("Detail");
                if(idx>-1){
                    n = n.substring(0,n);
                }
                for(var k in meauTree){
                    var ms = meauTree[k];
                    if(ms.indexOf(n)>-1){
                        $scope.subflag = k;
                        break;
                    }
                }

                if(n == 'custommenu'){
                     $scope.subflag = n;
                }
            }
             
        });

        // $(".leftSidebar").perfectScrollbar();
    }
})();