$(function () {

  	$('.button_delete_modal').on('click', function() {

  		var id = $(this).data("id");
  	
  		$('#delete_modal').modal({
  			closable: false,
		    onApprove : function() {
		    	sendDelete(id);
		    }
  		}).modal('show');  
  	});		  

  	function sendDelete(id) {

	    var data = {id_cliente : id};

        $.requestApi('/cliente/eliminar', data, 'POST', function (resolve) {
	        if (resolve) {
                if (resolve.message === "success") {
                    $('[data-table="'+id+'"]').remove();         
                }
	            $.showMessages(resolve);
	        }
	    });
        
        return false;
	};

    $('.button_info_modal').on('click', function() {

        var id = $(this).data("id");
        var data = {id_cliente : id};
        $.requestApi('/cliente/getById', data, 'POST', function (resolve) {
            if (resolve) {
                $('#_1').text(resolve.nombre); 
                $('#_2').text(resolve.tipo_documento ? resolve.tipo_documento.nombre : ''); 
                $('#_3').text(resolve.numero_documento); 
                $('#_4').text(resolve.direccion); 
                $('#_5').text(resolve.telefono); 
                $('#_6').text(resolve.email); 
    
                $('#detalles_modal').modal('show'); 
            }
        });
    });       

    $('.btn_reporte').on('click', function() {
        window.open(APP_URL+'/../pdf/listaClientes.php', '_blank');
    });
 
});	