<commit_before>import { computed } from '@ember/object';
import { A } from '@ember/array';
import Service, { inject as service } from '@ember/service';
import { hrefTo } from 'ember-href-to/helpers/href-to';
import { assert } from '@ember/debug';

export default Service.extend({

  router: service('-routing'),

  init() {
    this._super(...arguments);
    this.resetState();
  },

  resetState() {
    this.set('items', A());
  },

  // Each routeParam is [ routeName, model ] where model is optional
  routes: computed('items.[]', function() {
    return this.get('items').map(item => {
      let routeParams = [ item.route ];
      if (item.model) {
        routeParams.push(item.model);
      }

      return routeParams;
    });
  }),

  routeUrls: computed('routes.[]', function() {
    return this.get('routes').map(route => {
      return hrefTo.apply(null, [this, ...route]);
    });
  }),

  currentRouteIndex: computed('router.router.currentURL', 'routeUrls.[]', function() {
    if (this.get('routeUrls.length')) {
      let currentURL = this.get('router.router.currentURL').replace(/\/$/, "");
      let index = this.get('routeUrls').indexOf(currentURL);
      assert(`DocsRoutes wasn't able to correctly detect the current route.`, index > -1);
      return index;
    }
  }),

  nextRoute: computed('currentRouteIndex', 'routes.[]', function() {
    let currentIndex = this.get('currentRouteIndex');

    if (currentIndex < this.get('routes.length')) {
      return this.get('routes')[(currentIndex + 1)];
    }
  }),

  previousRoute: computed('currentRouteIndex', 'routes.[]', function() {
    let currentIndex = this.get('currentRouteIndex');

    if (currentIndex > 0) {
      return this.get('routes')[(currentIndex - 1)];
    }
  })
  
});
<commit_msg>Add baseURL into currentRoute logic<commit_after>import { computed } from '@ember/object';
import { A } from '@ember/array';
import Service, { inject as service } from '@ember/service';
import { hrefTo } from 'ember-href-to/helpers/href-to';
import { assert } from '@ember/debug';

export default Service.extend({

  router: service('-routing'),

  init() {
    this._super(...arguments);
    this.resetState();
  },

  resetState() {
    this.set('items', A());
  },

  // Each routeParam is [ routeName, model ] where model is optional
  routes: computed('items.[]', function() {
    return this.get('items').map(item => {
      let routeParams = [ item.route ];
      if (item.model) {
        routeParams.push(item.model);
      }

      return routeParams;
    });
  }),

  routeUrls: computed('routes.[]', function() {
    return this.get('routes').map(route => {
      return hrefTo.apply(null, [this, ...route]);
    });
  }),

  currentRouteIndex: computed('router.router.currentURL', 'routeUrls.[]', function() {
    if (this.get('routeUrls.length')) {
      let router = this.get('router.router');
      let currentURL = router.get('rootURL') + router.get('currentURL');
      currentURL = currentURL
        .replace("//", "/")  // dedup slashes
        .replace(/\/$/, ""); // remove trailing slash
      let index = this.get('routeUrls').indexOf(currentURL);
      assert(`DocsRoutes wasn't able to correctly detect the current route.`, index > -1);
      return index;
    }
  }),

  nextRoute: computed('currentRouteIndex', 'routes.[]', function() {
    let currentIndex = this.get('currentRouteIndex');

    if (currentIndex < this.get('routes.length')) {
      return this.get('routes')[(currentIndex + 1)];
    }
  }),

  previousRoute: computed('currentRouteIndex', 'routes.[]', function() {
    let currentIndex = this.get('currentRouteIndex');

    if (currentIndex > 0) {
      return this.get('routes')[(currentIndex - 1)];
    }
  })

});

{'fraction_non_alphanumeric': 0.1821342604974592, 'fraction_numerical': 0.0021396095212623694, 'mean_word_length': 3.240362811791383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1657677', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1135, 'n_words': 249}