import{__decorate as e}from"tslib";import{html as t}from"lit";import{query as s,queryAssignedNodes as i,property as l,state as r,customElement as a}from"lit/decorators.js";import{s as o}from"./nile-table-body.css.esm.js";import{N as n}from"../internal/nile-element.esm.js";import{h as d}from"../internal/resizable-table-helper.esm.js";import{ifDefined as h}from"lit/directives/if-defined.js";import"../internal/resizable-table-styles.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 m=class extends n{constructor(){super(...arguments),this.type="primary",this.rows_data=[],this.header_rows_data=[],this.hasResizableColumns=!1}static get styles(){return[o]}firstUpdated(e){this.emit("nile-body-load",{value:this.type,comp:this},!0,!1)}getChildren(e,t){return e.querySelectorAll(t)}getIndexValue(e){return this.header_rows_data.indexOf(e)}checkForResizableColumns(){this.hasResizableColumns=d(this)}handleSlotchange(e){let t=[];this._childNodes.forEach((e=>{if(e.tagName&&"nile-table-row"===e?.tagName?.toLowerCase()){let s=this.getChildren(e,"nile-table-cell-item");if(s.length>0)s.forEach((e=>{t.push(e.innerHTML)})),this.rows_data.push(t);else{let t=this.getChildren(e,"nile-table-header-item");t.length>0&&t.forEach(((e,t)=>{this.header_rows_data.push(e.innerHTML)}))}t=[]}})),this.checkForResizableColumns()}handleSort(e){const{curr_sort_string:t,order:s}=e.detail.value,i=this.getIndexValue(t);this.emit("nile-sort",{value:{header_index:i,curr_sort_string:t,order:s}})}handleSearch(e){const t=e.detail.value;this.search__index=this.getIndexValue(e.target.textContent),this.emit("nile-table-search",{index:this.search__index,value:t})}render(){return t`
      <div class="base" part="base">
        <slot name="table__header" class="table__header"></slot>
        <slot
          @slotchange=${this.handleSlotchange}
          @nile-click-sort=${this.handleSort}
          class="nile__table__body"
          style=${h(this.bodyStyle?`display: ${this.bodyStyle}`:void 0)}
          ?resizable=${this.hasResizableColumns}
          @nile-search=${this.handleSearch}
        ></slot>
      </div>
    `}};e([s("slot")],m.prototype,"defaultSlot",void 0),e([i({flatten:!0})],m.prototype,"_childNodes",void 0),e([l()],m.prototype,"type",void 0),e([l()],m.prototype,"bodyStyle",void 0),e([r()],m.prototype,"rows_data",void 0),e([r()],m.prototype,"header_rows_data",void 0),e([r()],m.prototype,"sort__index",void 0),e([r()],m.prototype,"search__index",void 0),e([r()],m.prototype,"hasResizableColumns",void 0),m=e([a("nile-table-body")],m);export{m as N};
