import Controller from '@ember/controller';
import {tracked} from '@glimmer/tracking'
import { isEmpty } from '@ember/utils';  

export default class ApplicationController extends Controller {
  appName = 'Ember Twiddle';
  @tracked list = [
    "Active Directory and Group Policy",
    "Airwatch",
    "Apple iOS Apps",
    "Blackberry Enterprise Server(BES)",
    "Business Continuity and Disaster Recovery",
    "Database Analysis",
    "Decompiling and Static Analysis",
]
	@tracked filter
  
  get pattern() {
    if (isEmpty(this.filter)) {
      return ''
    }
    return this.filter
      .split('')
      .reduce(function(a,b) {return a + '[^'+b+']*' + b})
  }
  
	get filteredList() {
    if (isEmpty(this.filter)) {
    return this.list
    }
    let reg = new RegExp(this.pattern, "gi")
    return this.list.filter(x => reg.test(x))	
  }
}