"use strict";

var lumanPlusGeneralSettings = function () {

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

            const $form = $("#luman_plus_general_settings_form");
            const formData = $form.serialize();

            $.ajax({
                url: ajaxurl,
                type: "POST",
                data: {
                    action: 'luman_plus_save_general_settings',
                    data: formData
                },
                beforeSend: function () {
                    $('#save_general_setting_button').prop('disabled', true);
                    $('#save_general_setting_button .indicator-progress').show();
                    $('#save_general_setting_button .indicator-label').hide();
                },
                success: function (response) {
                    if ( response.success ) {
                        toastr.success(response.data.message);
                    } else {
                        toastr.error(response.data.message);
                    }
                },
                error: function () {
                    toastr.error("خطایی در ذخیره‌سازی تنظیمات رخ داد");
                },
                complete: function () {
                    $('#save_general_setting_button').prop('disabled', false);
                    $('#save_general_setting_button .indicator-progress').hide();
                    $('#save_general_setting_button .indicator-label').show();
                }
            });
        })
    }

    return {
        init: function () {

            handleUpdate();
        }
    }
}();

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