// VARIAVES PARA O LOAD BUTTON
var textLoad = "<i class='fa fa-circle-o-notch fa-spin'></i>";
var textButton = '';
var btn = null;
var $qtd_leads = $('.qtd_leads').data('qtd_leads');

//$('#btn_enviar_whats').on('click', function(e){
$('#form_enviar_whats').submit(function(e) {
e.preventDefault();
    
    loadButton($('#btn_salvar_msg_whats'));
    
    $data = getForm('#form_enviar_whats');
    
    console.log($data);
    
    if($qtd_leads != 0){
        if(confirm("Deseja salvar as configurações de mensagem?")){
            get_ajax_($data, 'administrativo/ajax/Incorporadora_ajax/salvarConfigMensagem', 
            success =>{
                if(success.success == true){
                    $('.result_whats').html('');
                    
                    $('.result_whats').append('<div class="alert alert-primary alert-dismissible fade show" role="alert"> '+success.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
                    
                    $('.btn_enviar_whats').show();
                }
                else{
                    $('.result_whats').html('');
                    
                    $('.result_whats').append('<div class="alert alert-danger alert-dismissible fade show" role="alert"> '+success.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
                }
            },
            error =>{
                console.log(error);
                $('.result_whats').html('');
                    
                $('.result_whats').append('<div class="alert alert-danger alert-dismissible fade show" role="alert"> '+error.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
            }
            );
        }
        else{
            alert("Operação cancelada!");
            loadButton(null,false);
        }
    }
    else
    {
        alert("Sem leads para esse evento!");
        loadButton(null,false);
    }
    
});

$('#btn_enviar_whats').on('click', function(e){
e.preventDefault();
    
    loadButton($('#btn_enviar_whats'));
    
    $data = getForm('#form_enviar_whats');
    
    console.log($data);
    
    if($qtd_leads != 0){
        if(confirm("Deseja enviar mensagem de whatsapp para os "+$qtd_leads+" Leads?")){
            get_ajax_($data, 'administrativo/ajax/Incorporadora_ajax/enviarWhatsLista', 
            success =>{
                if(success.success == true){
                    $('.result_whats').html('');
                    
                    $('.result_whats').append('<div class="alert alert-primary alert-dismissible fade show" role="alert"> '+success.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');

                }
                else{
                    $('.result_whats').html('');
                    
                    $('.result_whats').append('<div class="alert alert-danger alert-dismissible fade show" role="alert"> '+success.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
                }
            },
            error =>{
                console.log(error);
                $('.result_whats').html('');
                    
                $('.result_whats').append('<div class="alert alert-danger alert-dismissible fade show" role="alert"> '+error.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
            }
            );
        }
        else{
            alert("Operação cancelada!");
            loadButton(null,false);
        }
    }
    else
    {
        alert("Sem leads para esse evento!");
        loadButton(null,false);
    }
    
});


$('#form_enviar_email').submit(function(e) {
e.preventDefault();
    
    loadButton($('#btn_enviar_email'));
    
    $data = getForm('#form_enviar_email');
    
    console.log($data);
    
    if($qtd_leads != 0){
        if(confirm("Deseja enviar email para os "+$qtd_leads+" Leads?")){
            get_ajax_($data, 'administrativo/ajax/Incorporadora_ajax/enviarEmailLista', 
            success =>{
                if(success.success == true){
                    $('.result_email').html('');
                    
                    $('.result_email').append('<div class="alert alert-primary alert-dismissible fade show" role="alert"> '+success.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');

                }
                else{
                    $('.result_email').html('');
                    
                    $('.result_email').append('<div class="alert alert-danger alert-dismissible fade show" role="alert"> '+success.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
                }
            },
            error =>{
                console.log(error);
                $('.result_email').html('');
                    
                $('.result_email').append('<div class="alert alert-danger alert-dismissible fade show" role="alert"> '+error.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
            }
            );
        }
        else{
            alert("Operação cancelada!");
            loadButton(null,false);
        }
    }
    else
    {
        alert("Sem leads para esse evento!");
        loadButton(null,false);
    }
    
});