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';
@Component({
  selector: 'app-textbook-details',
  imports: [
    CommonCompModule,
    ReactiveFormsModule,
    NzAnchorModule,
    DatePipe,
  ],
  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 = {}
  constructor(private router: Router, private activeRoute: ActivatedRoute) {}

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

  handleClick(e: string): void {
    console.log(e);
  }
  back() {
    history.back();
  }
  edit(){
    this.router?.navigate(['/nav-author/manage/apply',{id:this.textBook.objectId}],{ replaceUrl: true })
  }
  openFile(url:string){
    console.log(url);
    window.open(url)
  }
}
