import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, RouterOutlet, Router } from '@angular/router';
import { CompTableListComponent } from '../../../../app/comp-table/comp-table-list/comp-table-list.component';
import { EduTextbook } from '../../../../schemas/EduTextbook';
// import { TranslateService } from '@ngx-translate/core';
import * as Parse from "parse";
import { CommonModule } from '@angular/common';
@Component({
  selector: 'app-page-textbook',
  templateUrl: './page-textbook.component.html',
  styleUrls: ['./page-textbook.component.scss'],
  imports: [CommonModule,RouterOutlet,CompTableListComponent],
  standalone: true,
})
export class PageTextbookComponent implements OnInit {
  @ViewChild(CompTableListComponent) list:CompTableListComponent|undefined

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

  constructor(
    private router: Router,
    private activeRoute: ActivatedRoute,
    // private translate:TranslateService,
  ) {
    this.user = Parse.User.current();
    this.className = this.EduTextbook.className
    this.fieldsArray = this.EduTextbook.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()
    });
  }

}
