import { Component, OnInit, ViewChild, Input } from '@angular/core';
import { ActivatedRoute, RouterOutlet, Router } from '@angular/router';
import { CompTableListComponent } from '../../../app/comp-table/comp-table-list/comp-table-list.component';
import { NzPageHeaderModule } from 'ng-zorro-antd/page-header';
import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
import * as Parse from 'parse';
import { CommonModule } from '@angular/common';
import { textbookServer } from '../../../services/textbook';
import { TextbookComponent } from '../../../app/textbook/textbook.component';
import { NzSpaceModule } from 'ng-zorro-antd/space';
import { CommonCompModule } from '../../../services/common.modules';
import { NzTabsModule } from 'ng-zorro-antd/tabs';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'app-page-textbook',
  templateUrl: './page-textbook.component.html',
  styleUrls: ['./page-textbook.component.scss'],
  imports: [
    CommonModule,
    RouterOutlet,
    TextbookComponent,
    CompTableListComponent,
    NzPageHeaderModule,
    CommonCompModule,
    NzBreadCrumbModule,
    NzSpaceModule,
    NzTabsModule,
  ],
  standalone: true,
})
export class PageTextbookComponent implements OnInit {
  @ViewChild(CompTableListComponent) list: CompTableListComponent | undefined;
  @Input('discard') discard: boolean = false;
  @Input('render') render: boolean = false;
  active: number = 0;

  user: Parse.User | undefined;
  //草稿
  draftFilterObj:any = {
    showMore: true, //显示更多字段
    isCheck: true,
    status: ['101','102','300'],
    team:true,
    btns: {
      export:true,
      review:true,//查阅
    },
  }
  //待提交教材
  beforeFilterObj: any = {
    showMore: true, //显示更多字段
    isCheck: true,
    status: ['103'],
    team:true,
    btns: {
      beforSubmit: true, //提交至工作联系人
      reject: true, //退回教材
      export:true
    },
  };
  //待评审教材
  afterFilterObj: any = {
    showMore: true, //显示更多字段
    isCheck: true,
    status: ['200'],
    team:true,
    noStared: true,
    btns: {
      export:true,
      review:true,//查阅
    },
  };
  eduProcess?:Parse.Object

  constructor(
    public tbookSer: textbookServer,
    private message: NzMessageService,
    private router: Router,
    private activeRoute: ActivatedRoute // private translate:TranslateService,
  ) {
    this.user = Parse.User.current();
  }

  ngOnInit(): void {
    this.getProcess()
  }
  async getProcess(){
    let parentMap = await this.tbookSer.formatNode(
      this.tbookSer?.profile?.user?.department?.objectId
    );
    if (!parentMap[1]?.key) return;
    let query = new Parse.Query('EduProcess');
    query.equalTo('department', parentMap[1]?.key);
    // query.lessThanOrEqualTo('startDate', new Date());
    // query.greaterThan('deadline', new Date());
    query.notEqualTo('isDeleted', true);
    // query.notEqualTo('status', '100');
    let res = await query.first();
    this.eduProcess = res
  }
  toUrl(url: string, params?: object) {
    if (params) {
      this.router.navigate([url, params]);
    } else {
      this.router.navigate([url]);
    }
  }
}
