import { Component,OnInit } from '@angular/core';
import { NavController } from '@ionic/angular';
"assets"; [
  "src/favicon.ico",
  "src/assets"
]
import Parse from "parse";
@Component({
  selector: 'app-tab2',
  templateUrl: 'tab2.page.html',
  styleUrls: ['tab2.page.scss']
})

export class Tab2Page implements OnInit {
  selectedSegment: string = 'categories';
  categories: any[] = [
    { name: '诗经' },
    { name: '楚辞' },
    { name: '禅' },
    { name: '酒' },
    { name: '离别' },
    { name: '战争' }
  ];
  dynasties: string[] = ['唐', '宋', '元', '明', '清'];
  authors: string[] = ['李白', '杜甫', '王维', '苏轼'];
  poems: any[] = [
    { title: '静夜思', dynasty: '唐', author: '李白', firstLine: '床前明月光' },
    { title: '春望', dynasty: '唐', author: '杜甫', firstLine: '国破山河在' },
    // 更多示例数据
  ];
  selectedDynasty: string | undefined;
  selectedAuthor: string | undefined;

  ngOnInit() { }

  segmentChanged(event: any) {
    this.selectedSegment = event.detail.value;
  }

  get filteredPoems() {
    return this.poems.filter(poem => {
      return (!this.selectedDynasty || poem.dynasty === this.selectedDynasty) &&
             (!this.selectedAuthor || poem.author === this.selectedAuthor);
    });
  }
 poetries = [
    {
      title: '南乡子·登京口北固亭有怀',
      author: '辛弃疾【宋代】',
      content: '何处望神州？满眼风光北固楼。干古兴亡多少事？悠悠。不尽长江滚滚流。年少万兜整，坐断东南战未休。天下英雄谁敌手？曹刘。生子当如孙仲谋。'
    },
    {
      title: '菩萨蛮·书江西造口壁',
      author: '辛弃疾【宋代】',
      content: '郁孤台下清江水，中间多少行人泪。可无数山。'
    }
    // Add more poems as needed
  ];

  isLastPoetry(poetry: any): boolean {
    return poetry === this.poetries[this.poetries.length - 1];
  }


 //搜索下拉框内容
 results: Parse.Object[] = []
 segment = 'tang';
 search(event: any) {
   console.log('Searching for:', event.detail.value);
   if (event?.detail?.value) {
     this.loadShigeList(event?.detail?.value)
   }
 }
 filteredAuthors: any[] = [];

 async loadShigeList(search: string) {
   let query = new Parse.Query("Shige");
   query.select("title");
   query.contains("title", search);
   query.limit(5);
   this.results = await query.find();
 }

 constructor(private navController: NavController) { }
 goToDetailPage(item: Parse.Object) {
   this.results = []
   this.navController.navigateForward('/detail/' + item.id);
 }








}
