import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonIcon,IonContent, IonHeader, IonTitle, IonToolbar,NavController, IonButton, IonTextarea, IonItem, IonLabel, 
  IonButtons, ToastController } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { close } from 'ionicons/icons';
import { CloudFeedback, CloudUser } from 'src/lib/ncloud';

@Component({
  selector: 'app-feedback',
  templateUrl: './feedback.page.html',
  styleUrls: ['./feedback.page.scss'],
  standalone: true,
  imports: [IonContent, IonHeader, IonTitle, IonToolbar, CommonModule, FormsModule,
    IonIcon,IonButton,IonTextarea,IonItem,IonLabel,FormsModule,IonButtons,
  ]
})
export class FeedbackPage implements OnInit {

currentUser:CloudUser
  FeedbackData:any={
 feedback: '', // 初始化 feedback 字段
  };


constructor(private navCtrl:NavController,private toastController: ToastController){
    this.currentUser=new CloudUser();
    addIcons({close})
  }

  ngOnInit() {
  }
  
  closeFeedback() {
    this.navCtrl.back();
  }

  FeedbackDataChange(key:string,env:any){
    this.FeedbackData[key] = env.detail.value; // 更新 postData 对象
  }
    async saveFeedback(){
    let feedback=new CloudFeedback();
    feedback.setFeedbackData(this.FeedbackData, this.currentUser.id); // 设置帖子数据和用户ID

    try {
      await feedback.save(); // 保存反馈
      this.FeedbackData['feedback'] = ''; // 清空 feedback
       // 创建并显示提示
    const toast = await this.toastController.create({
      message: '反馈已提交！',
      duration: 2000, // 持续时间（毫秒）
      position: 'middle', // 显示位置
    });
    toast.present(); // 显示提示
    } catch (error) {
      console.error('保存反馈失败:', error);
    }
    }


}
