import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, RouterOutlet } from '@angular/router';
import { CompTableListComponent } from '../../../app/comp-table/comp-table-list/comp-table-list.component';
import _Role from '../../../schemas/_Role';
// import { TranslateService } from '@ngx-translate/core';
import * as Parse from "parse";
import { CommonModule } from '@angular/common';


@Component({
  selector: 'app-page-role',
  templateUrl: './page-role.component.html',
  styleUrls: ['./page-role.component.scss'],
  imports: [CommonModule,RouterOutlet,CompTableListComponent],
  standalone: true,
})
export class PageRoleComponent  implements OnInit {
  @ViewChild(CompTableListComponent) list:CompTableListComponent|undefined

  _Role = _Role
  user:Parse.User|undefined
  className:string|undefined
  queryParams:any|undefined
  fieldsArray:Array<any>|undefined

  constructor(
    private route: ActivatedRoute,
    private activeRoute: ActivatedRoute,
    // private translate:TranslateService,
  ) {
    this.user = Parse.User.current();
    this.className = this._Role.className
    this.fieldsArray = this._Role.fieldsArray
    this.queryParams = {where:{
      // user:this.user?.toPointer(),
      isDeleted:{$ne:true},
    }}
  }

  ngOnInit(): void {
    this.activeRoute.paramMap.subscribe(async (params) => {
      let isDeleted = params.get('isDeleted')
      if(isDeleted){
        this.queryParams.where['isDeleted'] = {$eq:true}
      }else{
        this.queryParams.where['isDeleted'] = {$ne:true}
      }
      this.list?.ngOnInit()
    });
  }

}
