import { Component } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { CourseDetailPage } from './course-detail/course-detail.page';

@Component({
  selector: 'app-tab2',
  templateUrl: 'tab2.page.html',
  styleUrls: ['tab2.page.scss'],
  standalone: false
})
export class Tab2Page {
  categories = [
    {
      name: '体态矫正',
      icon: 'body-outline',
      courses: [
        { id: 1, title: '肩部舒展训练', duration: 15, difficulty: 2, progress: 0.4 },
        { id: 2, title: '脊柱灵活性提升', duration: 20, difficulty: 3, progress: 0.2 }
      ]
    },
    {
      name: '力量训练',
      icon: 'barbell-outline',
      courses: [
        { id: 3, title: '核心肌群激活', duration: 12, difficulty: 1, progress: 0.7 },
        { id: 4, title: '下肢力量训练', duration: 25, difficulty: 3, progress: 0 }
      ]
    }
  ];

  aiRecommendedCourses = [
    {
      name: 'AI推荐',
      icon: 'sparkles-outline',
      courses: [
        { id: 5, title: '雨天室内训练', duration: 20, difficulty: 2, progress: 0, weather: 'rainy', time: undefined },
        { id: 6, title: '晨间唤醒训练', duration: 15, difficulty: 1, progress: 0, time: 'morning', weather: undefined }
      ]
    }
  ];

  constructor(private modalCtrl: ModalController) {
    this.loadAiRecommendations();
  }

  loadAiRecommendations() {
    // 修改后的推荐课程设置
    const hour = new Date().getHours();
    if (hour < 12) {
      this.aiRecommendedCourses[0].courses = [
        { id: 6, title: '晨间唤醒训练', duration: 15, difficulty: 1, progress: 0, time: 'morning', weather: undefined }
      ];
    }
  }

  async openCourseDetail(course: any) {
    const modal = await this.modalCtrl.create({
      component: CourseDetailPage,
      componentProps: { course }
    });
    await modal.present();
  }

  getDifficultyStars(difficulty: number): string {
    return '★'.repeat(difficulty) + '☆'.repeat(3 - difficulty);
  }
}
