"use strict";
appCore.controller("ShoutOutListCtrl", ["$state", "$scope", "$http", "$timeout", "vServices", "$uibModal", "$document",
    function ($state, $scope, $http, $timeout, vServices, $uibModal, $document) {
      $scope.$root.page.title = "List of shout out";
      $scope.shouts = [];
      $scope.shout = [];
	  
	$scope.deleteContact = (id) => {
        //alert(id);
        vServices.callApi("shoutout/delete/" + id, "DELETE", {}).then(function (res) {
          if (res) {
            toastr.success(res, "Success");
            $state.go($state.current, {}, {reload: true});
          }
        });
      };
	  
	  
      const init = function () {
        vServices.callApi("shoutout/all_data", "GET", {}).then(function (res) {
          if (res && res.length > 0) {
            $scope.shouts = res;
			//console.log($scope.appreciations);
            $scope.$root.callDataTable("#shoutList");
          }
        });
      };
	  
	  
/* 	   $scope.ok = () => {       
          vServices.callApi("clientappreciations/update", "PUT", $scope.appreciation).then((res) => {
				// console.log($scope.appreciation);
                 if (res && typeof res === 'string') {
                     toastr.success(res, "Success!", {timeOut: 5000});
                     $state.go("ClientAppreciationlList", {}, {reload: true});
                 } else {
                     toastr.error("Edit not working", "Not Working", {timeOut: 5000});
                 }
             });
        
    } */
	  
      init();
	  
$scope.clickRow = function(res) {
  $scope.shouts = res
};

 /* Model code start*/
      $scope.updateCaModel = (obj) => {
        let modalInstance = $uibModal.open({
          animation: true,
          ariaLabelledBy: "modal-title",
          ariaDescribedBy: "modal-body",
          templateUrl: "UpdateCa.html",
          controller: "UpdateCaCtrl",
          controllerAs: "$scope",
          size: "sm",//sm md lg
          backdrop: "static",
          resolve: {
            data: () => {
              return {
                shout: obj
              };
            }
          }
        });

        modalInstance.result.then((data) => {
          $scope.deleteContact(data.shout.id);
        }, () => {
          toastr.warning("Action has been canceled", "Cancel");
        });
      };      
	  
	  $scope.viewImgModel = (obj) => {
        let modalInstance = $uibModal.open({
          animation: true,
          ariaLabelledBy: "modal-title",
          ariaDescribedBy: "modal-body",
          templateUrl: "Viewimg.html",
          controller: "UpdateCaCtrl",
          controllerAs: "$scope",
          size: "lg",//sm md lg
          backdrop: "static",
          resolve: {
            data: () => {
              return {
                shout: obj
              };
            }
          }
        });
      };
      /* Model code end*/

    }
  ])
 
 
 .controller("UpdateCaCtrl", function ($uibModalInstance, data, $scope) {
    $scope.shout = data;
	
	//console.log($scope.appreciation);
    $scope.ok = () => $uibModalInstance.close($scope.shout);
    $scope.cancel = () => $uibModalInstance.dismiss("cancel");
  });
  
  
  
