import {Component, OnInit, TemplateRef, ViewChild} from '@angular/core';
import {PermissionGroupsService, PermissionsService} from '../../../classes/resorcess/permissions.service';
import {ListComponent} from '../../../classes/base_components/list/list.component';
import {Dialog} from '../../../classes/base_components/dialog/dialog';
import {EditPermissionsComponent} from './edit-permissions/edit-permissions.component';
import {Http} from '@angular/http';

@Component({
  selector: 'app-permissions',
  templateUrl: './permissions.component.html',
  styleUrls: ['./permissions.component.scss']
})
export class PermissionsComponent extends ListComponent implements OnInit {
  @ViewChild('filter_id') public filter_id_ref: TemplateRef<any>;
  @ViewChild('filter_name') public filter_name_ref: TemplateRef<any>;
  @ViewChild('filter_slug') public filter_slug_ref: TemplateRef<any>;
  @ViewChild('filter_group') public filter_group_ref: TemplateRef<any>;
  @ViewChild('myTable') table: any;
  limit = 40;
  permission_groups = [];

  constructor(
    public listService: PermissionsService,
    public dialog: Dialog,
    public permissionGroupsService: PermissionGroupsService,
    public http: Http,
  ) {
    super(listService, dialog, EditPermissionsComponent, http);
    permissionGroupsService.register();
    const basics = JSON.parse(localStorage.getItem('basics'));
    this.permission_groups = basics['permission_groups'];
  }

  toggleExpandGroup(group) {
    this.table.groupHeader.toggleExpandGroup(group);
  }

  ngOnInit() {
    this.columns = [

      {
        prop: 'name',
        name: 'نام',
        filter: this.filter_name_ref,
      },
      {
        prop: 'slug',
        name: 'اسلاگ',
        filter: this.filter_slug_ref,
      },
      {
        prop: 'group',
        name: 'گروه',
        isRelationship: true,
        mustIncluded: true,
        filter: this.filter_group_ref,
      },
      {
        prop: 'id',
        name: 'id',
        filter: this.filter_id_ref,
      },
    ];
    super.ngOnInit();

  }

}
