$(function(){function t(t,e,n,a){var r=t.find("#generate-thumbnails-progress");r.removeClass("d-none");var o=Math.min(e,n),i=n>0?Math.round(o/n*100):0;if(r.find("#generate-thumbnails-progress-text").text("".concat(o," / ").concat(n)),r.find("#generate-thumbnails-progress-percent").text("".concat(i,"%")),r.find("#generate-thumbnails-progress-bar").css("width","".concat(i,"%")),t.find("#generate_thumbnails_start_offset").val(o),a>0){var s=r.find("#generate-thumbnails-error-log");s.removeClass("d-none"),s.find("#generate-thumbnails-error-text").text("".concat(a," file(s) failed to generate thumbnails."))}}$(".generate-thumbnails-trigger-button").on("click",function(t){t.preventDefault();var e=$(t.currentTarget),n=e.closest("form");$httpClient.make().withButtonLoading(e).postForm(n.prop("action"),new FormData(n[0])).then(function(t){var e=t.data,n=$("#generate-thumbnails-modal");n.modal("show"),n.data("total-files",e.data.files_count),function(t){var e=t.find("#generate-thumbnails-progress");e.addClass("d-none"),e.find("#generate-thumbnails-progress-bar").css("width","0%").removeClass("bg-danger"),e.find("#generate-thumbnails-error-log").addClass("d-none"),e.find("#generate-thumbnails-error-text").text("")}(n),n.find("#generate_thumbnails_start_offset").attr("max",e.data.files_count)})}),$("#generate-thumbnails-button").on("click",function(e){e.preventDefault();var n=$(e.currentTarget),a=n.closest(".modal"),r=n.closest("form"),o=a.data("total-files"),i=a.find('input[name="override_existing"]').is(":checked")?1:0,s=parseInt(a.find('input[name="start_offset"]').val())||0,d=null,l=0;Botble.showButtonLoading(n),a.find("input").prop("disabled",!0);var c=parseInt(a.find('input[name="batch_size"]').val())||a.data("chunk-limit");function f(){Botble.hideButtonLoading(n),a.find("input").prop("disabled",!1),l>0?Botble.showError(d):Botble.showSuccess(d)}!function e(){var u=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s,h=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c;u>=o?f():(t(a,u,o,l),$httpClient.make().post(r.prop("action"),{total:o,offset:u,limit:h,override_existing:i}).then(function(n){var r=n.data;d=r.message,r.error&&l++,r.data.next&&r.data.next<o?e(r.data.next,h):(t(a,o,o,l),f())}).catch(function(){l++,t(a,u,o,l),function(t){Botble.hideButtonLoading(n),a.find("input").prop("disabled",!1),a.find("#generate_thumbnails_start_offset").val(t);var e=a.find("#generate-thumbnails-error-log");e.removeClass("d-none"),e.find("#generate-thumbnails-error-text").text("Process stopped at offset ".concat(t,'. You can click "Generate" to resume from this position.'))}(u)}))}()}),$(document).on("change",".check-all",function(t){var e=$(t.currentTarget),n=e.attr("data-set"),a=e.prop("checked");$(n).each(function(t,e){$(e).prop("checked",a)})})});