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 { ProcessComponent } from '../../components/process/process.component';
import { CreateCollectionComponent } from '../create-collection/create-collection.component';
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';
@Component({
  selector: 'app-collection-edit',
  templateUrl: './collection-edit.component.html',
  styleUrls: ['./collection-edit.component.scss'],
  imports: [
    CommonModule,
    NzSpaceModule,
    CommonCompModule,
    NzTabsModule,
    ProcessComponent,
    CreateCollectionComponent,
    CompTableListComponent
  ],
  standalone: true,
})
export class CollectionEditComponent implements OnInit {
  active: number = 0;
  eduCollection: Parse.Object | undefined;

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

  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');
      if (id) {
        let query = new Parse.Query('EduCollection');
        query.equalTo('objectId', id);
        this.eduCollection = await query.first();
      }
    })
  }

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