import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { IonBackButton, IonButtons, IonIcon } from '@ionic/angular/standalone';
import { IonCard, IonCardContent, IonItem, IonList, IonThumbnail } from '@ionic/angular/standalone';
import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/angular/standalone';
import { IonContent, IonHeader, IonTitle, IonToolbar } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { arrowBackOutline } from 'ionicons/icons';
import { CloudObject, CloudQuery } from 'src/lib/ncloud';

addIcons({ arrowBackOutline })

@Component({
  selector: 'app-knowledge-total',
  templateUrl: './knowledge-total.component.html',
  styleUrls: ['./knowledge-total.component.scss'],
  standalone: true,
  imports: [
    IonHeader, IonToolbar, IonTitle, IonContent, IonSegment, IonSegmentButton, IonLabel, IonSegmentView, IonSegmentContent,
    IonThumbnail, CommonModule, IonCard, IonCardContent, IonList, IonItem, IonIcon, IonButtons, IonBackButton
  ]
})
export class KnowledgeTotalComponent implements OnInit {

  constructor(private router: Router) { }

  goToKnowledge(knowledge: CloudObject) {
    const objectId = knowledge.get('title'); // 假设你的主键字段为 'title'
    this.router.navigate(['/tabs/knowledge-page1', { id: objectId }]);
  }

  goToVKnowledge(knowledge: CloudObject) {
    const objectId = knowledge.get('title'); // 假设你的主键字段为 'title'
    this.router.navigate(['/tabs/knowledge-video', { id: objectId }]);
  }


  ngOnInit() {
    // 生命周期：页面加载后，运行医生列表加载函数
    this.loadKnowledgeList()

    this.loadVKnowledgeList()
  }

  // 创建用于数据列表存储的属性
  knowledgeList: Array<CloudObject> = []
  // 查询并加载医生列表的函数
  async loadKnowledgeList() {
    let query = new CloudQuery("Knowledge");
    this.knowledgeList = await query.find()
  }


  // 创建用于数据列表存储的属性
  vknowledgeList: Array<CloudObject> = []
  // 查询并加载医生列表的函数
  async loadVKnowledgeList() {
    let query = new CloudQuery("videoknowledge");
    this.vknowledgeList = await query.find()
  }

}
