document.querySelectorAll('input').forEach(el => {
el.setAttribute('autocomplete', 'off');
});

$(document).on('input', '.fee_input', function() {
this.value = this.value.replace(/[^0-9]/g, '');
});


document.addEventListener('contextmenu', function (e) {
    e.preventDefault();
});

document.addEventListener('dragstart', function (e) {
    if (e.target.tagName === 'IMG') {
        e.preventDefault();
    }
});

var loader = "<div class='d-flex justify-content-center alert alert-primary'><div class='spinner-border load_spin' role='status'><span class='sr-only'></span></div>&nbsp;<strong>Fething information...</strong></div>";

$("#sub_btnp").on("click", function(){
$("#sub_btnp").blur();
var current_pw = document.getElementById('cpass').value;
var new_pw = document.getElementById('npass').value;
var confirm_pw = document.getElementById('cnpass').value;

if (current_pw == "") {


Swal.fire({
title: 'Please enter your current password',
icon: 'warning',
showDenyButton: false,
confirmButtonText: 'Okay',
allowOutsideClick: false,
customClass: {
icon: 'swal2-icon-small',
confirmButton: 'btn btn-primary',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
})

document.getElementById('cpass').focus();
return false;
}

if (new_pw == "") {

Swal.fire({
title: 'Please enter your new password',
icon: 'warning',
showDenyButton: false,
confirmButtonText: 'Okay',
allowOutsideClick: false,
customClass: {
icon: 'swal2-icon-small',
confirmButton: 'btn btn-primary',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
})


document.getElementById('npass').focus();
return false;
}

if((new_pw).length < 8)
{

Swal.fire({
title: 'New password should be minimum 8 characters',
icon: 'warning',
showDenyButton: false,
confirmButtonText: 'Okay',
allowOutsideClick: false,
customClass: {
icon: 'swal2-icon-small',
confirmButton: 'btn btn-primary',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
})

document.getElementById('npass').focus();
return false;
}

if (confirm_pw == "") {

Swal.fire({
title: 'Please enter confirmation password',
icon: 'warning',
showDenyButton: false,
confirmButtonText: 'Okay',
allowOutsideClick: false,
customClass: {
icon: 'swal2-icon-small',
confirmButton: 'btn btn-primary',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
})

document.getElementById('cnpass').focus();
return false;
}

if((confirm_pw).length < 8)
{

Swal.fire({
title: 'Confirmation password should be minimum 8 characters',
icon: 'warning',
showDenyButton: false,
confirmButtonText: 'Okay',
allowOutsideClick: false,
customClass: {
icon: 'swal2-icon-small',
confirmButton: 'btn btn-primary',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
})

document.getElementById('cnpass').focus();
return false;
}


if(confirm_pw != new_pw)
{

Swal.fire({
title: 'Password confirmation does not match',
icon: 'warning',
showDenyButton: false,
confirmButtonText: 'Okay',
allowOutsideClick: false,
customClass: {
icon: 'swal2-icon-small',
confirmButton: 'btn btn-primary',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
})

document.getElementById('cnpass').focus();
return false;
}

})

$('.app_table').on('click', '.delete_btn', function () {

Swal.fire({
title: $(this).data('message'),
showDenyButton: false,
icon: 'question',
customClass: {
icon: 'swal2-icon-small'
},
showCancelButton: true,
confirmButtonText: $(this).data('yes'),
cancelButtonText: $(this).data('no'),
allowOutsideClick: false,
customClass: {
icon: 'swal2-icon-small',
confirmButton: 'btn btn-primary',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
}).then((result) => {
if (result.isConfirmed) {
window.location.assign($(this).data('url'));
} else if (result.isDenied) {

}
});

});

$('.app_table').on('click', '.edit_btn', function () {

callDynamicFunction($(this).data('function'), $(this).data('id'));

});


$(document).on('click', '#pay_btn', function () {

initialize_payement();

});

$(document).on('change', '.select_programme', function () {
$('#courses').find('option').remove();
$.ajax({
type: 'POST',
url: 'getter/get_courses.php',
data: 'programme='+this.value,
success: function (data) {
$('#courses').append(data);
}
});

});

$(document).on('click', '.search_btn', function () {

var student_number = document.getElementById('student_number').value;

if (student_number == "") {

Swal.fire({
title: 'Enter your student number',
icon: 'warning',
showDenyButton: false,
confirmButtonText: 'Okay',
allowOutsideClick: false,
customClass: {
icon: 'swal2-icon-small',
confirmButton: 'btn btn-primary',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
})

document.getElementById('student_number').focus();
return false;

}else{

document.getElementById('docket_response').innerHTML = loader;

$.ajax({
type: 'POST',
url: 'getter/get_docket_lists.php',
data: 'student_number='+student_number,
success: function (data) {
document.getElementById('docket_response').innerHTML = data;
}
});


}
});

$(".app_frm").on("submit", function(){

$('.app_frm :input').prop('readonly', true);

$('.app_frm button').prop('disabled', true);

$('.app_btn').html(`
<div class='d-flex justify-content-center'>
<div class='spinner-border form_load' role='status'>
<span class='sr-only'></span>
</div>&nbsp;Loading
</div>
`);

})


function get_programme(id) {

document.getElementById('ajax_response').innerHTML = loader;
$.ajax({
type: 'POST',
url: 'getter/get_programme.php',
data: 'id='+id,
success: function (data) {
document.getElementById('ajax_response').innerHTML = data;
}
});

}


function get_course(id) {

document.getElementById('ajax_response').innerHTML = loader;
$.ajax({
type: 'POST',
url: 'getter/get_course.php',
data: 'id='+id,
success: function (data) {
document.getElementById('ajax_response').innerHTML = data;
$(".select_edit").select2({
dropdownParent: $("#modal-edit"),
width: '100%'
});
}
});

}


function get_session(id) {

document.getElementById('ajax_response').innerHTML = loader;
$.ajax({
type: 'POST',
url: 'getter/get_session.php',
data: 'id='+id,
success: function (data) {
document.getElementById('ajax_response').innerHTML = data;
}
});

}


function get_type(id) {

document.getElementById('ajax_response').innerHTML = loader;
$.ajax({
type: 'POST',
url: 'getter/get_type.php',
data: 'id='+id,
success: function (data) {
document.getElementById('ajax_response').innerHTML = data;
}
});

}

function get_enrollment(id) {

document.getElementById('ajax_response').innerHTML = loader;
$.ajax({
type: 'POST',
url: 'getter/get_enrollment.php',
data: 'id='+id,
success: function (data) {
document.getElementById('ajax_response').innerHTML = data;
}
});

}


function callDynamicFunction(funcName, param) {
return globalThis[funcName](param);
}
