import Ember from 'ember';
import DS from 'ember-data';
import { translationMacro as t } from "ember-i18n";

const { Component, computed } = Ember;

export default Component.extend({
  i18n: Ember.inject.service(),
  learnerGroup: null,
  notInThisGroup: t('learnerGroups.notInThisGroup'),
  topLevelGroupMembersNotInThisGroup: computed(
    'learnerGroup.topLevelGroup.allDescendantUsers.[]',
    'learnerGroup.user.[]',
    function(){
      var deferred = Ember.RSVP.defer();
      this.get('learnerGroup.usersOnlyAtThisLevel').then(currentUsers => {
        this.get('learnerGroup.topLevelGroup').then(topLevelGroup => {
          topLevelGroup.get('allDescendantUsers').then(users => {
            let filteredUsers = users.filter(
              user => !currentUsers.contains(user)
            );
            deferred.resolve(filteredUsers.sortBy('fullName'));
          });
        });
      });

      return DS.PromiseArray.create({
        promise: deferred.promise
      });
    }
  ),
  cohortMembersNotInAnyGroup: computed(
    'learnerGroup.topLevelGroup.allDescendantUsers.[]',
    'learnerGroup.user.[]',
    'learnerGroup.cohort.users.[]',
    function(){
      var deferred = Ember.RSVP.defer();
      this.get('learnerGroup.topLevelGroup').then(topLevelGroup => {
        topLevelGroup.get('allDescendantUsers').then(currentUsers => {
          this.get('learnerGroup.cohort').then(cohort => {
            cohort.get('users').then(users => {
              let filteredUsers = users.filter(
                user => !currentUsers.contains(user)
              );
              deferred.resolve(filteredUsers.sortBy('fullName'));
            });
          });
        });
      });
      return DS.PromiseArray.create({
        promise: deferred.promise
      });
    }
  )
});

@@ -401,32 +401,33 @@
 earnerGroup.user
+s
 .%5B%5D',%0A    functi
@@ -1109,16 +1109,17 @@
 oup.user
+s
 .%5B%5D',%0A  

Fix computed property definition in learner groups