$(function(){

	'use strict';

	// Common Validation
	/*$('.btn-validate').on('click',function(e) {
	  e.preventDefault();
	  if($('.form-validate').smkValidate()) {

	        $('.btn-validate').html('Please Wait...').addClass('btn-success');
	        $('.form-validate').submit();
	  }

	});*/


	$(document).on('keyup', '.sluggify', function() {
        $('.slugg_field').val(convertToSlug($(this).val()));
    });


	function convertToSlug(Text) {
        return Text
            .toLowerCase()
            .replace(/ /g, '-')
            .replace(/[^\w-]+/g, '');
    }


    $('.branch').on('change',function(){

    	let branch_id = $(this).val();

    	jQuery.ajax({
	    	type : "POST",
	    	url : baseURL+'member/load_users',
	    	data : { branch_id : branch_id } 
	    	}).done(function(data){

	    		$('#link_user').html(data);
	    		$("#link_user").selectpicker('refresh');
    	});
    });
    
    
    $(document).on('click','.delete',function(){
    	let id = $(this).data('id');
        let url = $(this).data('url');

        $.confirm({
            title: 'Confirm',
            content: 'Are you sure you want to delete',
            buttons: {
                confirm: function () {
                    
                    $('#cover-spin').show();
                    let dataJson = { [csrfName]: csrfHash, id: id };

                    jQuery.ajax({
                        type : "POST",
                        url : url,
                        data : dataJson 
                        }).done(function(data){
                            window.location.href = data;
                    });
                },
                cancel: function () {
                }
            }
        });
    })
    
    $(document).on('click','.revoke',function(){
    	let id = $(this).data('id');
        let url = $(this).data('url');

        $.confirm({
            title: 'Confirm',
            content: 'Are you sure you want to active',
            buttons: {
                confirm: function () {
                    
                    $('#cover-spin').show();
                    let dataJson = { [csrfName]: csrfHash, id: id };

                    jQuery.ajax({
                        type : "POST",
                        url : url,
                        data : dataJson 
                        }).done(function(data){
                            window.location.href = data;
                    });
                },
                cancel: function () {
                }
            }
        });
    })
    
 //    const table = $('#categoryList').DataTable({
	// 	"processing": true,
	// 	"serverSide": true,
	// 	"order": [],
	// 	"ajax": {
	// 		"url": baseURL+"category/ajax_list",
	// 		"type": "POST",
	// 		"data": function (d) {
	// 			console.log(d)
	// 		}
	// 	},
	// 	"columnDefs": [
	// 		{
	// 			"targets": [0],
	// 			"orderable": false,
	// 		},
	// 	],
	// });
})