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 { VegaInternalLeftNavLinkSelected } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
export class VegaLeftNavGroupForLeftNavLinkClickObserver extends VegaSlimmer {
  /**
   * Component lifecycle - [disconnectedCallback]
   */
  disconnectedCallback() {
    const topParent = this.vegaLeftNavHierarchyController.getTopParent();
    if (topParent) {
      changeManager.unregister(domNodeSubjectFactory.getSubject(topParent, VegaInternalLeftNavLinkSelected), 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, VegaInternalLeftNavLinkSelected), this.observer);
    }
  }
  isAcceptableObserver(input) {
    return !this.host.contains(input['host']);
  }
  /**
   * Determines if the group should be collapsed based on the autoCollapseGroups property and the openByDefault property.
   * If autoCollapseGroups is 'on-link-click', true, false, or 'always', then the group should be collapsed.
   *
   * @returns {boolean} - Returns true if the group should be collapsed, otherwise false.
   */
  shouldCollapse() {
    return (this.autoCollapseGroups === 'on-link-click' ||
      this.autoCollapseGroups === true ||
      this.autoCollapseGroups === false ||
      this.autoCollapseGroups === 'always');
  }
  observerListener() {
    if (this.shouldCollapse()) {
      this.vegaLeftNavGroupOpenStateController.close();
    }
  }
}
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForLeftNavLinkClickObserver.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForLeftNavLinkClickObserver.prototype, "autoCollapseGroups", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForLeftNavLinkClickObserver.prototype, "vegaLeftNavGroupOpenStateController", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForLeftNavLinkClickObserver.prototype, "vegaLeftNavHierarchyController", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupForLeftNavLinkClickObserver.prototype, "openByDefault", void 0);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaLeftNavGroupForLeftNavLinkClickObserver.prototype, "disconnectedCallback", null);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaLeftNavGroupForLeftNavLinkClickObserver.prototype, "componentWillLoad", null);
