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 { VegaTableEditableController } from '../controllers/vega-table-editable-controller';
import { h } from '@stencil/core';
import { DomNodeSubjectObserverFactory } from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaClick } from '../../../../helpers/event-manager/event-id/vega-event-id';
export class VegaTableRowRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.renderTableRowComponent = (rowProps) => {
      const { rowKey, index, record, isVisibleInCurrentPage } = rowProps;
      const renderInputs = this.vegaTableRenderInputController.getLeafRenderInputs();
      return (h("vega-table-row", { class: {
          'v-hidden': !isVisibleInCurrentPage,
        }, key: `vega-table-row-${rowKey}`, rowKey: rowKey, 
        /* eslint-disable-next-line react/jsx-no-bind */
        ref: (ref) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, () => {
            this.rowClickEventEmitter.emit({ record: record, index: index });
          });
        }, striped: this.striped && index % 2 === 1, rowDivider: this.rowDivider && !rowProps.isLastRow }, renderInputs.map((renderInput) => {
        return this.vegaTableCellRenderer.render(renderInput, record, index);
      })));
    };
  }
  render(rowProps, editable) {
    const { rowKey } = rowProps;
    return editable ? (h("vega-form", { key: `vega-table-row-form-${rowKey}`, "data-vega-form": `${VegaTableEditableController.rowFormKeyPrefix}${rowKey}`, ref: (ref) => this.vegaTableEditableController.getRowFormRefMap().set(rowKey, ref) }, this.renderTableRowComponent(rowProps))) : (this.renderTableRowComponent(rowProps));
  }
}
__decorate([
  MapToComponentField()
], VegaTableRowRenderer.prototype, "rowClickEventEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaTableRowRenderer.prototype, "vegaTableEditableController", void 0);
__decorate([
  MapToComponentField()
], VegaTableRowRenderer.prototype, "vegaTableCellRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaTableRowRenderer.prototype, "striped", void 0);
__decorate([
  MapToComponentField()
], VegaTableRowRenderer.prototype, "rowDivider", void 0);
__decorate([
  MapToComponentField()
], VegaTableRowRenderer.prototype, "vegaTableRenderInputController", void 0);
