"use strict";
appCore.controller("RequisitionCommentCtrl", ["$state", "$scope", "$http", "$timeout", "vServices", function ($state, $scope, $http, $timeout, vServices) {
    $scope.params = $state.params;
    $scope.$root.page.title = "Template";
    $scope.currentUser      = $scope.$root.gUser;
    $scope.req_detail_id    = $scope.params.reqDetail_id;
    $scope.params           = $state.params;
    $scope.$root.page.title = "Manage Commenting"

    $scope.page = {
            allow: false,
            name: "Requisition",
            type: "Comment",
            group:'Salesforce', 
            icon: "fa-users", 
            color: "purple"
        };

        $scope.reset = () => {
            $scope.req = {comment: ''};
            // $scope.page.type = "Submit";
        };

   
    $scope.commentList= [];
    $scope.req = {
        comment : '',
    };

    $scope.add = () => 
    {
        // console.log($scope.req);
        // $scope.req.raised_on = $scope.$root.convertDate2DateTimeUTC($scope.req.raised_on);
        $scope.req.req_detail_id = $scope.req_detail_id;
        $scope.req.created_at    = $scope.$root.convertDate2DateTimeUTC(moment().format('DD-MM-YYYY'));
        vServices.callApi("requisition/submitComment", "POST", $scope.req).then(function (res){
            if (res) toastr.success( "Success!", {timeOut: 5000});
            $state.go($state.current, {}, {reload: true});
        });
    };
    
    
    
    
    const init = function () {
        // $scope.page;
        console.log($scope.params);
        vServices.callApi("requisition/getAllcomment?rdi="+$scope.req_detail_id, "GET").then(function (res){
            if(res){
                res.comment.forEach(element => {
                    element.icon = element.emp_first_name.charAt(0);
                    element.class = element.created_by==$scope.currentUser.id?'end':'start';
                });
                console.log(res);
                $scope.commentList= res.comment;
            }
            $scope.hero= res.hero;

        });
        
    };
    init();

}
]);



