(()=>{function e(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function t(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}var a=function(){function a(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),t(this,"$filterForm",$(document).find("form.filter-form")),t(this,"$table",this.$filterForm.closest(".table-wrapper").find("table"))}var r,i,l;return r=a,(i=[{key:"loadData",value:function(e){$httpClient.make().get($(".filter-data-url").val(),{class:$(".filter-data-class").val(),key:e.val(),value:e.closest(".filter-item").find(".filter-column-value").val()}).then((function(t){var a=t.data,r=$.map(a.data,(function(e,t){return{id:t,name:e}}));e.closest(".filter-item").find(".filter-column-value-wrap").html(a.html);var i=e.closest(".filter-item").find(".filter-column-value");i.length&&"text"===i.prop("type")&&(i.typeahead({source:r}),i.data("typeahead").source=r),Botble.initResources()}))}},{key:"init",value:function(){var e=this,t=this;$.each($(".filter-items-wrap .filter-column-key"),(function(e,a){$(a).val()&&t.loadData($(a))})),this.$filterForm.on("change",".filter-column-key",(function(e){t.loadData($(e.currentTarget))})).on("click",".add-more-filter",(function(){var e=$(document).find(".sample-filter-item-wrap").html();$(document).find(".filter-items-wrap").append(e.replace("<script>","").replace("<\\/script>","")),Botble.initResources();var a=$(document).find(".filter-items-wrap .filter-item:last-child").find(".filter-column-key");$(a).val()&&t.loadData(a)})).on("click",".btn-remove-filter-item",(function(e){e.preventDefault();var t=$(e.currentTarget);t.closest(".filter-item").remove(),t.tooltip("hide")})).on("click",".btn-apply",(function(t){t.preventDefault();var a=$(t.currentTarget).closest("form.filter-form");e.$filterForm.find('[data-bb-toggle="datatable-reset-filter"]').show();var r=new URL(window.location.href),i=new URLSearchParams(r.search),l=a.serializeArray(),n={};$.each(l,(function(e,t){var a=t.name;if("string"==typeof a&&a.endsWith("[]")){var r=n[a]=n[a]||0;i.set("".concat(a.replace("[]","[".concat(r,"]"))),t.value),n[a]++}else i.set(t.name,t.value)})),window.history.pushState({},"","".concat(r.pathname,"?").concat(i.toString())),e.reloadDatatable(e.$table.DataTable())})).on("click",'[data-bb-toggle="datatable-reset-filter"]',(function(t){t.preventDefault(),e.$filterForm.find(".form-filter:not(.filter-item-default)").remove(),e.$filterForm.find(".filter-item").find(".filter-column-key").val("").trigger("change"),e.$filterForm.find(".filter-item").find(".filter-column-operator").val("="),e.$filterForm.find(".filter-item").find(".filter-column-value").val(""),$(t.currentTarget).hide();var a=new URL(window.location.href);window.history.pushState({},"",a.pathname),e.reloadDatatable(e.$table.DataTable())}))}},{key:"reloadDatatable",value:function(e){e.ajax.url(window.location.href).load()}}])&&e(r.prototype,i),l&&e(r,l),Object.defineProperty(r,"prototype",{writable:!1}),a}();$((function(){(new a).init()}))})();