$(document).ready(function(){const s=window.fraudModulesConfig;let r;$(".module-toggle").on("change",function(){const t=$(this),e=t.data("slug"),a=t.is(":checked");$.ajax({url:s.routes.toggle.replace(":slug",e),type:"POST",headers:{},success:function(o){o.success?i(o.message,"success"):(t.prop("checked",!a),i(o.message||s.translations.toggleFailed,"error"))},error:function(){t.prop("checked",!a),i(s.translations.toggleFailed,"error")}})}),$(".test-module").on("click",function(){const t=$(this),e=t.data("slug"),a=t.html();t.prop("disabled",!0).html('<i class="fas fa-spinner fa-spin"></i>'),$.ajax({url:s.routes.test.replace(":slug",e),type:"POST",headers:{},success:function(o){o.success?i(o.message||s.translations.testSuccess,"success"):i(o.message||s.translations.testFailed,"error")},error:function(){i(s.translations.testFailed,"error")},complete:function(){t.prop("disabled",!1).html(a)}})}),$(".module-priority").on("input",function(){clearTimeout(r),r=setTimeout(n,1e3)});function n(){const t={};$(".module-priority").each(function(){const e=$(this).data("slug"),a=parseInt($(this).val())||0;t[e]=a}),$.ajax({url:s.routes.updatePriorities,type:"POST",headers:{},data:{priorities:t},success:function(e){e.success&&i(e.message||s.translations.priorityUpdated,"success")},error:function(){i(s.translations.toggleFailed,"error")}})}function i(t,e){const a=e==="success"?"alert-success":"alert-danger",o=$('<div class="alert '+a+' alert-dismissible fade show position-fixed" style="top: 20px; right: 20px; z-index: 9999;" role="alert">'+t+'<button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');$("body").append(o),setTimeout(function(){o.alert("close")},3e3)}});
