import{__decorate as t}from"tslib";import{html as s}from"lit";import{query as e,customElement as i}from"lit/decorators.js";import{s as r}from"./nile-table.css.esm.js";import{N as l}from"../internal/nile-element.esm.js";import"../internal/accessibility/a11y.state.enum.esm.js";import"../internal/accessibility/a11y.property.enum.esm.js";import"../internal/accessibility/role.enum.esm.js";let a=class extends l{constructor(){super(...arguments),this.rows=[],this.primaryRowWidths=[]}static get styles(){return[r]}connectedCallback(){super.connectedCallback(),this.addEventListener("nile-body-load",this.handleRows)}firstUpdated(t){this.updateComplete.then((()=>{this.handleResizeObserver()}))}render(){return s`
			<slot @slotchange="${this.repaintTable}"></slot>
			`}repaintTable(){this.realignStructure(),this.handleBodyCssUpdate()}handleRows(t){this.rows=[...this.rows,t.detail.comp]}handleBodyCssUpdate(){if(this.rows.length<2)return;const t=this.rows,s=t[0].shadowRoot?.querySelector("div.base");s&&(s.style.borderTopRightRadius="var(--nile-radius-radius-xl)",s.style.borderTopLeftRadius="var(--nile-radius-radius-xl)",s.style.borderBottomRightRadius="0px",s.style.borderBottomLeftRadius="0px",s.style.borderBottom="none"),t.forEach(((s,e)=>{if(e>0&&e<t.length-1){const t=s.shadowRoot?.querySelector("div.base");t&&(t.style.borderTopRightRadius="0px",t.style.borderTopLeftRadius="0px",t.style.borderBottomRightRadius="0px",t.style.borderBottomLeftRadius="0px",t.style.borderBottom="none")}}));const e=t[t.length-1].shadowRoot?.querySelector("div.base");e&&(e.style.borderTopRightRadius="0px",e.style.borderTopLeftRadius="0px",e.style.borderBottomRightRadius="var(--nile-radius-radius-xl)",e.style.borderBottomLeftRadius="var(--nile-radius-radius-xl)")}getPrimaryColumnWidths(){const t=this.rows.find((t=>"primary"==t.type));return this.getTableCellFetchQuery(t).map((t=>t.clientWidth))}realignStructure(){if(this.rows.length<2)return;const t=this.getPrimaryColumnWidths();this.rows.filter((t=>"primary"!=t.type)).forEach((s=>{let e=this.getTableCellFetchQuery(s);e?.forEach(((s,e)=>{s.style.setProperty("--cell-width",t.at(e)+"px")}))}))}getTableCellFetchQuery(t){return t?.shadowRoot?.querySelector("slot:not([name])")?.assignedElements()[0].shadowRoot?.querySelector("slot")?.assignedElements()}handleResizeObserver(){this.resizeObserver=new ResizeObserver((t=>{for(let s of t)this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout((()=>{this.realignStructure(),this.debounceTimeout=null}),50)})),this.resizeObserver.observe(this)}disconnectedCallback(){this.resizeObserver.disconnect(),super.disconnectedCallback()}};t([e("slot")],a.prototype,"defaultSlot",void 0),a=t([i("nile-table")],a);export{a as N};
