"use strict";

var lumanPlusCustomSettings = function () {

    const handleUpdate = function () {
        $(document).on('click', "#save_custom_setting_button", function (e) {
            e.preventDefault();

            const $form = $("#luman_plus_custom_settings_form");
            const formData = new FormData($form[0]);

            formData.append('action', 'luman_plus_save_custom_settings');

            $.ajax({
                url: ajaxurl,
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                beforeSend: function () {
                    $('#save_custom_setting_button').prop('disabled', true);
                    $('#save_custom_setting_button .indicator-progress').show();
                    $('#save_custom_setting_button .indicator-label').hide();
                },
                success: function (response) {
                    toastr.success("تنظیمات با موفقیت ذخیره شد");
                },
                error: function () {
                    toastr.error("خطایی در ذخیره‌سازی تنظیمات رخ داد");
                },
                complete: function () {
                    $('#save_custom_setting_button').prop('disabled', false);
                    $('#save_custom_setting_button .indicator-progress').hide();
                    $('#save_custom_setting_button .indicator-label').show();
                }
            });
        });
    }


    return {
        init: function () {
            handleUpdate();
        }
    }
}();

KTUtil.onDOMContentLoaded(function () {
    lumanPlusCustomSettings.init();
});