jQuery(document).ready(function($){
     console.log('ConfigMenu.js Ready...')
	 
     $('#btn-gamanet-save-config-integrations').click(function(evt){
		 console.log("save-config-integrations");
		 evt.preventDefault();		 
		 $.ajax({
			 url:gama_obj.url,
			 method:'POST',
			 dataType:'json',
			 data:{
				   action:'save-config-integrations',
				   nonce:gama_obj.sec,
				   cf7_metabox:$('#cf7_metabox').val(),
				   wpforms_process_complete:$('#wpforms_process_complete').val(),
				   wpforms_process_complete_template:$('#wpforms_process_complete_template').val(),
				   wc_notif_new_order:$('#wc_notif_new_order').val(),
				   wc_notif_new_order_template:$('#wc_notif_new_order_template').val(),
				   wc_notif_new_order_self:$('#wc_notif_new_order_self').val(),
				   wc_notif_new_order_self_template:$('#wc_notif_new_order_self_template').val(),
				   wc_notif_created_customer:$('#wc_notif_created_customer').val(),
				   wc_notif_created_customer_template:$('#wc_notif_created_customer_template').val(), 
				   wc_notif_created_customer_self:$('#wc_notif_created_customer_self').val(),
				   wc_notif_created_customer_self_template:$('#wc_notif_created_customer_self_template').val(),
				   wc_notif_created_customer_add_db:$('#wc_notif_created_customer_add_db').val(),
				   wc_notif_created_customer_add_db_group_id:$('#wc_notif_created_customer_add_db_group_id').val(),	   
				   edd_notif_new_order:$('#edd_notif_new_order').val(),
				   edd_notif_new_order_template:$('#edd_notif_new_order_template').val(),
				   gamasms_publish_post:$('#gamasms_publish_post').val(),
				   gamasms_publish_post_template:$('#gamasms_publish_post_template').val(),
				   gamasms_comment_post:$('#gamasms_comment_post').val(),
				   gamasms_comment_post_template:$('#gamasms_comment_post_template').val(),
				   wpforms_process_complete_send_to:$('#wpforms_process_complete_send_to').val(),
				   wpforms_process_complete_send_to_subscribes_group_id:$('#wpforms_process_complete_send_to_subscribes_group_id').val(),	   
				   gamasms_publish_post_send_to:$('#gamasms_publish_post_send_to').val(),
				   gamasms_publish_post_send_to_subscribes_group_id:$('#gamasms_publish_post_send_to_subscribes_group_id').val(),
				   gamasms_comment_post_send_to:$('#gamasms_comment_post_send_to').val(),
				   gamasms_comment_post_send_to_subscribes_group_id:$('#gamasms_comment_post_send_to_subscribes_group_id').val(),
                   gform_after_submission:$('#gform_after_submission').val(),
                   gform_after_submission_send_to:$('#gform_after_submission_send_to').val(),
                   gform_after_submission_send_to_subscribes_group_id:$('#gform_after_submission_send_to_subscribes_group_id').val(),
                   gform_after_submission_template:$('#gform_after_submission_template').val(),
				   gform_after_submission_forms:$('#gform_after_submission_forms').val(),
				   gform_after_submission_forms_ids:$('#gform_after_submission_forms_ids').val(),
				   wc_notif_processing_order:$('#wc_notif_processing_order').val(),
				   wc_notif_processing_order_template:$('#wc_notif_processing_order_template').val(),
				   wc_notif_cancelled_order:$('#wc_notif_cancelled_order').val(),
				   wc_notif_cancelled_order_template:$('#wc_notif_cancelled_order_template').val(),
				   wc_notif_completed_order:$('#wc_notif_completed_order').val(),
				   wc_notif_completed_order_template:$('#wc_notif_completed_order_template').val(),
				   wc_notif_pending_order:$('#wc_notif_pending_order').val(),
				   wc_notif_pending_order_template:$('#wc_notif_pending_order_template').val(),
				   wc_notif_failed_order:$('#wc_notif_failed_order').val(),
				   wc_notif_failed_order_template:$('#wc_notif_failed_order_template').val(),
				   wc_notif_refunded_order:$('#wc_notif_refunded_order').val(),
				   wc_notif_refunded_order_template:$('#wc_notif_refunded_order_template').val(),
				   wc_notif_note_order:$('#wc_notif_note_order').val(),
				   wc_notif_note_order_template:$('#wc_notif_note_order_template').val()
				 
			 },success: function(data){
				 //console.log(data.result + "1.1")
				 if(data.error){
					 $('#result-config-integrations').replaceWith("<span id='result-config-integrations'><p><div class='alert alert-danger' role='alert'>" + data.result + "</div></p></span>");
				 }else{
				     $('#result-config-integrations').replaceWith("<span id='result-config-integrations'><p><div class='alert alert-info' role='alert'>" + data.result + "</div></p></span>");
				 }
				 setTimeout(function(){ $('#result-config-integrations').replaceWith("<span id='result-config-integrations'></span>"); }, 3000);
			 }
			 
		 });
		 
     });
	 
     $('#btn-gamanet-save-config-general').click(function(evt){
		 console.log("save-config-general");
		 evt.preventDefault();
		 $.ajax({
			 url:gama_obj.url,
			 method:'POST',
			 dataType:'json',
			 data:{
				   action:'save-config-general',
				   nonce:gama_obj.sec,
				   token:$('#token').val(),
				   medio:$('#medio').val(),
				   smstype:$('#smstype').val(),
				   adminmobilenumber:$('#adminmobilenumber').val()	   
			 },success: function(data){
				 //console.log(data.result + "1.1")
				 $('#result-config-general').replaceWith("<span id='result-config-general'><p><div class='alert alert-info' role='alert-config-general'>" + data.result + "</div></p></span>");
				 setTimeout(function(){ $('#result-config-general').replaceWith("<span id='result-config-general'></span>"); }, 3000);
			 }
			 
		 });
		 
     });
	 
	 // Oculta el tipo de mensjes sms cuando se selecciona whatsapp
	 $("#medio").change(function(){
            if($(this).val() == "whatsapp"){
               $("#smstype-group").addClass('d-none');
            }else if($(this).val() == "sms"){
               $("#smstype-group").removeClass('d-none');				
			}
	 });
	 
	 
	 $("#wpforms_process_complete").change(function(){
            if($(this).val() == 0){
               $("#wpforms_process_complete_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wpforms_process_complete_more").removeClass('d-none');				
			}
	 });
	 
	 
	 $("#wc_notif_new_order").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_new_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_new_order_more").removeClass('d-none');				
			}
	 });
	 
	 $("#wc_notif_new_order_self").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_new_order_self_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_new_order_self_more").removeClass('d-none');				
			}
	 });	 
	 
	 $("#wc_notif_created_customer").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_created_customer_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_created_customer_more").removeClass('d-none');				
			}
	 });	 
	 
	 
	 $("#wc_notif_created_customer_self").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_created_customer_self_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_created_customer_self_more").removeClass('d-none');				
			}
	 });

	 $("#wc_notif_created_customer_add_db").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_created_customer_add_db_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_created_customer_add_db_more").removeClass('d-none');				
			}
	 });		 
	 
	 
	 $("#edd_notif_new_order").change(function(){
            if($(this).val() == 0){
               $("#edd_notif_new_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#edd_notif_new_order_more").removeClass('d-none');				
			}
	 });	

	 $("#gamasms_publish_post").change(function(){
            if($(this).val() == 0){
               $("#gamasms_publish_post_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#gamasms_publish_post_more").removeClass('d-none');				
			}
	 });	

	 $("#gamasms_comment_post").change(function(){
            if($(this).val() == 0){
               $("#gamasms_comment_post_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#gamasms_comment_post_more").removeClass('d-none');				
			}
	 });

     $("#wpforms_process_complete_send_to").change(function(){
            if($(this).val() == "subscribes_group"){
               $("#wpforms_process_complete_send_to_subscribes_group_id").show();
            }
            if($(this).val() == "admin"){
               $("#wpforms_process_complete_send_to_subscribes_group_id").hide();
            }
     });	 
	 
     $("#gamasms_publish_post_send_to").change(function(){
            if($(this).val() == "subscribes_group"){
               $("#gamasms_publish_post_send_to_subscribes_group_id").show();
            }
            if($(this).val() == "admin"){
               $("#gamasms_publish_post_send_to_subscribes_group_id").hide();
            }
     });	
	 
     $("#gamasms_comment_post_send_to").change(function(){
            if($(this).val() == "subscribes_group"){
               $("#gamasms_comment_post_send_to_subscribes_group_id").show();
            }
            if($(this).val() == "admin"){
               $("#gamasms_comment_post_send_to_subscribes_group_id").hide();
            }
     });
	 
	 $("#gform_after_submission").change(function(){
            if($(this).val() == 0){
               $("#gform_after_submission_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#gform_after_submission_more").removeClass('d-none');				
			}
	 });

     $("#gform_after_submission_send_to").change(function(){
            if($(this).val() == "subscribes_group"){
               $("#gform_after_submission_send_to_subscribes_group_id").show();
            }
            if($(this).val() == "admin"){
               $("#gform_after_submission_send_to_subscribes_group_id").hide();
            }
     });	

 // Oculta la asignacion de formularios que lanzaran la notificacion
	 $("#gform_after_submission_forms").change(function(){
            if($(this).val() == "0"){
               $("#gform_after_submission_forms-group").addClass('d-none');
            }else if($(this).val() == "1"){
               $("#gform_after_submission_forms-group").removeClass('d-none');				
			}
	 });

	 $("#wc_notif_processing_order").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_processing_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_processing_order_more").removeClass('d-none');				
			}
	 });	
	 
	 $("#wc_notif_cancelled_order").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_cancelled_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_cancelled_order_more").removeClass('d-none');				
			}
	 });	
	 
	 
	 $("#wc_notif_completed_order").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_completed_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_completed_order_more").removeClass('d-none');				
			}
	 });	
	 
	 $("#wc_notif_pending_order").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_pending_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_pending_order_more").removeClass('d-none');				
			}
	 });	
	 
	 
	 $("#wc_notif_failed_order").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_failed_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_failed_order_more").removeClass('d-none');				
			}
	 });	
	 
	 $("#wc_notif_refunded_order").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_refunded_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_refunded_order_more").removeClass('d-none');				
			}
	 });	
	 
	 $("#wc_notif_note_order").change(function(){
            if($(this).val() == 0){
               $("#wc_notif_note_order_more").addClass('d-none');
            }else if($(this).val() == 1){
               $("#wc_notif_note_order_more").removeClass('d-none');				
			}
	 });	
	 
});