var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { Fragment, h } from '@stencil/core';
import { VegaTableExpandRowController } from '../controllers/vega-table-expand-row-controller';
export class VegaTableBodyRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.renderTableBody = (editable) => {
      const currentData = this.vegaTableDataSourceController.getCurrentData();
      return (h("vega-table-body", null, currentData.map((record, index) => {
        const rowKey = this.vegaTableDataSourceController.getRecordKey(record);
        const isVisibleInCurrentPage = this.vegaTablePaginationController.isRowVisible(index);
        const isLastRow = index === currentData.length - 1;
        return (h(Fragment, null,
          this.vegaTableRowRenderer.render({
            rowKey,
            index,
            record,
            isVisibleInCurrentPage,
            isLastRow: isLastRow,
          }, editable),
          this.rowExpandable && (h("vega-table-expand-row", { class: {
              'v-hidden': !isVisibleInCurrentPage,
            }, key: `vega-table-expanded-row-${rowKey}`, rowKey: rowKey, striped: this.striped && index % 2 === 1 },
            h("slot", { name: `${VegaTableExpandRowController.expandRowSlotNamePrefix}${rowKey}` })))));
      })));
    };
  }
  getTableFormRef() {
    return this.tableFormRef;
  }
  render() {
    const editable = this.columnStructureModel
      .generateColumnConfigByLeaves(this.columns)
      .some((item) => item === null || item === void 0 ? void 0 : item.editable);
    return editable ? (h("vega-form", { ref: (ref) => (this.tableFormRef = ref) }, this.renderTableBody(editable))) : (this.renderTableBody(false));
  }
}
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "striped", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "rowDivider", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "columns", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "currentBreakpoint", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "rowExpandable", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "rowClickable", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "vegaTableDataSourceController", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "vegaTablePaginationController", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "vegaTableRowSelectionController", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "vegaTableRowRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaTableBodyRenderer.prototype, "columnStructureModel", void 0);
