
function restore_data(uid){
    Swal.fire({
        text: confirm_restore_record,
        icon: 'question',
        showCancelButton: true,
        cancelButtonClass:'danger',
        confirmButtonText: confirm_ok_restore,
        cancelButtonText: confirm_cancel_restore,
    }).then((result) => {
        if (result.value) {
            $.ajax({
                url: restore_url,
                method:'POST',
                data:{
                    "_token": csrf_token,
                    uid : uid,
                },
                success:function(res) {
                    handleMessage(res.success, res.message)
                    if(res.success) setTimeout(function () {location.reload()}, messageDuration)
                }
            })
        }
    });
}


$('#modal-physician').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget) // Button that triggered the modal
    var action = button.data('action') // Extract info from data-* attributes
    var modal = $(this);
    if(action === "new"){
        // Clear inputs
        $('#form-physician').attr('action', save_url)
        modal.find('.modal-body select[name="lab_ids"]').attr('multiple', true)
        modal.find('.modal-body input[name="name_en"]').val("");
        modal.find('.modal-body input[name="uid"]').val(0);
        modal.find('.modal-title').html(modal_add_title);
    }else if(action === "edit"){
        $('#form-physician').attr('action', update_url)
        uid = button.data('uid');
        modal.find('.modal-body select[name="lab_ids"]').attr('multiple', false)
        modal.find('.modal-body input[name="uid"]').val(uid);
        modal.find('.modal-title').html(modal_edit_title);
        $.ajax({
            url: get_url,
            type:"POST",
            data:{
                "_token": csrf_token,
                uid: uid,
            },
            success:function(res){
                let data = res.data;
                modal.find('.modal-body input[name="name_en"]').val(data.name_en);
                modal.find('.modal-body input[name="name_kh"]').val(data.name_kh);
                modal.find('.modal-body select[name="lab_ids"]').val(data.lab_id).trigger('change');
                document.getElementById("file-ip-1-preview").src = physician_logo_path+'/'+data.logo
                
                if(data.is_default==0) $('#default-select').prop('checked', false)
		        else $('#default-select').prop('checked', true)
                
                if(!res.success) handleMessage(res.success, res.message)
            }
        });
    }
})
