import { Component, OnInit } from '@angular/core';
import { CommonCompModule } from '../../../services/common.modules';
import { Router } from '@angular/router';
import * as Parse from 'parse';
import { NzTabsModule } from 'ng-zorro-antd/tabs';
import { PageTextbookComponent } from '../components/page-textbook/page-textbook.component';
import { textbookServer } from '../../../services/textbook';
import { TextbookComponent } from '../../../app/textbook/textbook.component';
import { DatePipe } from '@angular/common';

@Component({
  selector: 'app-space',
  standalone: true,
  imports: [
    CommonCompModule,
    NzTabsModule,
    PageTextbookComponent,
    TextbookComponent,
    DatePipe,
  ],
  templateUrl: './space.component.html',
  styleUrls: ['./space.component.scss'],
  providers: [DatePipe],
})
export class SpaceComponent implements OnInit {
  user: Parse.Object | any = Parse.User.current();
  active: number = 0;
  myTextBook:any = {
    isCheck:true,
    status:['101','102','300'],
    btns:{
      edit:true,//编辑
      export:true,
      isDelete:true, //删除权限
      submit:true //提交
    }
  }
  submitTextBook = {
    status:['103','200','201','400'],
    btns:{
      review:true,//查阅
    }
  }
  eduProcess?:Parse.Object

  constructor(private router: Router, public tbookSer: textbookServer) {}

  async ngOnInit() {
    let parentMap = await this.tbookSer.formatNode(
      this.tbookSer?.profile?.user?.department?.objectId
    );
    console.log(parentMap);
    await this.getEduProcess(parentMap[1]?.key);
  }
  async getEduProcess(id: string){
    if (!id) return;
    let query = new Parse.Query('EduProcess');
    query.equalTo('department', id);
    // query.lessThanOrEqualTo('startDate', new Date());
    // query.greaterThan('deadline', new Date());
    query.notEqualTo('isDeleted', true);
    // query.containedIn('status', ['200', '201','300', '400']);
    let res = await query.first();
    this.eduProcess = res
  }
  goUrl(url: string, params?: object | any) {
    console.log(url);
    if (params) {
      this.router.navigate([url, params]);
    } else {
      this.router.navigate([url]);
    }
  }
}
