 toImmutable = require 'app/util/toImmutable'
 immutable   = require 'immutable'
 isEmailValid = require 'app/util/isEmailValid'
+getFullnameFromAccount = require 'app/util/getFullnameFromAccount'
 
 
 team = ['TeamStore']

  re = new RegExp(value, 'i')

  if member.get('status') is 'pending'
    re.test(member.get('email')) or \
    re.test(member.get('firstname')) or \
    re.test(member.get('lastname'))
  else
    re.test(member.get('profile').get('email')) or \
    re.test(member.get('profile').get('firstname')) or \
    re.test(member.get('profile').get('lastname'))


membersWithPendingInvitations = [

    return members
]

sortedMembersWithPendingInvitations = [
  membersWithPendingInvitations
  (members) ->

    members.sortBy (member) ->
      if member
        if member.get('status') is 'pending'
          member.get('firstName')  if member.get 'firstname'
          member.get('lastName')  if member.get 'lastName'
          member.get('email')
        else
          member.getIn(['profile', 'firstName'])  if member.getIn(['profile', 'firstName'])
          member.getIn(['profile', 'lastName'])  if member.getIn(['profile', 'lastName'])
          member.getIn(['profile', 'email'])
]


filteredMembersWithRole = [
  sortedMembersWithPendingInvitations
  searchInputValue
  (members, value) ->
    return members  if value is ''
