import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'filter',
  pure : false
})
export class FilterPipe implements PipeTransform {
  result:any = [];
  transform(items: any[], filter: any): any {
    if (!items || !filter) {
        return items;
    }
    // filter items array, items which match and return true will be
    // kept, false will be filtered out
    this.result = items.filter(item => item.smpin.indexOf(filter) !== -1)
    if(this.result.length != 0){
      return this.result;
    }else{
      return items.filter(item => item.name.indexOf(filter.toUpperCase()) !== -1);
    }
  }

}
