import ENV from 'irene/config/environment';

const initialize = function(application) {
  // inject Ajax
  application.inject('route', 'ajax', 'service:ajax');
  application.inject('component', 'ajax', 'service:ajax');

  // Inject notify
  application.inject('route', 'notify', 'service:notification-messages');
  application.inject('component', 'notify', 'service:notification-messages');
  application.inject('authenticator', 'notify', 'service:notification-messages');

  // Inject realtime
  application.inject('component', 'realtime', 'service:realtime');

  // Inject Store
  application.inject('component', 'store', 'service:store');

  // Inject ENV
  if (ENV.environment !== 'test') {
    // FIXME: Fix this test properly
    application.register('env:main', ENV, {singleton: true, instantiate: false});
    return application.inject('component', 'env', 'env:main');
  }
};

const IreneInitializer = {
  name: 'irene',
  initialize
};

export {initialize};
export default IreneInitializer;

@@ -632,24 +632,1447 @@
 e:store');%0A%0A
+  let runtimeConfig = window.runtimeGlobalConfig;%0A%0A  function parseUrl(url) %7B%0A    let parser = document.createElement('a'), searchObject = %7B%7D, queries, split, i;%0A    parser.href = url;%0A    queries = parser.search.replace(/%5E%5C?/, '').split('&');%0A    for(i = 0; i %3C queries.length; i++ ) %7B%0A        split = queries%5Bi%5D.split('=');%0A        searchObject%5Bsplit%5B0%5D%5D = split%5B1%5D;%0A    %7D%0A    return parser;%0A  %7D%0A%0A  if(runtimeConfig) %7B%0A    ENV.host = runtimeConfig.IRENE_API_HOST %7C%7C ENV.host;%0A    var devicefarmEnv = runtimeConfig.IRENE_DEVICEFARM_URL;%0A    if(devicefarmEnv) %7B%0A      let deviceFarmWebsockifyHost = parseUrl(devicefarmEnv);%0A      let deviceFarmSsl = deviceFarmWebsockifyHost.protocol === %22wss:%22;%0A      ENV.deviceFarmSsl = deviceFarmSsl;%0A      ENV.deviceFarmPort = deviceFarmWebsockifyHost.port %7C%7C (deviceFarmSsl ? 443:80);%0A      ENV.deviceFarmHost = deviceFarmWebsockifyHost.hostname;%0A    %7D%0A    ENV.socketPath = runtimeConfig.IRENE_API_SOCKET_PATH %7C%7C ENV.socketPath;%0A    ENV.enableSSO = runtimeConfig.IRENE_ENABLE_SSO %7C%7C ENV.enableSSO;%0A    ENV.isEnterprise = runtimeConfig.ENTERPRISE %7C%7C ENV.isEnterprise;%0A    ENV.whitelabel = %7B%0A      enabled: runtimeConfig.WHITELABEL_ENABLED %7C%7C ENV.whitelabel.enabled,%0A      name: runtimeConfig.WHITELABEL_ENABLED %7C%7C ENV.whitelabel.name,%0A      logo: runtimeConfig.WHITELABEL_ENABLED %7C%7C ENV.whitelabel.logo,%0A      theme: runtimeConfig.WHITELABEL_ENABLED %7C%7C ENV.whitelabel.theme%0A    %7D;%0A  %7D%0A%0A
   // Inject 

add runtime config