(function(){
    'use srict';
    app.controller('EditSecond', ['$rootScope', '$scope', function($rootScope, $scope){
        $rootScope.$on('EditSecondComment', function(event, comments, mainId, secondId){
            
            for (let i = 0; i < comments.length; i++) {
                for (let j = 0; j < comments[i].secondComments.length; j++) {

                    if (comments[i].secondComments[j].mainId === mainId) {
                       
                        if (comments[i].secondComments[j].id === secondId) {
                           $scope.editSecondCommetById = comments[i].secondComments[j]
                        }
                    }
                        
                }
                
            }
        });
        $scope.saveSecondEdit = function(){
            $rootScope.$emit('SaveSecondEdit', $scope.editSecondCommetById, $scope.editSecondCommetById.mainId, $scope.editSecondCommetById.id);
        };
        $scope.cancelSecondEdit = function(){
            $rootScope.$emit('CancelSecondEdit', $scope.editSecondCommetById.mainId, $scope.editSecondCommetById.id);
        };
    }])
})()