import { Component, OnInit, ViewChild } from '@angular/core';
import { CommonCompModule } from '../../../services/common.modules';
import { Router, ActivatedRoute } from '@angular/router';
import { ReactiveFormsModule } from '@angular/forms';
import { NzAnchorModule } from 'ng-zorro-antd/anchor';
import { DatePipe } from '@angular/common';
import Parse from 'parse';
import { NzCollapseModule } from 'ng-zorro-antd/collapse';
import { CommonModule } from '@angular/common';
import { NzTabsModule } from 'ng-zorro-antd/tabs';
import { NzTableModule } from 'ng-zorro-antd/table';
import { UploadCollectComponent } from '../../nav-province-contact/components/upload-collect/upload-collect.component';
@Component({
  selector: 'app-textbook-details',
  imports: [
    CommonCompModule,
    ReactiveFormsModule,
    NzAnchorModule,
    DatePipe,
    NzCollapseModule,
    CommonModule,
    NzTabsModule,
    NzTableModule,
    UploadCollectComponent
  ],
  standalone: true,
  templateUrl: './textbook-details.component.html',
  styleUrls: ['./textbook-details.component.scss'],
  providers: [DatePipe],
})
export class TextbookDetailsComponent implements OnInit {
  @ViewChild('templ1') templ1: any;
  user?: Parse.Object;
  textBook: object | any = {};
  /**扩展表记录 */
  eduTextbookVolumeList: Array<any> = [];
  active:number = 0
  /** 册数*/
  typeNumber: any;
  /** 申报类型*/
  type: any;
  eduTextbookVolumeParseList:Array<Parse.Object> = []
  constructor(
    private router: Router,
    private activeRoute: ActivatedRoute
  ) {}

  ngOnInit() {
    this.activeRoute.paramMap.subscribe(async (params) => {
      this.user = Parse.User.current();
      let id = params.get('id');
      console.log(id);
      if (id) {
        let query = new Parse.Query('EduTextbook');
        query.equalTo('objectId', id);
        query.include('childrens');
        let r = await query.first();
        this.textBook = r?.toJSON();
        console.log(this.textBook);
        this.eduTextbookVolumeList = this.textBook?.childrens;
        this.eduTextbookVolumeParseList = r?.get('childrens')
      }
    });
  }

  openFile(url: string) {
    console.log(url);
    window.open(url);
  }
  /**锚点 */
  herfLink(domId: string) {
    console.log(domId);
    let topEle = document.getElementById(domId);
    if (topEle) {
      topEle.scrollIntoView({ behavior: 'smooth' });
    }
  }
}
