import { Component, Input, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NzSpaceModule } from 'ng-zorro-antd/space';
import { CommonCompModule } from '../../../services/common.modules';
import { NzTabsModule } from 'ng-zorro-antd/tabs';
import { ActivatedRoute, Router } from '@angular/router';
import Parse from 'parse';
import { EduTextbook } from '../../../schemas/EduTextbook';
import { CompTableListComponent } from '../../../app/comp-table/comp-table-list/comp-table-list.component';
import { ProcessCreateComponent } from './process-create/process-create.component';
import { TextbookComponent } from '../../../app/textbook/textbook.component';

@Component({
  selector: 'app-page-process',
  templateUrl: './page-process.component.html',
  styleUrls: ['./page-process.component.scss'],
  imports: [
    CommonModule,
    NzSpaceModule,
    CommonCompModule,
    NzTabsModule,
    ProcessCreateComponent,
    CompTableListComponent,
    TextbookComponent,
  ],
  standalone: true,
})
export class PageProcessComponent  implements OnInit {
  active: number = 0;
  eduProcess: Parse.Object | undefined;

  EduTextbook = EduTextbook;
  user: Parse.User | undefined;
  className: string | undefined;
  queryParams: any | undefined;
  fieldsArray: Array<any> | undefined;
  filterObj: any = {
    showMore: true, //显示更多字段
    isCheck: false,
    status: ['400'],
    btns: {review:true},
  };
  constructor(
    private activeRoute:ActivatedRoute,
    private router: Router,
  ) {
    this.user = Parse.User.current();
    this.className = this.EduTextbook.className;
    this.fieldsArray = this.EduTextbook.fieldsArray;
    this.queryParams = {
      where: {
        isDeleted: { $ne: true },
        render: true,
        status: '200',
      },
    };
  }

  ngOnInit() {
    this.activeRoute.paramMap.subscribe(async (params) => {
      let id = params.get('id');
      this.queryParams.where['department'] = id
      if (id) {
        let query = new Parse.Query('EduProcess');
        query.include('branch', 'department');
        query.equalTo('objectId', id);
        this.eduProcess = await query.first();
      }
    })
  }

  onCreateProcess(){
    this.router.navigate(['/nav-admin/manage/process/create',{cid:this.eduProcess?.id}])
  }
}
