import { Component, Input, OnInit } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CommonCompModule } from '../../../../services/common.modules';
import { Router, ActivatedRoute } from '@angular/router';
import { NzSelectModule } from 'ng-zorro-antd/select';
import Parse from 'parse';
import {
  NonNullableFormBuilder,
} from '@angular/forms';
import { textbookServer } from '../../../../services/textbook';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalService } from 'ng-zorro-antd/modal';
import { MatButtonModule } from '@angular/material/button';
import { setHours } from 'date-fns';
import { NzRadioModule } from 'ng-zorro-antd/radio';
import { ProfileComponent } from '../../../nav-admin/components/profile/profile.component';
import { DatePipe } from '@angular/common';
@Component({
  selector: 'app-process-create',
  templateUrl: './process-create.component.html',
  styleUrls: ['./process-create.component.scss'],
  imports: [
    CommonCompModule,
    FormsModule,
    ReactiveFormsModule,
    NzSelectModule,
    MatButtonModule,
    ProfileComponent,
    NzRadioModule,
    DatePipe
  ],
  standalone: true,
})
export class ProcessCreateComponent implements OnInit {
  timeDefaultValue = setHours(new Date(), 0);

  eduProcess: Parse.Object | undefined;
  showProfileFrom: boolean = false;
  @Input('isEdit') isEdit: boolean = false; //当前是否作为编辑子组件
  profileId: string = '';
  isVisible: boolean = false;
  searchValue: string = ''; //搜索部门内容

  constructor(
    private activeRoute: ActivatedRoute,
    private router: Router,
    public tbookSer: textbookServer,
    private fb: NonNullableFormBuilder,
    private msg: NzMessageService,
    private modal: NzModalService
  ) {}

  ngOnInit() {
    this.activeRoute.paramMap.subscribe(async (params) => {
      let id = params.get('id');
      if (id) {
        this.isEdit = true;
        let query = new Parse.Query('EduProcess');
        query.include('branch', 'department');
        query.equalTo('objectId', id);
        this.eduProcess = await query.first();
        console.log(this.eduProcess?.get('profileSubmitted')?.id);
      }
    });
  }
}
