import { Component, OnInit } from '@angular/core';
import { DataImporter } from '../import-book-data';
import { CloudObject, CloudQuery } from 'src/lib/ncloud';
import { NavController } from '@ionic/angular/standalone';
import { DatePipe } from '@angular/common';
import { IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonListHeader, IonLabel, IonItem, IonIcon, IonCard, IonCardHeader, IonCardTitle, IonCardContent, IonGrid, IonRow, IonCol, IonBadge, IonFab, IonFabButton } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { documentTextOutline, documentOutline, bookOutline, cloudDownloadOutline } from 'ionicons/icons';


@Component({
  selector: 'app-page-book-list',
  templateUrl: './page-book-list.component.html',
  styleUrls: ['./page-book-list.component.scss'],
  standalone: true,
  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonListHeader, IonLabel, IonItem, IonIcon, IonCard, IonCardHeader, IonCardTitle, IonCardContent, IonGrid, IonRow, IonCol, IonBadge, IonFab, IonFabButton, DatePipe]
})
export class PageBookListComponent  implements OnInit {

  constructor(
    private navCtrl: NavController
  ) {
    addIcons({ documentTextOutline, documentOutline, bookOutline, cloudDownloadOutline });
  }

  ngOnInit() {
    this.loadBookData();
  }

  categorieList: Array<CloudObject> = [];
  documentList: Array<CloudObject> = [];
  knowledgeList: Array<CloudObject> = [];

  async loadBookData() {
    try {
      let query1 = new CloudQuery("DocumentCategory");
      this.categorieList = await query1.find();
      
      let query2 = new CloudQuery("LegalDocument");
      this.documentList = await query2.find();
      
      let query3 = new CloudQuery("LegalKnowledge");
      this.knowledgeList = await query3.find();
    } catch (error) {
      console.error('加载数据失败:', error);
    }
  }

  goBook(book: CloudObject) {
    this.navCtrl.navigateForward(['tabs', 'demo', 'book', 'display', book?.id]);
  }

  importData() {
    DataImporter.executeFullImport();
  }

}
