import{r as t,c as i,g as s}from"./p-1a84f38a.js";import{i as e}from"./p-9158fc11.js";import{k as a}from"./p-76bb3e24.js";import{T as l}from"./p-ac1fe2eb.js";var h;!function(t){t.SELECT_CELL="Select Cell"}(h||(h={}));const n=class{constructor(s){t(this,s),this.cellClickListener=t=>this.onCellClick(t),this.cellKeyListener=e(this.onCellClick.bind(this)),this.tableWillUpdateListener=()=>this.onTableWillChange(),this.tableDidUpdateListener=()=>this.onTableDidChange(),this.anjCellSelect=i(this,"anjCellSelect",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)})}onTableDidChange(){Array.from(this.table.querySelectorAll("td.anj-selectable")).forEach(t=>{t.tabIndex=0,t.setAttribute("aria-label",this.translator(h.SELECT_CELL)),t.addEventListener("click",this.cellClickListener),t.addEventListener("keyup",this.cellKeyListener)})}onCellClick(t){const i=t.target,s="TD"===i.tagName?i:i.closest("td"),e=s.dataset.columnField,l=a(s.dataset.rowKey);this.anjCellSelect.emit({cell:s,columnField:e,rowKey:l})}get element(){return s(this)}};l.injectProps(n,["translator"]);export{n as anj_cell_selection};