['#expiration'].forEach(function (elementId) {
    $(elementId).datepicker({
        autoclose: true
    });
});

$(function () {
    $("#post_service").on("submit", function (e) {
        e.preventDefault();
        var formData = new FormData(this);
        formData.append('post_service', '1');
        $.ajax({
            type: "post",
            url: "./includes/post_ottrun_orvpn_services.php",
            data: formData,
            processData: false,
            contentType: false,
            success: function () {
                location.reload();
            },
        });
    });
    $("#post_client").on("submit", function (e) {
        e.preventDefault();
        var formData = new FormData(this);
        formData.append('post_client', '1');
        $.ajax({
            type: "post",
            url: "./includes/post_ottrun_orvpn_services.php",
            data: formData,
            processData: false,
            contentType: false,
            success: function () {
                location.reload();
            },
        });
    });
});

function deleteService(id) {
    if (confirm("Are you sure you want to delete this service?")) {
        $.ajax({
            type: "post",
            url: "./includes/post_ottrun_orvpn_services.php",
            data: {
                delete_service: 1,
                id: id
            },
            success: function () {
                location.reload();
            },
        });
    }
}

function editService(name, url) {
    $("#name").val(name);
    $("#url").val(url);
}

function deleteClient(id) {
    if (confirm("Are you sure you want to delete this client?")) {
        $.ajax({
            type: "post",
            url: "./includes/post_ottrun_orvpn_services.php",
            data: {
                delete_client: 1,
                id: id
            },
            success: function () {
                location.reload();
            },
        });
    }
}

function editClient(username, password, expirey) {
    $("#client_username").val(username);
    $("#client_password").val(password);
    $("#expiration").val(expirey);
}

function banClient(id) {
    if (confirm("Are you sure you want to ban this client?")) {
        $.ajax({
            type: "post",
            url: "./includes/post_ottrun_orvpn_services.php",
            data: {
                ban_client: 1,
                id: id
            },
            success: function () {
                location.reload();
            },
        });
    }
}

function unbanClient(id) {
    if (confirm("Are you sure you want to unban this client?")) {
        $.ajax({
            type: "post",
            url: "./includes/post_ottrun_orvpn_services.php",
            data: {
                unban_client: 1,
                id: id
            },
            success: function () {
                location.reload();
            },
        });
    }
}