$(document).ready(function () {
    $('#secret_code').on('change', function () {
        var isChecked = $(this).prop('checked');
        $.ajax({
            type: 'post',
            url: './includes/post_smarters_pro_services.php',
            data: { 
                post_secret_code: 1,
                secret_code: isChecked ? 'enabled' : 'disabled' 
            },
            success: function (response) {
                location.reload();
            }
        });
    });
    $('#maintenancemode').on('change', function () {
        var isChecked = $(this).prop('checked');
        $.ajax({
            type: 'post',
            url: './includes/post_smarters_pro_services.php',
            data: { 
                post_maintenancemode: 1,
                maintenancemode: isChecked ? 'on' : 'off' 
            },
            success: function (response) {
                location.reload();
            }
        });
    });
    $('#welcomestatus').on('change', function () {
        var isChecked = $(this).prop('checked');
        $.ajax({
            type: 'post',
            url: './includes/post_smarters_pro_services.php',
            data: { 
                post_welcomestatus: 1,
                welcomestatus: isChecked ? 'on' : 'off' 
            },
            success: function (response) {
                location.reload();
            }
        });
    });
});

$(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_smarters_pro_services.php",
            data: formData,
            processData: false,
            contentType: false,
            success: function () {
                location.reload();
            },
        });
    });
});

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


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