import{r as t,c as s,h as i,g as n}from"./p-c063aff1.js";import"./p-9158fc11.js";import{T as e}from"./p-76bb3e24.js";import"./p-077c4f78.js";import{T as o,R as r}from"./p-bdda32f3.js";import{T as a}from"./p-6cd35191.js";var l;!function(t){t.EXPAND_GROUP="Expand Group",t.COLLAPSE_GROUP="Collapse Group"}(l||(l={}));const h=class{constructor(i){t(this,i),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},n=this.findGroup(t.row);return[i(o,{classList:e.rowGroupHeader},i("td",Object.assign({},s,{class:e.rowGroupHeader}),i("anj-headline",null,i("h4",null,`${n.headerRenderer(n.field,n.caption)}: ${t.row[n.field]}`))),i("td",null,this.groupControl(n,t.row))),this.isExpanded(n.groupKeys,t.row[n.groupKey])&&this.hasNestedGroup(t.row[n.groupKey])?t.row[n.groupKey].map((s,n)=>i(r,Object.assign({},Object.assign(t,{rowIndex:t.rowIndex+n,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 n=s[t.field],e=this.isExpanded(t.groupKeys,n),o=e?`${this.translator(l.EXPAND_GROUP)}: ${n}`:`${this.translator(l.COLLAPSE_GROUP)}: ${n}`;return i("anj-button",{ariaLabel:o,context:"free",onClick:()=>this.groupClick(t,n)},i("svg",{slot:"icon-only",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},i("path",{d:e?"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 i("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 n(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)}"}};a.injectProps(h,["translator"]);export{h as anj_row_grouping};