"use strict";
appCore.controller("AclProfileListCtrl", ["$state", "$scope", "$http", "$timeout", "vServices",
  function ($state, $scope, $http, $timeout, vServices) {
    $scope.$root.page.title = "ACL Profile";
    $scope.btn = {text: "Save"};
    $scope.cCode = ["primary", "success", "warning", "danger", "indigo", "navy", "purple", "maroon", "lime", "teal", "olive", "orange", "fuchsia"];
    // TODO To make this dynamic
    $scope.aclList = [];

    $scope.aclProfileClone = (data) => {
      const _html = `Do you really want to create clone ?`;
      $scope.$root.prompt(_html, 'Clone operation has been canceled!').then(result => {
        if (result) {
          data.profile_name = data.profile_name + ' - Cloned';
          delete data.$$hashKey;
          delete data.id;
          if(data.profile_name.length > 50){
            toastr.error('Error','Profile name cannot be more than 50 characters.');
          }else{
            vServices.callApi("acl/addProfile" , "POST",data).then(function (res) {
              if (res) toastr.success(res, "Success!", {timeOut: 5000});
              $state.go($state.current, {}, {reload: true});
            });
          }
        }
      });
    }

    const init = function () {
      vServices.callApi("acl/aclProfileList", "GET", {}).then(function (res) {
        if (res && res.length > 0) {
          $scope.aclList = res;
          $scope.$root.callDataTable("#aclList");
        }
      });
    };
    init();
  }
]);



