import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { CommonCompModule } from '../../../services/common.modules';
import { Router, ActivatedRoute } from '@angular/router';
import { ReactiveFormsModule } from '@angular/forms';
import { BasicInComponent } from '../components/basic-in/basic-in.component';
import { TextbookPertainComponent } from '../components/textbook-pertain/textbook-pertain.component';
import { TextbookContentComponent } from '../components/textbook-content/textbook-content.component';
import { AttachmentComponent } from '../components/attachment/attachment.component';
// import { NzLayoutModule } from 'ng-zorro-antd/layout';
import Parse from 'parse';

@Component({
  selector: 'app-apply',
  imports: [
    CommonCompModule,
    ReactiveFormsModule,
    BasicInComponent,
    TextbookPertainComponent,
    TextbookContentComponent,
    AttachmentComponent,
  ],
  standalone: true,
  templateUrl: './apply.component.html',
  styleUrls: ['./apply.component.scss'],
})
export class ApplyComponent implements OnInit {
  textBook: Parse.Object | any;
  state: number = 0;
  get stateMap() {
    let map: any = {
      '0': '教材基本信息',
      '1': '教材适用情况',
      '2': '申报教材建设历程',
      '3': '附件材料',
    };
    return map[this.state];
  }
  showFrom: boolean = false;

  constructor(private router: Router, private activeRoute: ActivatedRoute) {}

  async ngOnInit() {
    this.activeRoute.paramMap.subscribe(async (params) => {
      let id = params.get('id');
      if (id) {
        let query = new Parse.Query('EduTextbook');
        query.equalTo('objectId', id);
        this.textBook = await query.first();
        console.log(this.textBook);
        if(this.textBook?.get('render')){
          window.alert("已提交，禁止编辑")
          history.back()
        }
      }
      this.showFrom = true;
    });
  }
  changeState(event: string | any) {
    console.log(event);
    if(event?.textBook){
      this.textBook = event?.textBook
    }
    if (event?.type == 'pre') {
      this.state--;
    } else if(event?.type == 'next'){
      this.state++;
    }
    let topEle = document.getElementById('top')
    if(topEle){
      topEle.scrollIntoView({ behavior: 'smooth' });
    }
  }
  save() {}

  back() {
    history.back();
  }
}
