(function(){"use strict";var p=function(){function d(o,t){var e=this;this.$table=o,this.tableName=t,this.storageKey="joomla-tablecolumns-"+this.tableName,this.$headers=[].slice.call(o.querySelector("thead tr").children),this.$rows=[].slice.call(o.querySelectorAll("tbody tr")),this.listOfHidden=[],this.loadState(),this.protectedCols=[0],this.$rows[0]&&[].slice.call(this.$rows[0].children).forEach(function(n,l){if(n.nodeName==="TH"){e.protectedCols.push(l);var a=e.listOfHidden.indexOf(l);a!==-1&&e.listOfHidden.splice(a,1)}}),this.createControls(),this.listOfHidden.forEach(function(n){e.toggleColumn(n,!0)})}var s=d.prototype;return s.createControls=function(){var t=this,e=document.createElement("div");e.setAttribute("class","dropdown float-end pb-2");var n=document.createElement("div");n.setAttribute("class","dropdown-menu dropdown-menu-end"),n.setAttribute("data-bs-popper","static");var l=document.createElement("button");l.type="button",l.textContent=Joomla.Text._("JGLOBAL_COLUMNS"),l.classList.add("btn","btn-primary","btn-sm","dropdown-toggle"),l.setAttribute("data-bs-toggle","dropdown"),l.setAttribute("data-bs-auto-close","false"),l.setAttribute("aria-haspopup","true"),l.setAttribute("aria-expanded","false");var a=document.createElement("ul");a.setAttribute("class","list-unstyled p-2 text-nowrap mb-0"),a.setAttribute("id","columnList"),this.$headers.forEach(function(i,c){if(!(c===0&&i.nodeName!=="TH")){var f=document.createElement("li"),m=document.createElement("label"),r=document.createElement("input");r.classList.add("form-check-input","me-1"),r.type="checkbox",r.name="table[column][]",r.checked=t.listOfHidden.indexOf(c)===-1,r.disabled=t.protectedCols.indexOf(c)!==-1,r.value=c;var h=i.querySelector("span"),u=h?h.textContent.trim():"";u||(h=i.querySelector("span.visually-hidden")||i,u=h.textContent.trim()),u.includes(":")&&(u=u.split(":",2)[1].trim()),m.textContent=u,m.insertAdjacentElement("afterbegin",r),f.appendChild(m),a.appendChild(f)}}),this.$table.insertAdjacentElement("beforebegin",e),e.appendChild(l),e.appendChild(n),n.appendChild(a),a.addEventListener("change",function(i){t.toggleColumn(parseInt(i.target.value,10)),t.saveState()}),this.$headers.forEach(function(i){i.classList.remove("d-none","d-xs-table-cell","d-sm-table-cell","d-md-table-cell","d-lg-table-cell","d-xl-table-cell","d-xxl-table-cell")}),this.$rows.forEach(function(i){[].slice.call(i.children).forEach(function(c){c.classList.remove("d-none","d-xs-table-cell","d-sm-table-cell","d-md-table-cell","d-lg-table-cell","d-xl-table-cell","d-xxl-table-cell")})}),this.$button=l,this.$menu=a,this.updateCounter()},s.updateCounter=function(){var t=this.$headers.length-1,e=t-this.listOfHidden.length;this.$button.textContent=e+"/"+t+" "+Joomla.Text._("JGLOBAL_COLUMNS")},s.toggleColumn=function(t,e){if(this.$headers[t]&&this.protectedCols.indexOf(t)===-1){var n=this.listOfHidden.indexOf(t);n===-1?this.listOfHidden.push(t):e!==!0&&this.listOfHidden.splice(n,1),this.$headers[t].classList.toggle("d-none",e),this.$rows.forEach(function(l){l.children[t].classList.toggle("d-none",e)}),this.updateCounter()}},s.saveState=function(){window.localStorage.setItem(this.storageKey,this.listOfHidden.join(","))},s.loadState=function(){var t=window.localStorage.getItem(this.storageKey);t&&(this.listOfHidden=t.split(",").map(function(e){return parseInt(e,10)}))},d}();window.innerWidth>992&&[].concat(document.querySelectorAll("table:not(.columns-order-ignore)")).forEach(function(d){var s=d.dataset.name?d.dataset.name:document.querySelector(".page-title").textContent.trim().replace(/[^a-z0-9]/gi,"-").toLowerCase();s&&new p(d,s)})})();
