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

@Pipe({
    name: 'filterss'
})


// export class FilterPipe implements PipeTransform {
//   transform(items: any[], searchText: string): any[] {
//     if(!items) return [];
//     if(!searchText) return items;
//     searchText = searchText.toLowerCase();
//     return items.filter( it => {
//       return it.toLowerCase().includes(searchText);
//     });
//     }
// }

export class FilterPipe implements PipeTransform {
  transform(value: any, input: string) {
      if (input) {
          input = input.toLowerCase();
          console.log(value)
          return value.filter(function (el: any) {
              console.log(el);
            // if(el.address == null){
            //     return el.city.toLowerCase().indexOf(input) > -1 || el.state.toLowerCase().indexOf(input) > -1;
            // }
            // else if(el.city == null){
            //     return el.address.toLowerCase().indexOf(input) > -1 || el.state.toLowerCase().indexOf(input) > -1;
            // }
            // else if(el.state == null){
            //     return el.address.toLowerCase().indexOf(input) > -1 || el.city.toLowerCase().indexOf(input) > -1;
            // }
            //    return el.address.toLowerCase().indexOf(input) > -1 || el.city.toLowerCase().indexOf(input) > -1 || el.state.toLowerCase().indexOf(input) > -1;
            if((el.address != null) && (el.city == null || el.state == null)){
                return el.address.toLowerCase().indexOf(input) > -1 ;
            }
            else if((el.city != null)&& (el.address == null || el.state == null)){
                return el.city.toLowerCase().indexOf(input) > -1;
            }
            else if((el.state != null) && (el.city == null || el.address == null)){
                return el.state.toLowerCase().indexOf(input) > -1;
            }
            else{
                return el.address.toLowerCase().indexOf(input) > -1 || el.city.toLowerCase().indexOf(input) > -1 || el.state.toLowerCase().indexOf(input) > -1;
            }

            // if(el.address != null){
            //     return el.address.toLowerCase().indexOf(input) > -1 ;
            // }
            // else if(el.city != null){
            //     return el.city.toLowerCase().indexOf(input) > -1;
            // }
            // else if(el.state != null){
            //     return el.state.toLowerCase().indexOf(input) > -1;
            // }
            // else{
            //     return el.address.toLowerCase().indexOf(input) > -1 || el.city.toLowerCase().indexOf(input) > -1 || el.state.toLowerCase().indexOf(input) > -1;
            // }
          })
      }
      return value;
  }
}