'use strict'

angular.module('RECRUIT').controller('NotiEmailConfig', function ($scope, $mdDialog, RecService, $log, SwapLang) {
  $scope.lang = getLang()
  $scope.isEditTitle = []
  $scope.notiEmail = {}
  $scope.HrSwlang = SwapLang
  $scope.init = function () {
    RecService.ManageConfig.query({cname: 'NOTIEMAIL'}).$promise.then(function (data) {
      $scope.notiEmail = data.result
    })
  }
  $scope.init()

  $scope.addEmail = () => {
    $scope.notiEmail.object.email.push({
      name: 'Title',
      to: '',
      cc: ''
    })
  }
  $scope.removeEmail = ($index) => {
    $scope.notiEmail.object.email.splice($index, 1)
  }

  $scope.submit = function () {
    $scope.HrSwlang.getConfirm(1).then(function () {
      RecService.ManageConfig.save($scope.notiEmail).$promise.then(function () {
        $scope.HrSwlang.getAlert(18).then(function () {
          $scope.init()
        })
      }, function () {
        $scope.HrSwlang.getAlert(17)
      });
    })
  };
})