import {Component, OnChanges, OnInit, TemplateRef, ViewChild} from '@angular/core';
import {User, UsersService} from '../../../classes/resorcess/users.service';
import {ICollection} from 'ngx-jsonapi';
import {ListComponent} from '../../../classes/base_components/list/list.component';
import {Dialog} from '../../../classes/base_components/dialog/dialog';
import {EditUsersComponent} from './edit-users/edit-users.component';
import {Http} from '@angular/http';

@Component({
  selector: 'app-user',
  templateUrl: './users.component.html',
  styleUrls: ['./users.component.scss']
})
export class UsersComponent extends ListComponent implements OnInit {
  @ViewChild('filter_id') public filter_id_ref: TemplateRef<any>;
  @ViewChild('filter_name') public filter_name_ref: TemplateRef<any>;
  @ViewChild('filter_mobile') public filter_mobile_ref: TemplateRef<any>;
  @ViewChild('filter_email') public filter_email_ref: TemplateRef<any>;
  @ViewChild('filter_docDegree') public filter_docDegree_ref: TemplateRef<any>;
  users: ICollection<User>;
  data: any;


  constructor(public listService: UsersService,
              public dialog: Dialog,
              public http: Http,
  ) {
    super(listService, dialog, EditUsersComponent, http);
    this.listService.register();
  }

  ngOnInit() {
    this.columns = [
      {
        prop: 'name',
        name: 'نام',
        filter: this.filter_name_ref,
      },
      {
        prop: 'mobile',
        name: 'موبایل',
        filter: this.filter_mobile_ref,
      },
      {
        prop: 'email',
        name: 'ایمیل',
        filter: this.filter_email_ref,
      },
      {
        prop: 'id',
        name: 'شناسه',
        filter: this.filter_id_ref,
      },
    ];
    super.ngOnInit();
  }
}

// todo test
//      {
//         prop: 'university',
//         name: 'دانشگاه',
//         filter: this.filter_university_ref,
//         isRelationship: true,
//         mustIncluded: true,
//},
