import Em from 'ember';
import getOwner from 'ember-getowner-polyfill';

function hrefTo(context, targetRouteName, ...rest) {
  console.log('GJ: hrefTo', arguments);
  let router = getOwner(context).lookup('router:main');
  if (router === undefined || router.router === undefined) {
    return;
  }

  let lastParam = rest[rest.length - 1];

  let queryParams = {};
  if (lastParam && lastParam.isQueryParams) {
    queryParams = rest.pop();
  }

  let args = [targetRouteName];
  args.push.apply(args, rest);
  args.push({ queryParams: queryParams.values });

  return router.generate.apply(router, args);
}

export { hrefTo };

export default Em.Helper.extend({
  compute([targetRouteName, ...rest]) {
    return hrefTo(this, targetRouteName, ...rest);
  }
});

@@ -123,48 +123,8 @@
 ) %7B%0A
-  console.log('GJ: hrefTo', arguments);%0A
   le

remove console.log