(function (app) {
    app
        .controller('DetalleStakeHolderController', function ($scope, $http, $rootScope, SweetAlert, spsservice, $uibModal, $location, id, $route) {


           
            $scope.bloqueo = true;
          

            var getStakeHolder = spsservice.get_type('lists/getbytitle', 'Stakeholder', "/Items?$select=Relevancia,OtraComuna,Operacion,Organizacion,ID,Title,Telefono,Email,Vigente,Descripcion,DireccionUrl,Direccion,Tipoo,Categoria,Rol,Comuna&$filter=Id eq " + id);
            getStakeHolder.then(function (resp_sup) {
                if (resp_sup.d.results.length > 0) {
                    $scope.stakeholder = resp_sup.d.results[0];

                    debugger;
                   
                    $rootScope.comunasUsuarioData = $rootScope.comunasUsuario.filter(x => x.Zona == $scope.stakeholder.Operacion || x.Zona == "");


                }
            });


            $scope.modificarStakeholder = function () {
              
        

                debugger;

                var url = "lists/getbytitle('Stakeholder')/items(" + $scope.stakeholder.ID + ")";
                var data = {
                  '__metadata': {
                    'type': 'SP.Data.StakeholderListItem'
                  },
                  'Title': $scope.stakeholder.Title,
                  'Telefono': $scope.stakeholder.Telefono,
                  'Email': $scope.stakeholder.Email,
                  'Rol': $scope.stakeholder.Rol,
                  'DireccionUrl': $scope.stakeholder.DireccionUrl,
                  // 'Tipoo': $scope.stakeholder.Tipoo.Valor,
                  'Descripcion': $scope.stakeholder.Descripcion,
                  // 'Organizacion': $scope.person.selected == null ? "" : $scope.person.selected.Title,
                  'Operacion': $scope.stakeholder.Operacion,
                  'Comuna': $scope.stakeholder.Comuna,
                  'OtraComuna': $scope.stakeholder.OtraComuna,
                  'Categoria': $scope.stakeholder.Categoria == null ? "" : $scope.stakeholder.Categoria,
                  'Relevancia': $scope.stakeholder.Relevancia

                //   stakeholder.Relevancia
                };
        
                 spsservice.put_data(url, data).then(function () {
                    //$scope.actualizarInformacionAsunto($rootScope.actividadesModal, $rootScope.asuntoModal.ID);
                    // alert("MODIFICACION OK");
                    $rootScope.ObtenerStackeholders();
                    SweetAlert.swal("Stakeholder modificado.", "", "success");
                    $route.reload();
                });
        
        
              }


            $scope.obtenerTiposAsuntos = function (data) {
                $rootScope.tipoAsuntosProgramaData = $rootScope.tipoAsuntosData.filter(x => x.programa == data);
            }


            // $matches = [];

            // preg_match("/@(.*?),(.*?),/",$str,$matches);

            // $place = $matches[1];

            // preg_match("/@(.*?),(.*?),/",$str,$matches);

            // $lat = $matches[1];
            // $long = $matches[2];

            // echo '<iframe src="https://www.google.com/maps/embed/v1/place?q='.$place.'&center='.$lat.','.$long.'&key=AIzaSyAN0om9mFmy1QN6Wf54tXAowK4eT0ZUPrU&zoom=8" frameborder="0"></iframe>';


            


        });

}(angular.module('spsmodule')));