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 { VegaSlimmer, MapToComponentMethod } from 'vega-slimmer/core';
import { Observer } from '../../../helpers/change-manager/observer/observer';
import ChangeManager from '../../../helpers/change-manager/change-manager';
import { findParent } from '../../../utils/ui';
/**
 * The code is defining an abstract class called `VegaNavObserverSlimmer` that extends the `VegaSlimmer` class.
 */
export class VegaNavObserverSlimmer extends VegaSlimmer {
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-left-nav-link-e2e-disconnected}
   * @see{module:vega-left-nav-group-e2e-disconnected}
   */
  /* istanbul ignore next */
  /**
   * Unregister the observer with subject of LEFT_NAV_LINK_SELECTED_TOPIC.
   */
  disconnectedCallback() {
    const subject = this.getObserverSubject();
    if (subject) {
      ChangeManager.unregister(subject, this.observer);
    }
  }
  /**
   * The function creates an observer to observe the subject of LEFT_NAV_LINK_SELECTED_TOPIC.
   */
  componentWillLoad() {
    this.observer = new Observer(this.isAcceptableNavListObserver.bind(this), this.observerListener.bind(this));
    const subject = this.getObserverSubject();
    if (subject) {
      ChangeManager.register(subject, this.observer);
    }
  }
  /**
   * The function checks if the input is an HTMLElement and if it has the same parent element with the host element.
   *
   * @param {unknown} input - The `input` parameter is of type `unknown`, which means it can be any type.
   * @returns {boolean} a boolean value indicating whether the input is acceptable observer.
   */
  isAcceptableNavListObserver(input) {
    return (input instanceof HTMLElement &&
      findParent(this.host, '.vega-nav-list-container') ===
        findParent(input, '.vega-nav-list-container'));
  }
}
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaNavObserverSlimmer.prototype, "disconnectedCallback", null);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaNavObserverSlimmer.prototype, "componentWillLoad", null);
