import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';
import config from './config/environment';

import "./helpers/avatar";
import "./helpers/pluralize";
import "./helpers/repeat";
import "./helpers/stars";

// Used for redirecting after log in.
// TODO: This shouldn't be a global on window.
window.lastVisitedURL = '/';
if (!window.location.href.match('/sign-in')) {
  window.lastVisitedURL = window.location.href;
}

Ember.Route.reopen({
  resetScroll: function() {
    window.scrollTo(0, 0);
  }.on('activate')
});

// Set to false because it breaks polymorphic associations.
// Fixed in this PR: https://github.com/emberjs/data/pull/2586
Ember.MODEL_FACTORY_INJECTIONS = false;

// Plural of anime is anime.
Ember.Inflector.inflector.rules.uncountable.anime = true;
Ember.Inflector.inflector.rules.uncountable.full_anime = true;

// Plural of manga is manga.
Ember.Inflector.inflector.rules.uncountable.manga = true;
Ember.Inflector.inflector.rules.uncountable.full_manga = true;

var App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver: Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;

@@ -486,102 +486,1202 @@
 %0A%7D%0A%0A
-Ember.Route.reopen(%7B%0A  resetScroll: function() %7B%0A    window.scrollTo(0, 0);%0A  %7D.on('activate')
+if (document.createEvent) %7B%0A  window.XContentReadyEvent = document.createEvent('Event');%0A  window.XContentReadyEvent.initEvent('XContentReady', false, false);%0A%0A  window.XPushStateEvent = document.createEvent('Event');%0A  window.XPushStateEvent.initEvent('XPushState', false, false);%0A%0A  document.addEventListener('XPushState', function(e) %7B%0A    let router = App.__container__.lookup('router:main');%0A    Ember.run(function() %7B%0A      router.replaceWith(e.url).then(function(route) %7B%0A        if (route.handlerInfos) %7B%0A          // The route was already loaded%0A          document.dispatchEvent(window.XContentReadyEvent);%0A        %7D%0A      %7D);%0A    %7D);%0A  %7D);%0A%7D%0A%0AEmber.Route.reopen(%7B%0A  willComplete: function() %7B%0A    Ember.RSVP.resolve();%0A  %7D,%0A%0A  resetScroll: function() %7B%0A    window.scrollTo(0, 0);%0A  %7D.on('activate'),%0A%0A  actions: %7B%0A    didTransition: function() %7B%0A      this._super();%0A      let promises = %5B%5D;%0A      this.router.router.currentHandlerInfos.forEach((handler) =%3E %7B%0A        if (handler.handler.willComplete) %7B%0A          promises.push(handler.handler.willComplete());%0A        %7D%0A      %7D);%0A      Ember.RSVP.all(promises).then(() =%3E document.dispatchEvent(window.XContentReadyEvent));%0A    %7D%0A  %7D
 %0A%7D);

Add prerendering hooks