import {Component, OnInit} from '@angular/core';
import {EditComponent} from '../edit/edit.component';
import {Dialog} from '../../dialog';
import {ICollection, Resource, Service} from 'ngx-jsonapi';


@Component({
  selector: 'app-general',
  templateUrl: './general.component.html',
})
export class GeneralComponent {
  dataInput = [];

  constructor(protected listService: Service,
              protected dialog: Dialog,
              protected editComponent: EditComponent) {
  }

  opendialog() {
    const dialogRef = this.dialog.openWithData(this.editComponent );
  }

  protected _filterInput(service: Service, value: string, key: string = 'name') {
    const remotefilter = {};
    remotefilter[key] = value;
    service.all({
      remotefilter: remotefilter,
      page: {number: 1, size: 5}
    }).subscribe(data => {
      if (data.$source !== 'server' || data.$is_loading)
        return;
      // this.filteredOptions[key] = data.$toArray;
      this.dataInput = data.$toArray;
    });
  }


}
