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 { Observer } from '../../../helpers/change-manager/observer/observer';
import ChangeManager from '../../../helpers/change-manager/change-manager';
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
import { ACCORDION_EXPAND_TOPIC } from '../../../helpers/change-manager/subject/static-subject/static-subject-title';
import { isAccordionObserverPayload } from '../../../types/type-guard';
export class VegaAccordionExpandController extends VegaSlimmer {
  flipExpand() {
    this.expand = !this.expand;
  }
  onExpand() {
    if (this.groupId && this.expand) {
      ChangeManager.notify(ACCORDION_EXPAND_TOPIC, {
        groupId: this.groupId,
        element: this.host,
      });
    }
    this.expandEventEmitter.emit(this.expand);
  }
  registerObserver() {
    this.observer = new Observer(isAccordionObserverPayload, this.shouldCollapseSelfIfOtherExpand.bind(this));
    ChangeManager.register(ACCORDION_EXPAND_TOPIC, this.observer);
  }
  unregisterObserver() {
    if (this.observer) {
      ChangeManager.unregister(ACCORDION_EXPAND_TOPIC, this.observer);
      this.observer = null;
    }
  }
  shouldCollapseSelfIfOtherExpand(payload) {
    if (this.groupId === payload.groupId && this.host !== payload.element) {
      this.expand = false;
    }
  }
}
__decorate([
  MapToComponentField()
], VegaAccordionExpandController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionExpandController.prototype, "groupId", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaAccordionExpandController.prototype, "expand", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionExpandController.prototype, "expandEventEmitter", void 0);
__decorate([
  MapToComponentMethod('watchExpand')
], VegaAccordionExpandController.prototype, "onExpand", null);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaAccordionExpandController.prototype, "registerObserver", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaAccordionExpandController.prototype, "unregisterObserver", null);
