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, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
import ChangeManager from '../../../../../helpers/change-manager/change-manager';
import { TABLE_ROW_SELECTION_ALL } from '../../../../../helpers/change-manager/subject/static-subject/static-subject-title';
import { Observer } from '../../../../../helpers/change-manager/observer/observer';
import { isAcceptableTableObserver } from '../../../type-guard';
/**
 *
 */
export class VegaTableHeadRowController extends VegaSlimmer {
  /**
   * Component lifecycle - [connectedCallback]{@link VegaTableHeadRow.connectedCallback}
   */
  connectedCallback() {
    this.initRowSelectionAllObserver();
  }
  /**
   * Component lifecycle - [disconnectedCallback]{@link VegaTableHeadRow.disconnectedCallback}
   */
  disconnectedCallback() {
    ChangeManager.unregister(TABLE_ROW_SELECTION_ALL, this.rowSelectionAllObserver);
  }
  /**
   * Initialize the row selection all observer.
   */
  initRowSelectionAllObserver() {
    this.rowSelectionAllObserver = new Observer(isAcceptableTableObserver.bind({ host: this.host }), (payload) => {
      if (!payload.noneChecked && payload.checked === false) {
        this.checkedAll = null; // indeterminate status
      }
      else {
        this.checkedAll = payload.checked;
      }
    });
    ChangeManager.register(TABLE_ROW_SELECTION_ALL, this.rowSelectionAllObserver);
  }
}
__decorate([
  MapToComponentField()
], VegaTableHeadRowController.prototype, "host", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaTableHeadRowController.prototype, "checkedAll", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaTableHeadRowController.prototype, "connectedCallback", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaTableHeadRowController.prototype, "disconnectedCallback", null);
