(()=>{function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(e){var a=function(e,a){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,a||"default");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===a?String:Number)(e)}(e,"string");return"symbol"==t(a)?a:a+""}var n={},o=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return a=t,o=[{key:"init",value:function(){$('[data-bb-toggle="widgets-list"]').on("click",".page-link",function(e){e.preventDefault();var a=$(e.currentTarget),n=a.prop("href");n&&t.loadWidget(a.closest(".widget-item").find(".widget-content"),n)}),$(document).on("click",".card-actions .dropdown.predefined_range .dropdown-item",function(e){e.preventDefault();var a=$(e.currentTarget);a.closest(".dropdown").find(".dropdown-toggle").text(a.data("label")),a.closest(".dropdown").find(".dropdown-item").removeClass("active"),a.addClass("active"),t.loadWidget(a.closest(".widget-item").find(".widget-content"),a.closest(".widget-item").data("url"),{changed_predefined_range:1})})}}],r=[{key:"loadWidget",value:function(e,a,o,r){var i=e.closest(".widget-item"),l=i.prop("id"),d=i.find(".card");void 0!==r&&(n[l]=r);var s=i.find("a.collapse-expand");if(!s.length||!s.hasClass("collapse")){Botble.showLoading(d),void 0!==o&&null!=o||(o={});var c=i.find(".dropdown.predefined_range .dropdown-item.active");c.length&&(o.predefined_range=c.data("key")),$httpClient.makeWithoutErrorHandler().get(a,o).then(function(a){var o=a.data;e.html(o.data),void 0!==r?r():n[l]&&n[l](),t.initSortable()}).catch(function(t){var a,n=t.response,o=t.message,r=null==n||null===(a=n.data)||void 0===a?void 0:a.data;!r&&o&&(r='<div class="empty"><p class="empty-subtitle text-muted">'.concat(o,"</p></div>")),e.html(r)}).finally(function(){Botble.hideLoading(d)})}}},{key:"initSortable",value:function(){var t=$('[data-bb-toggle="widgets-list"]');t.length>0&&Sortable.create(t[0],{group:"widgets",sort:!0,delay:0,disabled:!1,store:null,animation:150,handle:".card-header",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dataIdAttr:"data-id",forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,scroll:!0,scrollSensitivity:30,scrollSpeed:10,onUpdate:function(){var e=[];$.each($(".widget-item"),function(t,a){e.push($(a).prop("id"))}),$httpClient.makeWithoutErrorHandler().post(t.data("url"),{items:e}).then(function(t){var e=t.data;Botble.showSuccess(e.message)})}})}}],o&&e(a.prototype,o),r&&e(a,r),Object.defineProperty(a,"prototype",{writable:!1}),a;var a,o,r}();$(function(){(new o).init(),window.BDashboard=o,$(document).on("submit",'[data-bb-toggle="widgets-management-modal"] form',function(t){t.preventDefault();var e=$(t.currentTarget),a=$(this).closest(".modal");$httpClient.make().withButtonLoading(e.find('button[type="submit"]')).postForm(e.prop("action"),new FormData(e[0])).then(function(t){var e=t.data;Botble.showSuccess(e.message),setTimeout(function(){window.location.reload()},1e3)}).finally(function(){a.modal("hide")})}).on("change",'[data-bb-toggle="widgets-management-item"]',function(t){var e=$(t.currentTarget),a=e.closest('[data-bb-toggle="widgets-management-item-wrapper"]'),n=a.find(".avatar");e.prop("checked")?(a.removeClass("text-muted"),n.removeClass("bg-secondary-lt").addClass("bg-primary-lt")):(a.addClass("text-muted"),n.removeClass("bg-primary-lt").addClass("bg-secondary-lt"))})})})();