(()=>{function e(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,o){if(e){if("string"==typeof e)return t(e,o);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,o):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,n=Array(t);o<t;o++)n[o]=e[o];return n}$((function(){var t=$(document).find("#bulk-import"),o=t.find(".form-import-data"),n=t.find(".btn-import"),a=[],i=0;$(document).on("click",".btn-import",(function(e){e.preventDefault(),l.getQueuedFiles().length>0&&(Botble.showButtonLoading(n),t.find(".show-errors").hide(),i=0,a=[],l.processQueue()),l.on("sending",(function(){t.find(".bulk-import-message").removeClass("alert-success").addClass("alert-info").text(n.data("uploading-text")).show()})),l.on("error",(function(e,t){Botble.showError(t.message)}))}));var r=function r(d){var m=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e3;0===m&&t.find(".bulk-import-message").text(n.data("validating-text")),$httpClient.make().post(o.data("validate-url"),{file:d,offset:m,limit:f}).then((function(o){var m=o.data,f=m.data,u=m.message;if(f&&f.count>0)t.find(".bulk-import-message").show(),t.find(".bulk-import-message").text(u),r(d,f.offset),a=[].concat(e(a),e(f.failed)),i+=f.count;else if(a.length>0){var c=t.find("#imported-listing"),p=t.find(".show-errors");i=0;var h=$(document).find("#failure-template").html(),g="";a.forEach((function(e){g+=h.replace("__row__",e.row).replace("__errors__",e.errors.join(", "))})),p.show(),t.find(".main-form-message").show(),c.show().html(g),a=[],i=0,Botble.hideButtonLoading(n),l.removeAllFiles(),t.find(".bulk-import-message").hide()}else s(d)}))},s=function e(a){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10;0===r&&(t.find(".bulk-import-message").text(n.data("importing-text")),Botble.showButtonLoading(n)),$httpClient.make().post(o.data("import-url"),{file:a,offset:r,limit:s}).then((function(o){var r=o.data,s=r.data,d=r.message,m=t.find(".processing"),f=m.find(".process");s&&s.count>0?(m.show(),e(a,s.offset),f.css("width",s.offset/i*100+"%"),t.find(".bulk-import-message").html(d)):(Botble.showSuccess(d),s.total_message&&(t.find(".main-form-message").show(),t.find(".bulk-import-message").removeClass("alert-info").addClass("alert-success").text(s.total_message).show(),l.removeAllFiles(),m.hide(),i=0,Botble.hideButtonLoading(n)))}))},l=new Dropzone(".import-dropzone",{url:o.data("upload-url"),method:"post",headers:{"X-CSRF-TOKEN":o.find("input[name=_token]").val()},previewTemplate:$(document).find("#preview-template").html(),autoProcessQueue:!1,chunking:!0,chunkSize:1048576,acceptedFiles:o.find(".import-properties-dropzone").data("mimetypes"),maxFiles:1,maxfilesexceeded:function(e){this.removeFile(e)},success:function(e,t){var o=t.data;t.message;o&&o.file_path&&r(o.file_path)}}),d=!1;$(document).on("click",".download-template",(function(e){if(e.preventDefault(),!d){var t=$(e.currentTarget),o=t.data("extension"),n=t.html();t.html(t.data("downloading")),t.addClass("text-secondary"),d=!0,$httpClient.make().withResponseType("blob").post(t.data("url"),{extension:o}).then((function(e){var o=e.data,n=document.createElement("a"),a=window.URL.createObjectURL(o);n.href=a,n.download=t.data("filename"),document.body.append(n),n.click(),n.remove(),window.URL.revokeObjectURL(a)})).finally((function(){setTimeout((function(){t.html(n),t.removeClass("text-secondary"),d=!1}),2e3)}))}}))}))})();