import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { CloudObject, CloudQuery } from 'src/lib/ncloud';
import { 
  IonHeader, 
  IonToolbar, 
  IonTitle, 
  IonContent, 
  IonButtons, 
  IonBackButton, 
  IonCard, 
  IonCardHeader, 
  IonCardTitle, 
  IonCardSubtitle, 
  IonCardContent, 
  IonChip, 
  IonLabel, 
  IonIcon, 
  IonButton, 
  IonImg, 
  IonSpinner, 
  NavController
} from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { star, download, create } from 'ionicons/icons';

@Component({
  selector: 'app-page-book-display',
  templateUrl: './page-book-display.component.html',
  styleUrls: ['./page-book-display.component.scss'],
  standalone: true,
  imports: [
    CommonModule,
    IonHeader, 
    IonToolbar, 
    IonTitle, 
    IonContent, 
    IonButtons, 
    IonBackButton, 
    IonCard, 
    IonCardHeader, 
    IonCardTitle, 
    IonCardSubtitle, 
    IonCardContent, 
    IonChip, 
    IonLabel, 
    IonIcon, 
    IonButton, 
    IonImg, 
    IonSpinner
  ]
})
export class PageBookDisplayComponent  implements OnInit {

   book: CloudObject | undefined | null;

  back(){
    this.navCtrl.back()
  }

  constructor(
    private route: ActivatedRoute,
    private navCtrl: NavController
  ) {
    addIcons({ star, download, create });
    
    this.route.params.subscribe(params => {
      console.log(params);
      this.loadBook(params['bookId']);
    });
  }

  async loadBook(bookId: string) {
    let query = new CloudQuery("DocumentCategory");
    this.book = await query.get(bookId);
  }

  ngOnInit() {}

}
