import { Pipe, PipeTransform } from '@angular/core';
import { ContentService } from '../services/content.service'; 

@Pipe({
  name: 'orderby'
  //pure: false
})
export class OrderbyDatePipe implements PipeTransform {

  sortBy:any;
 
  constructor(private contentService:ContentService){
  
  }

  transform(value: any, args?: any): any {
     // console.log("value & args::::::::::::::" ,value ,args);
      let newVal = value.sort((a: any, b: any) => {
              let date1;
              let date2 ;
              if(args == 'recent'){
                     date1 = new Date(a.lastUserAccDate);
                     date2 = new Date(b.lastUserAccDate);
                         if (date1 < date2) {
                          return 1;
                      } else if (date1 > date2) {
                          return -1;
                      } else {
                          return 0;
                      }
                  }
             else if (args == 'frequent'){
                     date1 = new Date(a.lastGenAccDate);
                     date2 = new Date(b.lastGenAccDate);
                         if (date1 < date2) {
                          return 1;
                      } else if (date1 > date2) {
                          return -1;
                      } else {
                          return 0;
                      }
                  }
          });
      return newVal;
    }

}
