import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { EditTagComponent } from '../components/edit-tag/edit-tag.component';
import { EditRatingStarComponent } from '../components/edit-rating-star/edit-rating-star.component';
import { IonicModule } from '@ionic/angular';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-tab1',
  templateUrl: './tab1.page.html',
  styleUrls: ['./tab1.page.scss'],
  standalone: true,
  imports: [IonicModule, CommonModule, EditTagComponent, EditRatingStarComponent],
})
export class Tab1Page {
  // 存储当前评分的梦境列表
  recentDreams = [
    {
      title: '飞翔的城市',
      date: new Date('2023-10-20'),
      emotion: '愉悦',
      rating: 4, // 默认评分
    },
    {
      title: '迷失的森林',
      date: new Date('2023-10-18'),
      emotion: '恐惧',
      rating: 2, // 默认评分
    },
  ];

  // 存储编辑的标签列表
  editTags: string[] = [];

  constructor(private router: Router) {}
  goTestPage(){
    this.router.navigate(['/tabs/test']);
  }


  // 更新梦境评分
  updateDreamRating(dream: any, newRating: number): void {
    console.log(`梦境 "${dream.title}" 的评分更新为：`, newRating);
    dream.rating = newRating;
  }

  // 更新标签值
  setTagsValue(ev: string[]): void {
    console.log('标签更新：', ev);
    this.editTags = ev;
  }

  // 导航到指定页面
  navigateTo(page: string): void {
    this.router.navigate([`/tabs/${page}`]);
  }

  // 获取情感图标
  getEmotionIcon(emotion: string): string {
    switch (emotion) {
      case '愉悦':
        return 'happy-outline';
      case '恐惧':
        return 'alert-circle-outline';
      case '平静':
        return 'leaf-outline';
      case '悲伤':
        return 'sad-outline';
      default:
        return 'help-outline';
    }
  }

  // 可选：用于 *ngFor 的 trackBy 函数
  trackByDream(index: number, dream: any): any {
    return dream.title;
  }
}