(()=>{"use strict";const e=window.lodash;jQuery((function(a){const l=function(){a(".dlp-category").on("click",this.handleFolderToggle),a(document).on("input keyup",'.dlp-folders-search input[type="search"]',(0,e.debounce)(this.handleFolderSearch,300)),a(document).on("click",".dlp-folders-reset",this.handleFolderSearchReset),a(".dlp-folders-container").each(((e,l)=>{a(l).show()})),a(".dlp-folder:not(.closed)").each(((e,a)=>{this.openFolder(a)}))};l.prototype.handleFolderToggle=function(e){const l=a(this),d=l.parents(".dlp-folder").first(),o=d.find(".dlp-category-table").first(),s=d.data("category-id"),t=l.parents(".dlp-folders-root").data("shortcode-atts");d.hasClass("closed")&&!d.hasClass("table-loaded")&&(o.block({message:null,overlayCSS:{background:"#fff",opacity:.7}}),a.ajax({url:dlp_folders_params.ajax_url,type:"POST",data:{category_id:s,shortcode_atts:t,action:dlp_folders_params.ajax_action,_ajax_nonce:dlp_folders_params.ajax_nonce},xhrFields:{withCredentials:!0}}).done((function(e){o.html(e.html),"table"===e.layout&&o.children("table").first().postsTable(),o.unblock(),a(document).trigger("dlp_folder_opened",d)})),d.addClass("table-loaded")),d.hasClass("closed")||d.find(".dlp-folder").each((function(e,l){const d=a(l);d.hasClass("closed")||d.addClass("closed")})),d.toggleClass("closed");const r=d.siblings(".dlp-folder").not(d);(-1!==navigator.userAgent.indexOf("Mac")&&!e.metaKey||-1===navigator.userAgent.indexOf("Mac")&&!e.ctrlKey)&&r.each((function(e,l){const d=a(l);d.hasClass("closed")||(d.addClass("closed"),d.find(".dlp-folder").each((function(e,l){const d=a(l);d.hasClass("closed")||d.addClass("closed")})))}))},l.prototype.openFolder=function(e){const l=a(e),d=l.find(".dlp-category-table").first(),o=l.data("category-id"),s=l.parents(".dlp-folders-root").data("shortcode-atts");l.hasClass("table-loaded")||(0===l.find(".dlp-folder:not(.closed)").length&&d.block({message:null,overlayCSS:{background:"#fff",opacity:.7}}),a.ajax({url:dlp_folders_params.ajax_url,type:"POST",data:{category_id:o,shortcode_atts:s,action:dlp_folders_params.ajax_action,_ajax_nonce:dlp_folders_params.ajax_nonce},xhrFields:{withCredentials:!0}}).done((function(e){d.html(e.html),"table"===e.layout&&d.children("table").first().postsTable(),d.unblock(),a(document).trigger("dlp_folder_opened",l)})),l.addClass("table-loaded"))},l.prototype.handleFolderSearch=function(e){const l=a(this),d=l.parents(".dlp-folders-container").first(),o=d.find(".dlp-folders"),s=d.find(".dlp-folders-search-results"),t=d.find(".dlp-folders-reset"),r=d.find(".dlp-folders-root").data("shortcode-atts"),n=!!s.hasClass("search-loaded")&&s.find("> div").attr("id"),c=l.val();if(c.length<dlp_folders_params.ajax_min_search_term_len)return s.hide(),o.show(),void t.hide();t.show(),d.find('.dlp-folders-search input[type="search"]').not(this).each((function(e){a(this).val(l.val())})),d.block({message:null,overlayCSS:{background:"#fff",opacity:.7}}),a.ajax({url:dlp_folders_params.ajax_url,type:"POST",data:{library_id:n,search_query:c,shortcode_atts:r,action:dlp_folders_params.ajax_folder_search,_ajax_nonce:dlp_folders_params.ajax_nonce},xhrFields:{withCredentials:!0}}).done((function(e){o.hide(),s.show(),s.html(e.html),"table"===e.layout&&s.children("table").first().postsTable(),s.addClass("search-loaded"),d.unblock()}))},l.prototype.handleFolderSearchReset=function(e){e.preventDefault();const l=a(this).parents(".dlp-folders-container").first(),d=l.find(".dlp-folders"),o=l.find('.dlp-folders-search input[type="search"]'),s=l.find(".dlp-folders-reset"),t=l.find(".dlp-folders-search-results");o.each((function(e){a(this).val("")})),s.each((function(e){a(this).hide()})),d.show(),t.hide()},new l}))})();