!function(e){"use strict";if("undefined"==typeof SifencyOptions)return;let s={init:function(){this.cacheDOM(),this.bindEvents()},cacheDOM:function(){this.$feedback=e("#sifency-ajax-feedback"),this.feedbackTimer=null},bindEvents:function(){e(document).on("change",".sifency-ajax-save[type='checkbox'], select.sifency-ajax-save",e=>{this.saveSetting(e.currentTarget)});let s=this.debounce(e=>this.saveSetting(e),800);e(document).on("input","input.sifency-ajax-save:not([type='checkbox']), textarea.sifency-ajax-save",function(){s(this)})},debounce:function(e,s){let t;return function(...n){clearTimeout(t),t=setTimeout(()=>e.apply(this,n),s)}},showMessage:function(e,s="success"){this.$feedback.length&&(this.$feedback.html(`<p>${e}</p>`).removeClass().addClass(`notice notice-${s} sifency-notice`).stop(!0,!0).fadeIn("fast"),clearTimeout(this.feedbackTimer),this.feedbackTimer=setTimeout(()=>{this.$feedback.fadeOut("fast")},2e3))},saveSetting:function(s){let t=e(s),n=t.data("setting"),a=t.is(":checkbox")?t.is(":checked")?"on":"off":t.val();t.css("opacity","0.6"),e.post(SifencyOptions.ajaxurl,{action:"sifency_save_admin_setting",nonce:SifencyOptions.nonce,setting_name:n,setting_value:a}).done(e=>{e.success?this.showMessage("Saved successfully!","success"):this.showMessage(e.data?.message||"Failed to save.","error")}).fail(()=>{this.showMessage("An AJAX error occurred.","error")}).always(()=>{t.css("opacity","1")})}};e(document).ready(()=>{s.init()})}(jQuery);