"use strict";
appCore.controller("WatchListMasterCtrl", ["$state", "$scope", "$http", "$timeout", "vServices", function ($state, $scope, $http, $timeout, vServices) {
    const accepted = ["skill", "designation", 'department', 'log type','certificatedomains','revenuecenter'];
    $scope.params = $state.params;
    $scope.$root.page.title = "Watchlist";
    $scope.dataList = [];
	$scope.managerOptions = [];
	$scope.tagOptions = [];
	$scope.heroes_id = [];
	$scope.data = [];
    
	vServices.callApi("watchlist/getAllManagers", "GET", {}).then((res) => {
        if (res && res.length > 0) {
          $scope.managerOptions = res;
          $scope.managerOptions.unshift({"employeeid": 0, "emp_first_name": "Select", "emp_last_name": ""});
        }
	})
	
	vServices.callApi("watchlist/watchlistTag_master", "GET", {}).then((res) => {
        if (res && res.length > 0) {
          $scope.tagOptions = res;
          $scope.tagOptions.unshift({"tag": "Select"});
        }
	})
	
    $scope.edit = (d) => {
        vServices.callApi("watchlist/tagWatchlistMaster/" + d.wtl_id + "/" + d.hero_id  , "PUT" , {}).then(function (res) {
            if (res) toastr.success(res, "Success!", {timeOut: 5000});
            $state.go($state.current, {}, {reload: true});
        });
    };

    $scope.delete = (d) => {
        vServices.callApi("watchlist/deleteWatchlistMaster/" + d.wtl_id + "/" + d.hero_id  , "PUT" , {}).then(function (res) {
            if (res) toastr.success(res, "Success!", {timeOut: 5000});
            $state.go($state.current, {}, {reload: true});
        });
    };
    $scope.add = (d) => {
        vServices.callApi("watchlist/addOrEditMaster/" + (d.wl_id ? "edit" : "add"), d.wl_id ? "PUT" : "POST", d).then(function (res) {
            if (res) toastr.success(res, "Success!", {timeOut: 5000});
            $state.go($state.current, {}, {reload: true});
        });
    };
    const init = function () {
            $scope.dataList = [];
            vServices.callApi("watchlist/watchlist_master", "GET", {}).then((res) => {
                $scope.dataList = res;
            });
        }
    ;

    init();

}
]);



