import{r as t,c as s,h as e,g as i}from"./p-1a84f38a.js";import"./p-9158fc11.js";import{T as n}from"./p-76bb3e24.js";import{T as o}from"./p-ac1fe2eb.js";import"./p-7e957087.js";import{T as r,R as a}from"./p-e654bf7e.js";var l;!function(t){t.EXPAND_GROUP="Expand Group",t.COLLAPSE_GROUP="Collapse Group"}(l||(l={}));const h=class{constructor(e){t(this,e),this.columnsUpdatedListener=({detail:t})=>this.onColumnsChanged(t),this.autoExpand=!1,this.row=this.renderGroup.bind(this),this.when=this.useAsRenderer.bind(this),this.anjColumnGroupChange=s(this,"anjColumnGroupChange",7),this.anjRowControlDidLoad=s(this,"anjRowControlDidLoad",7)}componentWillLoad(){this.table=this.element.closest("anj-table")}componentDidLoad(){this.anjRowControlDidLoad.emit(),this.table.addEventListener("anjColumnsDidLoad",this.columnsUpdatedListener),this.table.addEventListener("anjColumnsDidUpdate",this.columnsUpdatedListener)}componentDidUnload(){this.table.removeEventListener("anjColumnsDidLoad",this.columnsUpdatedListener),this.table.removeEventListener("anjColumnsDidUpdate",this.columnsUpdatedListener)}onColumnsChanged(t){this.columns=t.filter(t=>t.groupIndex>-1).sort((t,s)=>t.groupIndex-s.groupIndex)}renderGroup(t){const s={colspan:t.columns.length-1},i=this.findGroup(t.row);return[e(r,{classList:n.rowGroupHeader},e("td",Object.assign({},s,{class:n.rowGroupHeader}),e("anj-headline",null,e("h4",null,`${i.headerRenderer(i.field,i.caption)}: ${t.row[i.field]}`))),e("td",null,this.groupControl(i,t.row))),this.isExpanded(i.groupKeys,t.row[i.groupKey])&&this.hasNestedGroup(t.row[i.groupKey])?t.row[i.groupKey].map((s,i)=>e(a,Object.assign({},Object.assign(t,{rowIndex:t.rowIndex+i,row:s})))):void 0]}groupClick(t,s){t.groupKeys=t.groupKeys?t.groupKeys.includes(s)?t.groupKeys.filter(t=>t!==s):t.groupKeys.concat([s]):[s],this.anjColumnGroupChange.emit(t)}useAsRenderer(t){return!!this.findGroup(t)}findGroup(t){return this.columns.find(s=>t[s.groupKey])}hasNestedGroup(t){return t&&Array.isArray(t)&&t.length>0&&"object"==typeof t[0]}groupControl(t,s){const i=s[t.field],n=this.isExpanded(t.groupKeys,i),o=n?`${this.translator(l.EXPAND_GROUP)}: ${i}`:`${this.translator(l.COLLAPSE_GROUP)}: ${i}`;return e("anj-button",{ariaLabel:o,context:"free",onClick:()=>this.groupClick(t,i)},e("svg",{slot:"icon-only",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},e("path",{d:n?"M7.41 18.59L8.83 20 12 16.83 15.17 20l1.41-1.41L12 14l-4.59 4.59zm9.18-13.18L15.17 4 12 7.17 8.83 4 7.41 5.41 12 10l4.59-4.59z":"M12 5.83L15.17 9l1.41-1.41L12 3 7.41 7.59 8.83 9 12 5.83zm0 12.34L8.83 15l-1.41 1.41L12 21l4.59-4.59L15.17 15 12 18.17z"})))}isExpanded(t,s){return t?this.autoExpand?!t.includes(s):t.includes(s):this.autoExpand}render(){return e("anj-column",{internal:!0,pinned:"right",editable:!1,filterable:!1,sizable:!1,pinnable:!1,orderable:!1,selectable:!1,sortable:!1,name:"row-group-controls",width:"56px",cellRenderer:()=>"",headerRenderer:()=>""})}get element(){return i(this)}static get style(){return".anj-table .anj-col-row-group-controls.anj-header-cell .anj-column-caption{overflow:visible;padding-right:0}.anj-table .anj-col-row-group-controls anj-button{margin:-.75rem}.anj-table .anj-row-group-header anj-headline h4{color:var(--anj-neutral-dark)}"}};o.injectProps(h,["translator"]);export{h as anj_row_grouping};