import {Component} from '@angular/core';
import {ListsService} from "@app/_services/lists.service";

@Component({
  selector: 'sorting',
  templateUrl: 'sorting.component.html',
  styleUrls: ['sorting.component.scss']
})
export class SortingComponent {
  public orders = [
    {title: 'По убыванию дат', value: {by: 'dates', dir: 'desc'}, selected: true},
    {title: 'По возрастанию дат', value: {by: 'dates', dir: 'asc'}}
    //{title: 'По алфавиту', value: {by: 'names', dir: 'asc'}}
  ];
  public visible = false;

  constructor(private listsService: ListsService) {
  }

  ngOnInit() {

  }

  get selected() {
    return this.orders.filter(item => {return item.selected})[0];
  }


  set(order: any) {
    this.orders = this.orders.map(item => {
      item.selected = item.value === order.value;
      return item;
    });
    this.listsService.setOrder(order.value);
    this.visible = false;
  }

  order() {
    //this.listsService.setOrder({date: 'desc'});
  }
}
