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 { Observer } from '../../../../../helpers/change-manager/observer/observer';
import changeManager from '../../../../../helpers/change-manager/change-manager';
import domNodeSubjectFactory from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { VegaInternalLeftNavGroupExpand } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
export class VegaLeftNavGroupForOtherGroupsClickObserver extends VegaSlimmer {
  /**
   * Component lifecycle - [disconnectedCallback]
   */
  disconnectedCallback() {
    const topParent = this.vegaLeftNavHierarchyController.getTopParent();
    if (topParent) {
      changeManager.unregister(domNodeSubjectFactory.getSubject(topParent, VegaInternalLeftNavGroupExpand), this.observer);
    }
  }
  componentWillLoad() {
    const topParent = this.vegaLeftNavHierarchyController.getTopParent();
    if (topParent) {
      this.observer = new Observer(this.isAcceptableObserver.bind(this), this.observerListener.bind(this));
      changeManager.register(domNodeSubjectFactory.getSubject(topParent, VegaInternalLeftNavGroupExpand), this.observer);
    }
  }
  isAcceptableObserver(input) {
    return input['host'] !== this.host && !this.host.contains(input['host']);
  }
  shouldCollapse() {
    return (this.autoCollapseGroups == true ||
      this.autoCollapseGroups === 'on-group-click' ||
      this.autoCollapseGroups === 'always');
  }
  observerListener() {
    if (this.shouldCollapse()) {
      this.vegaLeftNavGroupOpenStateController.close();
    }
  }
}
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForOtherGroupsClickObserver.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForOtherGroupsClickObserver.prototype, "autoCollapseGroups", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForOtherGroupsClickObserver.prototype, "vegaLeftNavGroupOpenStateController", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForOtherGroupsClickObserver.prototype, "vegaLeftNavHierarchyController", void 0);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaLeftNavGroupForOtherGroupsClickObserver.prototype, "disconnectedCallback", null);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaLeftNavGroupForOtherGroupsClickObserver.prototype, "componentWillLoad", null);
