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 _User from '../../../schemas/_User';
// import { TranslateService } from '@ngx-translate/core';
import * as Parse from "parse";
import { CommonModule } from '@angular/common';


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

  _User = _User
  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._User.className
    this.fieldsArray = this._User.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()
    });
  }

}
