import{r as t,h as i}from"./p-23a36bb6.js";import{RECORD_DATE_FORMAT as a,DataUnitInMemoryLoader as e}from"@sankhyalabs/core";const s=class{constructor(i){t(this,i),this.inMemoryLoader=void 0,this.metadata=void 0,this.records=void 0,this.columnsConfig=void 0,this.pageSize=150,this.recordDateFormat=a.DD_MM_YYYY,this.multipleSelection=!1,this.autoFocus=!0,this.paginationCounterMode="auto",this.suppressCheckboxColumn=!1,this.suppressFilterColumn=!1,this.outlineMode=!1,this.enableRowTableStriped=!0,this.compact=!1,this.useSearchColumn=!0,this.suppressHorizontalScroll=!1}async getDataUnit(){if(this.hasValidDependencies())return this.ensureInMemoryLoaderExists(),this.inMemoryLoader.dataUnit}async refresh(){await this.inMemoryLoader.dataUnit.loadData()}async getSelection(){var t;return null===(t=this._gridRef)||void 0===t?void 0:t.getSelection()}async quickFilter(t){var i;await(null===(i=this._gridRef)||void 0===i?void 0:i.quickFilter(t))}async locateColumn(t){var i;await(null===(i=this._gridRef)||void 0===i?void 0:i.locateColumn(t))}async filterColumns(t){var i;return null===(i=this._gridRef)||void 0===i?void 0:i.filterColumns(t)}async addColumnMenuItem(t,i,a,e){await this._gridRef.addColumnMenuItem(t,i,a,e)}async addCustomValueFormatter(t,i){var a;await(null===(a=this._gridRef)||void 0===a?void 0:a.addCustomValueFormatter(t,i))}async removeCustomValueFormatter(t){var i;await(null===(i=this._gridRef)||void 0===i?void 0:i.removeCustomValueFormatter(t))}async addGridCustomRender(t,i,a){var e;await(null===(e=this._gridRef)||void 0===e?void 0:e.addGridCustomRender(t,i,a))}async setFocus(){var t;await(null===(t=this._gridRef)||void 0===t?void 0:t.setFocus())}async handleMetadataChanged(){await this.configGrid()}async handleRecordsChanged(){await this.configGrid()}async handlePageSizeChanged(){await this.configGrid(!0)}async handleRecordDateFormatChanged(){await this.configGrid(!0)}async configGrid(t=!1){this.hasValidDependencies()&&(this.ensureInMemoryLoaderExists(t),this.updateDURecords(),this.refreshFilterColumnDataSource())}updateDURecords(){requestAnimationFrame((()=>{this.inMemoryLoader.records=this.records}))}refreshFilterColumnDataSource(){requestAnimationFrame((async()=>{var t;await(null===(t=this._gridRef)||void 0===t?void 0:t.refreshColumnFilterDataSource())}))}hasValidDependencies(){return this.metadata&&this.records}buildGridConfig(){if(this.columnsConfig)return{columns:this.columnsConfig.map(this.parseColumnConfig.bind(this))}}parseColumnConfig(t,i){return Object.assign(Object.assign({},t),{orderIndex:i})}ensureInMemoryLoaderExists(t=!1){t&&this.clearInMemoryLoader(),this.buildInMemoryLoader()}buildInMemoryLoader(){requestAnimationFrame((()=>{this.inMemoryLoader||(this.inMemoryLoader=new e(this.metadata,this.records,this.buildInMemoryLoaderConfig()))}))}clearInMemoryLoader(){this.inMemoryLoader=void 0}buildInMemoryLoaderConfig(){return{pageSize:this.pageSize,recordDateFormat:this.recordDateFormat}}async componentDidLoad(){await this.configGrid()}render(){var t;if((null===(t=this.inMemoryLoader)||void 0===t?void 0:t.dataUnit)&&this.records)return i("ez-grid",{ref:t=>this._gridRef=t,canEdit:!1,dataUnit:this.inMemoryLoader.dataUnit,config:this.buildGridConfig(),multipleSelection:this.multipleSelection,autoFocus:this.autoFocus,paginationCounterMode:this.paginationCounterMode,suppressCheckboxColumn:this.suppressCheckboxColumn,suppressFilterColumn:this.suppressFilterColumn,suppressHorizontalScroll:this.suppressHorizontalScroll,outlineMode:this.outlineMode,enableRowTableStriped:this.enableRowTableStriped,useSearchColumn:this.useSearchColumn,compact:this.compact,onEzPageChangedChanged:()=>this.refreshFilterColumnDataSource()},i("slot",{name:"leftButtons"}),i("slot",{name:"footer"}))}static get watchers(){return{metadata:["handleMetadataChanged"],records:["handleRecordsChanged"],pageSize:["handlePageSizeChanged"],recordDateFormat:["handleRecordDateFormatChanged"]}}};s.style="";export{s as ez_grid_view}