import{r as t,c as s,g as i}from"./p-1a84f38a.js";import{i as e}from"./p-9158fc11.js";import{c as a}from"./p-76bb3e24.js";import{T as l}from"./p-ac1fe2eb.js";var n;!function(t){t.DESELECT_COLUMN="Deselect column",t.SELECT_COLUMN="Select Column"}(n||(n={}));const h=class{constructor(i){t(this,i),this.cellClickListener=t=>this.onCellClick(t),this.cellKeyListener=e(this.onCellClick.bind(this)),this.tableWillUpdateListener=()=>this.onTableWillChange(),this.tableDidUpdateListener=()=>this.onTableDidChange(),this.anjColumnSelect=s(this,"anjColumnSelect",7)}componentWillLoad(){this.table=this.element.closest("anj-table")}componentDidLoad(){this.table.addEventListener("anjTableWillUpdate",this.tableWillUpdateListener),this.table.addEventListener("anjTableDidUpdate",this.tableDidUpdateListener)}componentDidUnload(){this.onTableWillChange(),this.table.removeEventListener("anjTableWillUpdate",this.tableWillUpdateListener),this.table.removeEventListener("anjTableDidUpdate",this.tableDidUpdateListener)}onTableWillChange(){Array.from(this.table.querySelectorAll("td.anj-selectable")).forEach(t=>{t.removeEventListener("click",this.cellClickListener),t.removeEventListener("keyup",this.cellKeyListener)})}async onTableDidChange(){const t=await this.table.getColumns();Array.from(this.table.querySelectorAll("td.anj-selectable")).forEach(s=>{const i=a(t,s),e=this.table.selectedColumnFields.includes(i.field);s.tabIndex=0,s.setAttribute("aria-label",e?`${this.translator(n.DESELECT_COLUMN)}: ${i.name}`:`${this.translator(n.SELECT_COLUMN)}: ${i.name}`),s.addEventListener("click",this.cellClickListener),s.addEventListener("keyup",this.cellKeyListener)})}onCellClick(t){const s=t.target,i=("TD"===s.tagName?s:s.closest("td")).dataset.columnField;this.table.selectedColumnFields=this.table.selectedColumnFields.includes(i)?[]:[i],this.anjColumnSelect.emit({field:i,selectedColumnFields:this.table.selectedColumnFields})}get element(){return i(this)}static get style(){return".anj-table .anj-cell.anj-selected-col,.anj-table .anj-header-cell.anj-selected-col{background-color:var(--anj-background)!important}"}};l.injectProps(h,["translator"]);export{h as anj_column_selection};