import { get } from '@ember/object';
import { inject as service } from '@ember/service';
import { run } from '@ember/runloop';
import EmberRouter from '@ember/routing/router';
import RouterScroll from 'ember-router-scroll';
import config from './config/environment';

const Router = EmberRouter.extend(RouterScroll, {
  location: config.locationType,
  rootURL: config.rootURL,
  metrics: service(),

  didTransition() {
    this._super(...arguments);
    this._trackPage();
  },

  _trackPage() {
    run.scheduleOnce('afterRender', this, () => {
      let page = document.location.pathname;
      let title = this.getWithDefault('currentRouteName', 'unknown');

      get(this, 'metrics').trackPage({ page, title });
    });
  }
});

Router.map(function() {
  this.route('about');

  this.route('admin', function() {
    this.route('github-events', { path: '/github/events' }, function() {
      this.route('github-event', { path: '/:id' });
    });
  });

  this.route('github', {
    path: '/oauth/github'
  });

  this.route('login');

  this.route('organization', function() {
    this.route('settings', function() { });
  });

  this.route('organizations', function() {
    this.route('new');
    this.route('slugged-route', {
      path: '/:slugged_route_slug'
    }, function() {
      this.route('settings', function() {
        this.route('profile');
      });
    });
  });

  this.route('privacy');

  this.route('project', { path: '/:slugged_route_slug/:project_slug' }, function() {
    this.route('checkout');
    this.route('donate');
    this.route('settings', function() {
      this.route('contributors');
      this.route('donations', function() {
        this.route('goals');
        this.route('payments');
      });
      this.route('integrations');
      this.route('profile');
    });
    this.route('tasks', function() {
      this.route('new');
      this.route('task', { path: '/:number' });
    });
    this.route('thank-you');
  });

  this.route('projects', {
    path: '/:slugged_route_slug/projects'
  });

  this.route('projects-list', {
    path: '/projects'
  });

  this.route('password', function() {
    this.route('reset');
    this.route('forgot');
  });

  this.route('settings', function() {
    this.route('profile');
    this.route('integrations');
  });

  this.route('signup');

  this.route('slugged-route', {
    path: '/:slugged_route_slug'
  });

  this.route('start', function() {
    this.route('hello');
    this.route('interests');
    this.route('expertise');
    this.route('skills');
  });

  this.route('team');
  this.route('terms');
});

export default Router;

@@ -474,16 +474,68 @@
 ;%0A  %7D,%0A%0A
+  // Track the page view in Segment when it renders%0A
   _track
@@ -996,32 +996,68 @@
 %0A    %7D);%0A  %7D);%0A%0A
+  // GitHub OAuth redirection route%0A
   this.route('gi
@@ -1610,34 +1610,119 @@
 t');
-%0A    this.route('donate');
+ // Where you enter your credit card details%0A    this.route('donate'); // Where you choose your donation amount
 %0A   
@@ -2123,23 +2123,97 @@
 k-you');
-%0A  %7D);%0A
+ // When your donation successfully processed%0A  %7D);%0A%0A  // Organization's projects
 %0A  this.
@@ -2430,32 +2430,51 @@
 orgot');%0A  %7D);%0A%0A
+  // User settings%0A
   this.route('se
@@ -2582,24 +2582,95 @@
 'signup');%0A%0A
+  // User *or* organization routes%0A  // e.g. /code-corps or /joshsmith%0A
   this.route
@@ -2721,32 +2721,55 @@
 te_slug'%0A  %7D);%0A%0A
+  // Onboarding routes%0A
   this.route('st

Add router inline docs