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 { InjectVegaSlimmer, MapToComponentField, MapToComponentMethod, methodPlaceholder, VegaSlimmer, } from 'vega-slimmer/core';
import { MutationObserverSlimmer } from '../../../../helpers/slimmers/mutation-observer/mutation-observer-slimmer';
import { TagNameMutationFilter } from '../../../../helpers/slimmers/mutation-observer/mutation-observer-filters';
/**
 * The render mode controller of the table
 */
export class VegaTableRenderModeController extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.currentDataObserver = new MutationObserverSlimmer({
      // eslint-disable-next-line jsdoc/require-jsdoc
      target: () => this.host,
      options: { childList: true, subtree: true },
      mutationFilter: TagNameMutationFilter('VEGA-TABLE-ROW'),
      callback: 
      /* istanbul ignore next */
      // eslint-disable-next-line jsdoc/require-jsdoc
      () => {
        this.isTemplateRenderMode = this.checkIsTemplateRenderMode(this.host);
      },
    });
    /**
     * Check whether render mode is template render
     *
     * @param {HTMLElement} tableRef - VegaTable ref
     * @returns {boolean} return true if the mode is template, otherwise false
     */
    this.checkIsTemplateRenderMode = (tableRef) => {
      return Array.from(tableRef.children).some((el) => el.tagName.startsWith('VEGA-TABLE-'));
    };
  }
  /**
   * Used by {@link currentDataObserver}
   */
  connectedCallback() {
    methodPlaceholder();
  }
  /**
   * Used by {@link currentDataObserver}
   */
  disconnectedCallback() {
    methodPlaceholder();
  }
  /**
   * init the isTemplateRenderMode value
   */
  componentWillLoad() {
    this.isTemplateRenderMode = this.checkIsTemplateRenderMode(this.host);
  }
  /**
   * Used by {@link currentDataObserver}
   */
  componentDidLoad() {
    methodPlaceholder();
  }
}
__decorate([
  MapToComponentField()
], VegaTableRenderModeController.prototype, "host", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaTableRenderModeController.prototype, "isTemplateRenderMode", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaTableRenderModeController.prototype, "currentDataObserver", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaTableRenderModeController.prototype, "connectedCallback", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaTableRenderModeController.prototype, "disconnectedCallback", null);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaTableRenderModeController.prototype, "componentWillLoad", null);
__decorate([
  MapToComponentMethod('componentDidLoad')
], VegaTableRenderModeController.prototype, "componentDidLoad", null);
