import AnchorComponent from 'ember-anchor/components/ember-anchor';
import config from 'ember-api-docs/config/environment';
import getOffset from 'ember-api-docs/utils/get-offset';

export default class EmberAnchor extends AnchorComponent {
  // This overrides Ember Anchor to support scrolling within a fixed position element
  _scrollToElemPosition() {
    let qp = this.anchorQueryParam;
    let qpVal = this[this['attrs.a'] ? 'a' : `controller.${qp}`];
    let elem = document.querySelector(`[data-${qp}="${qpVal}"]`);

    if (elem && elem.offsetHeight) {
      const offsetToScroll = getOffset(
        elem,
        config.APP.scrollContainerSelector
      );
      const scrollContainer = document.querySelector(
        config.APP.scrollContainerSelector
      );
      if (scrollContainer.scrollTo) {
        scrollContainer.scrollTo(0, offsetToScroll);
      } else {
        // fallback for IE11
        scrollContainer.scrollTop = offsetToScroll;
      }
    }
  }
}

/* eslint-disable ember/classic-decorator-no-classic-methods */
import AnchorComponent from 'ember-anchor/components/ember-anchor';
import config from 'ember-api-docs/config/environment';
import getOffset from 'ember-api-docs/utils/get-offset';

export default class EmberAnchor extends AnchorComponent {
  // This overrides Ember Anchor to support scrolling within a fixed position element
  _scrollToElemPosition() {
    let qp = this.anchorQueryParam;
    let qpVal = this.a ?? this.controller[qp];
    let elem = document.querySelector(`[data-${qp}="${qpVal}"]`);

    if (elem && elem.offsetHeight) {
      const offsetToScroll = getOffset(
        elem,
        config.APP.scrollContainerSelector
      );
      const scrollContainer = document.querySelector(
        config.APP.scrollContainerSelector
      );
      if (scrollContainer.scrollTo) {
        scrollContainer.scrollTo(0, offsetToScroll);
      } else {
        // fallback for IE11
        scrollContainer.scrollTop = offsetToScroll;
      }
    }
  }
}

Rewrite logic as per latest syntax -@locks review
Rewrite logic as per latest syntax -@locks review
