import { Component, OnInit } from '@angular/core';
import { 
  IonHeader, 
  IonToolbar, 
  IonTitle, 
  IonContent,
  IonButtons,
  IonBackButton,
  IonList,
  IonItem,
  IonLabel,
  IonButton,
  IonIcon
} from '@ionic/angular/standalone';
import { NgFor, DatePipe } from '@angular/common';
import Parse from 'parse';

interface LearningPlan {
  id: string;
  subject: string;
  timeFrame: string;
  createdAt: Date;
  planDetails: string;
}

@Component({
  selector: 'app-learning-history',
  templateUrl: './learning-history.page.html',
  styleUrls: ['./learning-history.page.scss'],
  standalone: true,
  imports: [
    IonHeader,
    IonToolbar,
    IonTitle,
    IonContent,
    IonButtons,
    IonBackButton,
    IonList,
    IonItem,
    IonLabel,
    IonButton,
    IonIcon,
    NgFor,
    DatePipe
  ]
})
export class LearningHistoryPage implements OnInit {
  learningPlans: LearningPlan[] = [];

  constructor() {}

  ngOnInit() {
    this.loadLearningPlans();
  }

  async loadLearningPlans() {
    try {
      const currentUser = Parse.User.current();
      if (!currentUser) {
        throw new Error('User not logged in');
      }

      const LearningPlan = Parse.Object.extend('LearningPlan');
      const query = new Parse.Query(LearningPlan);
      query.equalTo('userId', currentUser.id);
      query.descending('createdAt');

      const results = await query.find();
      this.learningPlans = results.map(plan => ({
        id: plan.id,
        subject: plan.get('subject'),
        timeFrame: plan.get('timeFrame'),
        createdAt: plan.get('createdAt'),
        planDetails: plan.get('planDetails')
      }));
    } catch (error) {
      console.error('加载学习计划失败:', error);
    }
  }

  viewPlanDetails(plan: LearningPlan) {
    // 实现查看详情的逻辑
  }
} 